Namespace: Basic:isPotentialId

Basic:isPotentialId

Source:

Methods

isPotentialId(value, prefixopt, nullable, idRexopt, nullable, postfixopt, nullable, maskFixesopt, nullable) → {String|Boolean}

Determines if a given value is potentially a valid id for something, because it matches a format of given prefix, postfix and id regex. "Potential", because we can only assume by the format, we do not actually know if the id really matches anything like a database entry for example.

Parameters:
Name Type Attributes Default Description
value String | Number

the value to test, will be stringified

prefix String <optional>
<nullable>
''

a prefix for the id

idRex String <optional>
<nullable>
'[1-9][0-9]*'

the regex string to use to identify the id part of the value

postfix String <optional>
<nullable>
''

a postfix for the id

maskFixes Boolean <optional>
<nullable>
true

usually, prefixes are not treated as regexes and are automatically masked, if you'd like to define complex pre- and postfixes using regexes, set this to false

Source:
Returns:
if value is potential id according to format, the id is returned as a string (still usable as a truthy value), otherwise the return value is false
Type
String | Boolean
Example
if( isPotentialId(id, 'test_(', '[0-9]+', ')') ){
  createJsonRequest(`/backend/${id}`).then(() => { alert('done'); });
}