@pro-script/as-is v1.6.51
Pro-script Library Documentation
https://pro-script.gitbook.io/as-is
Overview
This library provides a comprehensive framework for type checking, utility functions, and macros for automated testing in JavaScript environments. It offers tools to validate types, manage enumerations, and enhance code quality through structured checks and assertions.
Table of Contents
- Installation
- Usage
- Summary of Features
- Type Checks
- Enum type
- Build-in validators
- Number Validators
- String Validators
- Alphabetic
- Digit
- Lowercase
- Uppercase
- CamelCase
- SnakeCase
- Kebab-Case
- Train-Case
- Path
- UUID
- HTTP URL
- HTTPS URL
- URL
- IPv4
- IPv6
- IP
- File Extension
- Hex Color
- Hex String
- Base64
- Data URL
- Credit Card
- MasterCard
- Visa
- American Express
- Diners Club
- Domain
- GUID
- Hostname
- ISO Date
- ISO Duration
- JWT
- Emoji
- Nanoid
- CUID
- CUID2
- Excludes
- Time (HH:MM:SS)
- DateTime (YYYY-MM-DDTHH:MM:SS)
- Date (YYYY-MM-DD)
- SHA-256 Hash
- BcryptHash
- ISO Time with Seconds
- ISO Timestamp
- ISO Week
- MAC Address
- MAC-48 Address
- MAC-64 Address
- Past Date
- Future Date
- ASCII String
- Base32
- Base58
- Date Before Specific Date
- Date After Specific Date
- Maximum String Length
- Minimum String Length
- Has Uppercase
- Has Lowercase
- Has Digit
- Has Special Character
- Password
- Utility
- Settings
- Aliases
- Micro-tests
- Advanced techniques
- Meta programing. Macros
- Possible Errors
Installation
npm install @pro-script/as-is @pro-script/as-is-pluginsFor Browsers
Without module:
<script src="https://www.unpkg.com/@pro-script/as-is"></script>
<script src="https://www.unpkg.com/@pro-script/as-is-plugins/numbers"></script>
<script src="https://www.unpkg.com/@pro-script/as-is-plugins/strings"></script>With module:
<script type="module">
import { Checker } from "https://www.unpkg.com/@pro-script/as-is";
import { NumbersValidator } from "https://www.unpkg.com/@pro-script/as-is-plugins/numbers";
import { StringsValidator } from "https://www.unpkg.com/@pro-script/as-is-plugins/strings";
// usage code
</script>Usage
Node.js (ESM)
import { Checker } from '@pro-script/as-is';
import { NumbersValidator } from '@pro-script/as-is-plugins/numbers';
import { StringsValidator } from '@pro-script/as-is-plugins/strings';
const { as, is } = new Checker({ integrate: Object.assign(NumbersValidator, StringsValidator) });Node.js (CommonJS)
const { Checker } = require('@pro-script/as-is');
const { NumbersValidator } = require('@pro-script/as-is-plugins/numbers');
const { StringsValidator } = require('@pro-script/as-is-plugins/strings');
const { as, is } = new Checker({ integrate: Object.assign(NumbersValidator, StringsValidator) });Browser
Without module:
<script>
const { as, is } = new Checker({ integrate: Object.assign(NumbersValidator, StringsValidator) });
</script>With module:
<script type="module">
import { Checker } from "https://www.unpkg.com/@pro-script/as-is";
import { NumbersValidator } from "https://www.unpkg.com/@pro-script/as-is-plugins/numbers";
import { StringsValidator } from "https://www.unpkg.com/@pro-script/as-is-plugins/strings";
const { as, is } = new Checker({ integrate: Object.assign(NumbersValidator, StringsValidator) });
</script>With import map:
<script type="importmap">
{
"imports": {
"@pro-script/as-is": "https://www.unpkg.com/@pro-script/as-is",
"@pro-script/as-is-plugins/numbers": "https://www.unpkg.com/@pro-script/as-is-plugins/numbers",
"@pro-script/as-is-plugins/strings": "https://www.unpkg.com/@pro-script/as-is-plugins/strings",
}
}
</script>
<script type="module">
import { Checker } from '@pro-script/as-is';
import { NumbersValidator } from '@pro-script/as-is-plugins/numbers';
import { StringsValidator } from '@pro-script/as-is-plugins/strings';
const { as, is } = new Checker({ integrate: Object.assign(NumbersValidator, StringsValidator) });
</script>Everything in one code block
const checker = new Checker({
'IF/ELSE/END': true,
strict: true,
Enum: true,
utility: true,
integrate: Object.assign(NumbersValidator, StringsValidator) });
const { multi, Interface, as, is, IF, ELSE, END, optional, get, macro, strict, Enum } = checker;
const { START, STOP, FINISH, METHOD, PROPERTY, IS, CHECK, passed, failed } = new MicroTest({ is, as });in global scope
Object.assign(global, { multi, Interface, as, is, Enum });or
Object.assign(window, { multi, Interface, as, is, Enum });After that you can use an as or is etc in other files.
Summary of Features
Supported Types:
Types list with alias name:
- Number | number
- String | string
- Boolean | boolean
- Symbol | symbol
- Function | function
- BigInt | bigInt | bigint
- Array | array
- TypedArray | typedArray | Typedarray | typedarray
- Buffer | buffer
- SharedArrayBuffer | sharedArrayBuffer | SharedarrayBuffer | sharedsrrayBuffer | sharedsrraybuffer
- Date | date
- Object | date
- Class | class
- instance
- Enum | enum
- Set | set
- Map | map
- Iterator | iterator
- Nullish | nullish
- WeakSet | weakSet | weeakset
- WeakMap | wearMap | weakmap
- WeakRef | weakRef | weakref
- RegExp | regExp | regexp
- Promise | promise
- Error | error
- RangeError | rangeError
- ReferenceError | referenceError
- SyntaxError |syntaxError
- TypeError | typeError
- Any | any
IF/ELSE/END for type checking
IF.number(string_)? (
console.log('IF type checking')
):ELSE.string(string_)? (
console.log('ELSE type checking'),
expect(string_).to.be.eq(string_)
):END;Strict type object:
strict.string`name`
strict.name = 'string'
// or
strict.string`name`.name = 'string'Class checking:
is.date(Date);
is.date(new Date);
is.class(Date) or is.class(new Date)Interface Interfaces works only in the set way where IName = { interface data }, not like IName({ interface data })
const { IUser } = Interface({
IUser: {
name: as.string,
age: as.number,
birthDate: as.date
}
});
as.IUser = { name: 'Jesus', age: 2022, birthDate: 'Sat Apr 7 0:0:0 GMT+0200 (Central European Summer Time)'};
function example(name, age, _ = as.IUser = { name, age }) {
console.log(name, age);
return 'returned string';
}
as.StringNumber(example({ name: 'text', age: 12, pages:['page'] }));Types Types works only in the apply way where TName({ types data }), not like interfaces TName = { types data }
const { multi, Interface, Type, as, is, IF, ELSE, END, optional, get, macro, strict, Enum } = checker;
const { TUser } = Type({
IUser: {
name: as.string,
birthDate: as.date,
age: (value)=> {
// any code here to check the value
}
}
});
as.TUser({ name: 'Jesus', age: 2022, birthDate: 'Sat Apr 7 0:0:0 GMT+0200 (Central European Summer Time)'});Integration
You can integrate any feature you want.
import { Checker, BaseInterface, MicroTest, Utility } from '@pro-script/as-is';
import axios from "axios";
const integrate = {
up: async function (url) {
const result = await axios.get(url);
if(result.status === 200) return 'Ok';
else throw new TypeError('url is down');
}
};
const { multi, strict, as, is } = new Checker({ integrate });
const isUrl = as;
async function example(arg, arg2, arg3,
type = [as.string(arg), as.number(arg2), as.boolean(arg3)]) {
await isUrl.up('https://google.com');
console.log(type);
};
await example('text', 2, true)
// [ 'text', 2, true ]
await isUrl?.up('https://not-google.com');
// TypeError: url is downInstancing
Minimal set of methods.
const { as, is } = new Checker;All methods without plugins.
const checker = new Checker({ 'IF/ELSE/END': true, strict: true, Enum: true, utility: true });
const { multi, Interface, as, is, IF, ELSE, END, optional, get, macro, strict, Enum } = checker;
const { START, STOP, FINISH, METHOD, PROPERTY, IS, CHECK, passed, failed } = new MicroTest({ is, as });All methods with plugins.
const checker = new Checker({
'IF/ELSE/END': true,
strict: true,
Enum: true,
utility: true,
integrate: Object.assign(NumbersValidator, StringsValidator)
});
const { multi, Interface, as, is, IF, ELSE, END, optional, get, macro, strict, Enum } = checker;
const { START, STOP, FINISH, METHOD, PROPERTY, IS, CHECK, passed, failed } = new MicroTest({ is, as });Type Checks
String
is.string(value) -> true | false
as.string(value) -> value | TypeError: [get.type(value)] is not a(an) stringDescription:
Checks if the provided argument is a string.
is.string(arg):
- Returns
trueifargis a string. - Returns
falseotherwise.
- Returns
as.string(arg):
- Returns
argif it is a string. - Throws
TypeErrorif
- Returns
arg is not a string.
Example:
is.string('hello'); // Returns true
is.string(123); // Returns false
as.string('hello'); // Returns 'hello'
as.string(123); // Throws TypeError: Number is not a(an) stringNumber
is.number(value) -> true | false
as.number(value) -> value | TypeError: [get.type(value)] is not is not a(an) numberDescription:
Checks if the provided argument is a number.
is.number(arg):
- Returns
trueifargis a number. - Returns
falseotherwise.
- Returns
as.number(arg):
- Returns
argif it is a number. - Throws
TypeErrorifargis not a number.
- Returns
Example:
is.number(123); // Returns true
is.number('123'); // Returns false
as.number(123); // Returns 123
as.number('123'); // Throws TypeError: Number is not a(an) numberBoolean
is.boolean(value) -> true | false
as.boolean(value) -> value | TypeError: [get.type(value)] is not a(an) booleanDescription:
Checks if the provided argument is a boolean.
is.boolean(arg):
- Returns
trueifargis a boolean. - Returns
falseotherwise.
- Returns
as.boolean(arg):
- Returns
argif it is a boolean. - Throws
TypeErrorifargis not a boolean.
- Returns
Example:
is.boolean(true); // Returns true
is.boolean(1); // Returns false
as.boolean(true); // Returns true
as.boolean(1); // Throws TypeError: Number is not a(an) booleanSymbol
is.symbol(value) -> true | false
as.symbol(value) -> value | TypeError: [get.type(value)] is not a(an) symbolDescription:
Checks if the provided argument is a symbol.
is.symbol(arg):
- Returns
trueifargis a symbol. - Returns
falseotherwise.
- Returns
as.symbol(arg):
- Returns
argif it is a symbol. - Throws
TypeErrorifargis not a symbol.
- Returns
Example:
const sym = Symbol('test');
is.symbol(sym); // Returns true
is.symbol('symbol'); // Returns false
as.symbol(sym); // Returns sym
as.symbol('symbol'); // Throws TypeError: String is not a(an) symbolFunction
is.function(value) -> true | false
as.function(value) -> value | TypeError: [get.type(value)] is not a(an) functionDescription:
Checks if the provided argument is a function.
is.function(arg):
- Returns
trueifargis a function. - Returns
falseotherwise.
- Returns
as.function(arg):
- Returns
argif it is a function. - Throws
TypeErrorifargis not a function.
- Returns
Example:
const func = () => {};
is.function(func); // Returns true
is.function(123); // Returns false
as.function(func); // Returns func
as.function(123); // Throws TypeError: Number is not a(an) functionBigInt
is.bigInt(value) -> true | false
as.bigInt(value) -> value | TypeError: [get.type(value)] is not a(an) bigIntDescription:
Checks if the provided argument is a BigInt.
is.bigInt(arg):
- Returns
trueifargis a BigInt. - Returns
falseotherwise.
- Returns
as.bigInt(arg):
- Returns
argif it is a BigInt. - Throws
TypeErrorifargis not a BigInt.
- Returns
Example:
const bigIntExample = BigInt('1234567890123456789012345678901234567890');
is.bigInt(bigIntExample); // Returns true
is.bigInt(1234567890); // Returns false
as.bigInt(bigIntExample); // Returns bigIntExample
as.bigInt(1234567890); // Throws TypeError: Number is not a(an) bigIntArray
is.array(value) -> true | false
as.array(value) -> value | TypeError: [get.type(value)] is not a(an) bigIntDescription:
Checks if the provided argument is an array.
is.array(arg):
- Returns
trueifargis an array. - Returns
falseotherwise.
- Returns
as.array(arg):
- Returns
argif it is an array. - Throws
TypeErrorifargis not an array.
- Returns
Example:
const arrayExample = [];
is.array(arrayExample); // Returns true
is.array('not an array'); // Returns false
as.array(arrayExample); // Returns arrayExample
as.array('not an array'); // Throws TypeError: String is not a(an) arrayDate
is.date(value) -> true | false
as.date(value) -> value | TypeError: [get.type(value)] is not a(an) dateDescription:
Checks if the provided argument is a date.
is.date(arg):
- Returns
trueifargis a date. - Returns
falseotherwise.
- Returns
as.date(arg):
- Returns
argif it is a date. - Throws
TypeErrorifargis not a date.
- Returns
Example:
const dateExample = new Date();
is.date(dateExample); // Returns true
is.date('not a date'); // Returns false
as.date(dateExample); // Returns dateExample
as.date('not a date'); // Throws TypeError: String is not a(an) dateObject
is.object(value) -> true | false
as.object(value) -> value | TypeError: [get.type(value)] is not a(an) objectDescription:
Checks if the provided argument is an object.
is.object(arg):
- Returns
trueifargis an object. - Returns
falseotherwise.
- Returns
as.object(arg):
- Returns
argif it is an object. - Throws
TypeErrorifargis not an object.
- Returns
Example:
const objectExample = {};
is.object(objectExample); // Returns true
is.object('not an object'); // Returns false
as.object(objectExample); // Returns objectExample
as.object('not an object'); // Throws TypeError: String is not a(an) objectSet
is.set(value) -> true | false
as.set(value) -> value | TypeError: [get.type(value)] is not a(an) setDescription:
Checks if the provided argument is a set.
is.set(arg):
- Returns
trueifargis a set. - Returns
falseotherwise.
- Returns
as.set(arg):
- Returns
argif it is a set. - Throws
TypeErrorifargis not a set.
- Returns
Example:
const setExample = new Set();
is.set(setExample); // Returns true
is.set('not a set'); // Returns false
as.set(setExample); // Returns setExample
as.set('not a set'); // Throws TypeError: String is not a(an) setMap
is.map(value) -> true | false
as.map(value) -> value | TypeError: [get.type(value)] is not a(an) mapDescription:
Checks if the provided argument is a map.
is.map(arg):
- Returns
trueifargis a map. - Returns
falseotherwise.
- Returns
as.map(arg):
- Returns
argif it is a map. - Throws
TypeErrorifargis not a map.
- Returns
Example:
const mapExample = new Map();
is.map(mapExample); // Returns true
is.map('not a map'); // Returns false
as.map(mapExample); // Returns mapExample
as.map('not a map'); // Throws TypeError: String is not a(an) mapWeakSet
is.weakSet(value) -> true | false
as.weakSet(value) -> value | TypeError: [get.type(value)] is not a(an) weakSetDescription:
Checks if the provided argument is a WeakSet.
is.weakSet(arg):
- Returns
trueifargis a WeakSet. - Returns
falseotherwise.
- Returns
as.weakSet(arg):
- Returns
argif it is a WeakSet. - Throws
TypeErrorifargis not a WeakSet.
- Returns
Example:
const weakSetExample = new WeakSet();
is.weakSet(weakSet
Example); // Returns true
is.weakSet('not a weakSet'); // Returns false
as.weakSet(weakSetExample); // Returns weakSetExample
as.weakSet('not a weakSet'); // Throws TypeError: String is not a(an) weakSetWeakMap
is.weakMap(value) -> true | false
as.weakMap(value) -> value | TypeError: [get.type(value)] is not a(an) weakMapDescription:
Checks if the provided argument is a WeakMap.
is.weakMap(arg):
- Returns
trueifargis a WeakMap. - Returns
falseotherwise.
- Returns
as.weakMap(arg):
- Returns
argif it is a WeakMap. - Throws
TypeErrorifargis not a WeakMap.
- Returns
Example:
const weakMapExample = new WeakMap();
is.weakMap(weakMapExample); // Returns true
is.weakMap('not a weakMap'); // Returns false
as.weakMap(weakMapExample); // Returns weakMapExample
as.weakMap('not a weakMap'); // Throws TypeError: String is not a(an) weakMapRegExp
is.regExp(value) -> true | false
as.regExp(value) -> value | TypeError: [get.type(value)] is not a(an) regExpDescription:
Checks if the provided argument is a regular expression.
is.regExp(arg):
- Returns
trueifargis a regular expression. - Returns
falseotherwise.
- Returns
as.regExp(arg):
- Returns
argif it is a regular expression. - Throws
TypeErrorifargis not a regular expression.
- Returns
Example:
const regExpExample = /./g;
is.regExp(regExpExample); // Returns true
is.regExp('not a regExp'); // Returns false
as.regExp(regExpExample); // Returns regExpExample
as.regExp('not a regExp'); // Throws TypeError: String is not a(an) regExpPromise
is.promise(value) -> true | false
as.promise(value) -> value | TypeError: [get.type(value)] is not a(an) promiseDescription:
Checks if the provided argument is a Promise.
is.promise(arg):
- Returns
trueifargis a Promise. - Returns
falseotherwise.
- Returns
as.promise(arg):
- Returns
argif it is a Promise. - Throws
TypeErrorifargis not a Promise.
- Returns
Example:
const promiseExample = new Promise((resolve) => resolve());
is.promise(promiseExample); // Returns true
is.promise('not a promise'); // Returns false
as.promise(promiseExample); // Returns promiseExample
as.promise('not a promise'); // Throws TypeError: String is not a(an) promiseGenerator
is.generator(value) -> true | false
as.generator(value) -> value | TypeError: [get.type(value)] is not a(an) generatorDescription:
Checks if the provided argument is a Generator.
is.generator(arg):
- Returns
trueifargis a Generator. - Returns
falseotherwise.
- Returns
as.generator(arg):
- Returns
argif it is a Generator. - Throws
TypeErrorifargis not a Generator.
- Returns
Example:
function* generatorExample() {
yield 1;
yield 2;
}
is.generator(generatorExample()); // Returns true
is.generator('not a generator'); // Returns false
as.generator(generatorExample()); // Returns generatorExample
as.generator('not a generator'); // Throws TypeError: String is not a(an) generatorHere is the documentation for the additional type checks:
TypedArray
is.typedArray(value) -> true | false
as.typedArray(value) -> value | TypeError: TypedArray is not a value that passed validationDescription:
Checks if the provided argument is a TypedArray.
is.typedArray(arg):
- Returns
trueifargis a TypedArray. - Returns
falseotherwise.
- Returns
as.typedArray(arg):
- Returns
argif it is a TypedArray. - Throws
TypeErrorifargis not a TypedArray.
- Returns
Example:
is.typedArray(new Int8Array()); // Returns true
is.typedArray([]); // Returns false
as.typedArray(new Int8Array()); // Returns Int8Array
as.typedArray([]); // Throws TypeError: Array is not a(an) typedArrayBuffer
is.buffer(value) -> true | false
as.buffer(value) -> value | TypeError: [get.type(value)] is not a(an) bufferDescription:
Checks if the provided argument is a Buffer.
is.buffer(arg):
- Returns
trueifargis a Buffer. - Returns
falseotherwise.
- Returns
as.buffer(arg):
- Returns
argif it is a Buffer. - Throws
TypeErrorifargis not a Buffer.
- Returns
Example:
is.buffer(Buffer.from('hello')); // Returns true
is.buffer('hello'); // Returns false
as.buffer(Buffer.from('hello')); // Returns Buffer
as.buffer('hello'); // Throws TypeError: String is not a(an) bufferSharedArrayBuffer
is.sharedArrayBuffer(value) -> true | false
as.sharedArrayBuffer(value) -> value | TypeError: [get.type(value)] is not a(an) sharedArrayBufferDescription:
Checks if the provided argument is a SharedArrayBuffer.
is.sharedArrayBuffer(arg):
- Returns
trueifargis a SharedArrayBuffer. - Returns
falseotherwise.
- Returns
as.sharedArrayBuffer(arg):
- Returns
argif it is a SharedArrayBuffer. - Throws
TypeErrorifargis not a SharedArrayBuffer.
- Returns
Example:
is.sharedArrayBuffer(new SharedArrayBuffer()); // Returns true
is.sharedArrayBuffer([]); // Returns false
as.sharedArrayBuffer(new SharedArrayBuffer()); // Returns SharedArrayBuffer
as.sharedArrayBuffer([]); // Throws TypeError: Array is not a(an) sharedArrayBufferDate
is.date(value) -> true | false
as.date(value) -> value | TypeError: [get.type(value)] is not a(an) dateDescription:
Checks if the provided argument is a Date object.
is.date(arg):
- Returns
trueifargis a Date object. - Returns
falseotherwise.
- Returns
as.date(arg):
- Returns
argif it is a Date object. - Throws
TypeErrorifargis not a Date object.
- Returns
Example:
is.date(new Date()); // Returns true
is.date('2021-01-01'); // Returns false
as.date(new Date()); // Returns Date
as.date('2021-01-01'); // Throws TypeError: String is not a(an) dateObject
is.object(value) -> true | false
as.object(value) -> value | TypeError: [get.type(value)] is not a(an) objectDescription:
Checks if the provided argument is an object.
is.object(arg):
- Returns
trueifargis an object. - Returns
falseotherwise.
- Returns
as.object(arg):
- Returns
argif it is an object. - Throws
TypeErrorifargis not an object.
- Returns
Example:
is.object({}); // Returns true
is.object('hello'); // Returns false
as.object({}); // Returns {}
as.object('hello'); // Throws TypeError: String is not a(an) objectClass
is.class(value) -> true | false
as.class(value) -> value | TypeError: [get.type(value)] is not a(an) classDescription:
Checks if the provided argument is a class.
is.class(arg):
- Returns
trueifargis a class. - Returns
falseotherwise.
- Returns
as.class(arg):
- Returns
argif it is a class. - Throws
TypeErrorifargis not a class.
- Returns
Example:
class MyClass {}
is.class(MyClass); // Returns true
is.class(() => {}); // Returns false
as.class(MyClass); // Returns MyClass
as.class(() => {}); // Throws TypeError: Function is not a(an) classInstance
is.instance(value, constructor) -> true | false
as.instance(value, constructor) -> value | TypeError: [get.type(value)] is not a(an) instanceDescription:
Checks if the provided argument is an instance of the specified class.
is.instance(arg, constructor):
- Returns
trueifargis an instance ofconstructor. - Returns
falseotherwise.
- Returns
as.instance(arg, constructor):
- Returns
argif it is an instance ofconstructor. - Throws
TypeErrorifargis not an instance ofconstructor.
- Returns
Example:
class MyClass {}
const instance = new MyClass();
is.instance(instance, MyClass); // Returns true
is.instance({}, MyClass); // Returns false
as.instance(instance, MyClass); // Returns instance
as.instance({}, MyClass); // Throws TypeError: Object is not a(an) instanceIterator
is.iterator(value) -> true | false
as.iterator(value) -> value | TypeError: [get.type(value)] is not a(an) iteratorDescription:
Checks if the provided argument is an iterator.
is.iterator(arg):
- Returns
trueifargis an iterator. - Returns
falseotherwise.
- Returns
as.iterator(arg):
- Returns
argif it is an iterator. - Throws
TypeErrorifargis not an iterator.
- Returns
Example:
const iterator = [][Symbol.iterator]();
is.iterator(iterator); // Returns true
is.iterator([]); // Returns false
as.iterator(iterator); // Returns iterator
as.iterator([]); // Throws TypeError: Array is not a(an) iteratorNullish
is.nullish(value) -> true | false
as.nullish(value) -> value | TypeError: [get.type(value)] is not a(an) nullishDescription:
Checks if the provided argument is null or undefined.
is.nullish(arg):
- Returns
trueifargis null or undefined. - Returns
falseotherwise.
- Returns
as.nullish(arg):
- Returns
argif it is null or undefined. - Throws
TypeErrorifargis not null or undefined.
- Returns
Example:
is.nullish(null); // Returns true
is.nullish(undefined); // Returns true
is.nullish('hello'); // Returns false
as.nullish(null); // Returns null
as.nullish(undefined); // Returns undefined
as.nullish('hello'); // Throws TypeError: String is not a(an) nullishError
is.error(value) -> true | false
as.error(value) -> value | TypeError: [get.type(value)] is not a(an) errorDescription:
Checks if the provided argument is an Error.
is.error(arg):
- Returns
trueifargis an Error. - Returns
falseotherwise.
- Returns
as.error(arg):
- Returns
argif it is an Error. - Throws
TypeErrorifargis not an Error.
- Returns
Example:
is.error(new Error()); // Returns true
is.error('error'); // Returns false
as.error(new Error()); // Returns Error
as.error('error'); // Throws TypeError: String is not a(an) errorRangeError
is.rangeError(value) -> true | false
as.rangeError(value) -> value | TypeError: [get.type(value)] is not a(an) rangeErrorDescription:
Checks if the provided argument is a RangeError.
is.rangeError(arg):
- Returns
trueifargis a RangeError. - Returns
falseotherwise.
- Returns
as.rangeError(arg):
- Returns
argif it is a RangeError. - Throws
TypeErrorifargis not a RangeError.
- Returns
Example:
is.rangeError(new RangeError()); // Returns true
is.rangeError('error'); // Returns false
as.rangeError(new RangeError()); // Returns RangeError
as.rangeError('error'); // Throws TypeError: String is not a(an) rangeErrorReferenceError
is.referenceError(value) -> true | false
as.referenceError(value) -> value | TypeError: [get.type(value)] is not a(an) referenceErrorDescription:
Checks if the provided argument is a ReferenceError.
is.referenceError(arg):
- Returns
trueifargis a ReferenceError. - Returns
falseotherwise.
- Returns
as.referenceError(arg):
- Returns
argif it is a ReferenceError. - Throws
TypeErrorifargis not a ReferenceError.
- Returns
Example:
is.referenceError(new ReferenceError()); // Returns true
is.referenceError('error'); // Returns false
as.referenceError(new ReferenceError()); // Returns ReferenceError
as.referenceError('error'); // Throws TypeError: String is not a(an) referenceErrorSyntaxError
is.syntaxError(value) -> true | false
as.syntaxError(value) -> value | TypeError: [get.type(value)] is not a(an) syntaxErrorDescription:
Checks if the provided argument is a SyntaxError.
is.syntaxError(arg):
- Returns
trueifargis a SyntaxError. - Returns
falseotherwise.
- Returns
as.syntaxError(arg):
- Returns
argif it is a SyntaxError. - Throws
TypeErrorifargis not a SyntaxError.
- Returns
Example:
is.syntaxError(new SyntaxError()); // Returns true
is.syntaxError('error'); // Returns false
as.syntaxError(new SyntaxError()); // Returns SyntaxError
as.syntaxError('error'); // Throws TypeError: String is not a(an) syntaxErrorTypeError
is.typeError(value) -> true | false
as.typeError(value) -> value | TypeError: [get.type(value)] is not a(an) typeErrorDescription:
Checks if the provided argument is a TypeError.
is.typeError(arg):
- Returns
trueifargis a TypeError. - Returns
falseotherwise.
- Returns
as.typeError(arg):
- Returns
argif it is a TypeError. - Throws
TypeErrorifargis not a TypeError.
- Returns
Example:
is.typeError(new TypeError()); // Returns true
is.typeError('error'); // Returns false
as.typeError(new TypeError()); // Returns TypeError
as.typeError('error'); // Throws TypeError: String is not a(an) typeErrorAny
is.any(value) -> true
as.any(value) -> valueDescription:
Checks if the provided argument is any value.
is.any(arg):
- Returns
trueifargis any value. - Returns
falseotherwise.
- Returns
as.any(arg):
- Returns
argif it is any value. - Throws
TypeErrorifargis not any value.
- Returns
Example:
is.any('hello'); // Returns true
is.any(123); // Returns true
as.any('hello'); // Returns 'hello'
as.any(123); // Returns 123Enum type
Enum type Basic
Enum['name of stored enum']('enum object here')Enum type Basic usage
Use increment
Enum.color({
RED: 0,
GREEN: Enum.inc,
BLUE: Enum.inc,
});
// Enum {
// '0': 'RED',
// '1': 'GREEN',
// '2': 'BLUE',
// RED: 0,
// GREEN: 1,
// BLUE: 2
// }
as.color('RED');// -> 'RED'
as.color('RED2');// -> TypeError String is not a member of color enumUse decrement
Enum.house({
ROOF: 2,
FLOOR: Enum.dec,
BASEMENT: Enum.dec,
});
// Enum {
// '0': 'BASEMENT',
// '1': 'FLOOR',
// '2': 'ROOF',
// ROOF: 2,
// FLOOR: 1,
// BASEMENT: 0
// }Use both
Enum.colorAndHouse({
RED: 0,
GREEN: Enum.inc,
BLUE: Enum.inc,
ROOF: 6,
FLOOR: Enum.dec,
BASEMENT: Enum.dec,
});
// Enum {
// '0': 'RED',
// '1': 'GREEN',
// '2': 'BLUE',
// '4': 'BASEMENT',
// '5': 'FLOOR',
// '6': 'ROOF',
// RED: 0,
// GREEN: 1,
// BLUE: 2,
// ROOF: 6,
// FLOOR: 5,
// BASEMENT: 4
// }Use with step
Enum.color({
[Enum.step]: 10, // ['Enum.step'] the same but with a quotes
RED: Enum.inc,
GREEN: Enum.inc,
BLUE: Enum.inc,
});
// Enum {
// '10': 'RED',
// '20': 'GREEN',
// '30': 'BLUE',
// RED: 10,
// GREEN: 20,
// BLUE: 30
// }
const enumExample = Enum.house({
[Enum.step]: 10,
ROOF: Enum.dec,
FLOOR: 30,
BASEMENT: Enum.dec,
});
// Enum {
// '10': 'ROOF',
// '20': 'BASEMENT',
// '30': 'FLOOR',
// ROOF: 10,
// FLOOR: 30,
// BASEMENT: 20
// }Check the Enum type like this
as.Enum(enumExample) && as.enum(enumExample);Build-in validators
This list of validators works with a minimum set of methods.
Empty
is.empty(value) -> true | false
as.empty(value) -> value | TypeError: Value is not emptyDescription:
Checks if the provided argument is empty.
is.empty(arg):
- Returns
trueifargis empty. - Returns
falseotherwise.
- Returns
as.empty(arg):
- Returns
argif it is empty. - Throws
TypeErrorifargis not empty.
- Returns
Example:
const emptyArray = [];
is.empty(emptyArray); // Returns true
is.empty([1, 2, 3]); // Returns false
as.empty(emptyArray); // Returns emptyArray
as.empty([1, 2, 3]); // Throws TypeError: Value is not emptyNotEmpty
is.notEmpty(value) -> true | false
as.notEmpty(value) -> value | TypeError: Value is emptyDescription:
Checks if the provided argument is not empty.
is.notEmpty(arg):
- Returns
trueifargis not empty. - Returns
falseotherwise.
- Returns
as.notEmpty(arg):
- Returns
argif it is not empty. - Throws
TypeErrorifargis empty.
- Returns
Example:
const notEmptyArray = [1, 2, 3];
is.notEmpty(notEmptyArray); // Returns true
is.notEmpty([]); // Returns false
as.notEmpty(notEmptyArray); // Returns notEmptyArray
as.notEmpty([]); // Throws TypeError: Value is emptyJSON
is.json(value) -> true | false
as.json(value) -> value | TypeError: Value is not JSONDescription:
Checks if the provided argument is a valid JSON string.
is.json(arg):
- Returns
trueifargis a valid JSON string. - Returns
falseotherwise.
- Returns
**
as.json(arg):**
- Returns
argif it is a valid JSON string. - Throws
TypeErrorifargis not a valid JSON string.
Example:
const jsonExample = JSON.stringify({ test: 'test' });
is.json(jsonExample); // Returns true
is.json('not json'); // Returns false
as.json(jsonExample); // Returns jsonExample
as.json('not json'); // Throws TypeError: Value is not JSONJSON5
is.json5(value) -> true | false
as.json5(value) -> value | TypeError: Value is not JSON5Description:
Checks if the provided argument is a valid JSON5 string.
is.json5(arg):
- Returns
trueifargis a valid JSON5 string. - Returns
falseotherwise.
- Returns
as.json5(arg):
- Returns
argif it is a valid JSON5 string. - Throws
TypeErrorifargis not a valid JSON5 string.
- Returns
Example:
const json5Example = '{property: "value"}';
is.json5(json5Example); // Returns true
is.json5('not json5'); // Returns false
as.json5(json5Example); // Returns json5Example
as.json5('not json5'); // Throws TypeError: Value is not JSON5Null
is.null(value) -> true | false
as.null(value) -> value | TypeError: Value is not nullDescription:
Checks if the provided argument is null.
is.null(arg):
- Returns
trueifargis null. - Returns
falseotherwise.
- Returns
as.null(arg):
- Returns
argif it is null. - Throws
TypeErrorifargis not null.
- Returns
Example:
const nullExample = null;
is.null(nullExample); // Returns true
is.null('not null'); // Returns false
as.null(nullExample); // Returns nullExample
as.null('not null'); // Throws TypeError: Value is not nullNumber Validators
Sure, I'll restructure the documentation as requested. Here is the first part of the updated documentation:
Zero
is.zero(value) -> true | false
as.zero(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is exactly zero.
is.zero(arg):
- Returns
trueifargis0. - Returns
falseotherwise.
- Returns
as.zero(arg):
- Returns
argif it is0. - Throws
TypeErrorifargis not0.
- Returns
Example:
is.zero(0); // Returns true
is.zero(5); // Returns false
as.zero(0); // Returns 0
as.zero(5); // Throws TypeError: Number is not a value that passed validationEven
is.even(value) -> true | false
as.even(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is an even number.
is.even(arg):
- Returns
trueifargis even. - Returns
falseotherwise.
- Returns
as.even(arg):
- Returns
argif it is even. - Throws
TypeErrorifargis not even.
- Returns
Example:
is.even(2); // Returns true
is.even(3); // Returns false
as.even(2); // Returns 2
as.even(3); // Throws TypeError: Number is not a value that passed validationOdd
is.odd(value) -> true | false
as.odd(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is an odd number.
is.odd(arg):
- Returns
trueifargis odd. - Returns
falseotherwise.
- Returns
as.odd(arg):
- Returns
argif it is odd. - Throws
TypeErrorifargis not odd.
- Returns
Example:
is.odd(1); // Returns true
is.odd(4); // Returns false
as.odd(1); // Returns 1
as.odd(4); // Throws TypeError: Number is not a value that passed validationPositive
is.positive(value) -> true | false
as.positive(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a positive number.
is.positive(arg):
- Returns
trueifargis positive. - Returns
falseotherwise.
- Returns
as.positive(arg):
- Returns
argif it is positive. - Throws
TypeErrorifargis not positive.
- Returns
Example:
is.positive(1.1); // Returns true
is.positive(-1.1); // Returns false
as.positive(1.1); // Returns 1.1
as.positive(-1.1); // Throws TypeError: Number is not a value that passed validationNegative
is.negative(value) -> true | false
as.negative(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a negative number.
is.negative(arg):
- Returns
trueifargis negative. - Returns
falseotherwise.
- Returns
as.negative(arg):
- Returns
argif it is negative. - Throws
TypeErrorifargis not negative.
- Returns
Example:
is.negative(-1.1); // Returns true
is.negative(1.1); // Returns false
as.negative(-1.1); // Returns -1.1
as.negative(1.1); // Throws TypeError: Number is not a value that passed validationPositive Integer
is.positiveInteger(value) -> true | false
as.positiveInteger(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a positive integer.
is.positiveInteger(arg):
- Returns
trueifargis a positive integer. - Returns
falseotherwise.
- Returns
as.positiveInteger(arg):
- Returns
argif it is a positive integer. - Throws
TypeErrorifargis not a positive integer.
- Returns
Example:
is.positiveInteger(1); // Returns true
is.positiveInteger(-1); // Returns false
as.positiveInteger(1); // Returns 1
as.positiveInteger(-1); // Throws TypeError: Number is not a value that passed validationNegative Integer
is.negativeInteger(value) -> true | false
as.negativeInteger(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a negative integer.
is.negativeInteger(arg):
- Returns
trueifargis a negative integer. - Returns
falseotherwise.
- Returns
as.negativeInteger(arg):
- Returns
argif it is a negative integer. - Throws
TypeErrorifargis not a negative integer.
- Returns
Example:
is.negativeInteger(-1); // Returns true
is.negativeInteger(1); // Returns false
as.negativeInteger(-1); // Returns -1
as.negativeInteger(1); // Throws TypeError: Number is not a value that passed validationFinite
is.isFinite(value) -> true | false
as.isFinite(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a finite number.
is.isFinite(arg):
- Returns
trueifargis finite. - Returns
falseotherwise.
- Returns
as.isFinite(arg):
- Returns
argif it is finite. - Throws
TypeErrorifargis not finite.
- Returns
Example:
is.isFinite(0); // Returns true
is.isFinite(Infinity); // Returns false
as.isFinite(0); // Returns 0
as.isFinite(Infinity); // Throws TypeError: Number is not a value that passed validationNaN
is.NaN(value) -> true | false
as.NaN(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is NaN (Not-a-Number).
is.NaN(arg):
- Returns
trueifargis NaN. - Returns
falseotherwise.
- Returns
as.NaN(arg):
- Returns
argif it is NaN. - Throws
TypeErrorifargis not NaN.
- Returns
Example:
is.NaN(NaN); // Returns true
is.NaN(0); // Returns false
as.NaN(NaN); // Returns NaN
as.NaN(0); // Throws TypeError: Number is not a value that passed validationBetween
is.between({ arg, min, max }) -> true | false
as.between({ arg, min, max }) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is between min and max values.
is.between({ arg, min, max }):
- Returns
trueifargis betweenminandmax. - Returns
falseotherwise.
- Returns
as.between({ arg, min, max }):
- Returns
argif it is betweenminandmax. - Throws
TypeErrorifargis not betweenminandmax.
- Returns
Example:
is.between({ arg: 5, min: 0, max: 10 }); // Returns true
is.between({ arg: 15, min: 0, max: 10 }); // Returns false
as.between({ arg: 5, min: 0, max: 10 }); // Returns 5
as.between({ arg: 15, min: 0, max: 10 }); // Throws TypeError: Number is not a value that passed validationGreater
is.greater({ arg, value }) -> true | false
as.greater({ arg, value }) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is greater than the specified value.
- is.greater({ arg, value }):
- Returns
trueifargis greater thanvalue. - Returns `
- Returns
false` otherwise.
- as.greater({ arg, value }):
- Returns
argif it is greater thanvalue. - Throws
TypeErrorifargis not greater thanvalue.
- Returns
Example:
is.greater({ arg: 15, value: 5 }); // Returns true
is.greater({ arg: 5, value: 15 }); // Returns false
as.greater({ arg: 15, value: 5 }); // Returns 15
as.greater({ arg: 5, value: 15 }); // Throws TypeError: Number is not a value that passed validationLess
is.less({ arg, value }) -> true | false
as.less({ arg, value }) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is less than the specified value.
is.less({ arg, value }):
- Returns
trueifargis less thanvalue. - Returns
falseotherwise.
- Returns
as.less({ arg, value }):
- Returns
argif it is less thanvalue. - Throws
TypeErrorifargis not less thanvalue.
- Returns
Example:
is.less({ arg: 5, value: 15 }); // Returns true
is.less({ arg: 15, value: 5 }); // Returns false
as.less({ arg: 5, value: 15 }); // Returns 5
as.less({ arg: 15, value: 5 }); // Throws TypeError: Number is not a value that passed validationEqual or Greater
is.equalGreater({ arg, value }) -> true | false
as.equalGreater({ arg, value }) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is equal to or greater than the specified value.
is.equalGreater({ arg, value }):
- Returns
trueifargis equal to or greater thanvalue. - Returns
falseotherwise.
- Returns
as.equalGreater({ arg, value }):
- Returns
argif it is equal to or greater thanvalue. - Throws
TypeErrorifargis not equal to or greater thanvalue.
- Returns
Example:
is.equalGreater({ arg: 5, value: 5 }); // Returns true
is.equalGreater({ arg: 4, value: 5 }); // Returns false
as.equalGreater({ arg: 5, value: 5 }); // Returns 5
as.equalGreater({ arg: 4, value: 5 }); // Throws TypeError: Number is not a value that passed validationEqual or Less
is.equalLess({ arg, value }) -> true | false
as.equalLess({ arg, value }) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is equal to or less than the specified value.
is.equalLess({ arg, value }):
- Returns
trueifargis equal to or less thanvalue. - Returns
falseotherwise.
- Returns
as.equalLess({ arg, value }):
- Returns
argif it is equal to or less thanvalue. - Throws
TypeErrorifargis not equal to or less thanvalue.
- Returns
Example:
is.equalLess({ arg: 5, value: 5 }); // Returns true
is.equalLess({ arg: 6, value: 5 }); // Returns false
as.equalLess({ arg: 5, value: 5 }); // Returns 5
as.equalLess({ arg: 6, value: 5 }); // Throws TypeError: Number is not a value that passed validationMax
is.max({ arg, value }) -> true | false
as.max({ arg, value }) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is equal to the specified maximum value.
is.max({ arg, value }):
- Returns
trueifargis equal to the maximumvalue. - Returns
falseotherwise.
- Returns
as.max({ arg, value }):
- Returns
argif it is equal to the maximumvalue. - Throws
TypeErrorifargis not equal to the maximumvalue.
- Returns
Example:
is.max({ arg: 5, value: 5 }); // Returns true
is.max({ arg: 4, value: 5 }); // Returns false
as.max({ arg: 5, value: 5 }); // Returns 5
as.max({ arg: 4, value: 5 }); // Throws TypeError: Number is not a value that passed validationMin
is.min({ arg, value }) -> true | false
as.min({ arg, value }) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is equal to the specified minimum value.
is.min({ arg, value }):
- Returns
trueifargis equal to the minimumvalue. - Returns
falseotherwise.
- Returns
as.min({ arg, value }):
- Returns
argif it is equal to the minimumvalue. - Throws
TypeErrorifargis not equal to the minimumvalue.
- Returns
Example:
is.min({ arg: 5, value: 5 }); // Returns true
is.min({ arg: 6, value: 5 }); // Returns false
as.min({ arg: 5, value: 5 }); // Returns 5
as.min({ arg: 6, value: 5 }); // Throws TypeError: Number is not a value that passed validationMultiple
is.multiple({ arg, value }) -> true | false
as.multiple({ arg, value }) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a multiple of the specified value.
is.multiple({ arg, value }):
- Returns
trueifargis a multiple ofvalue. - Returns
falseotherwise.
- Returns
as.multiple({ arg, value }):
- Returns
argif it is a multiple ofvalue. - Throws
TypeErrorifargis not a multiple ofvalue.
- Returns
Example:
is.multiple({ arg: 15, value: 5 }); // Returns true
is.multiple({ arg: 14, value: 5 }); // Returns false
as.multiple({ arg: 15, value: 5 }); // Returns 15
as.multiple({ arg: 14, value: 5 }); // Throws TypeError: Number is not a value that passed validationPort
is.port(value) -> true | false
as.port(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a valid port number (between 0 and 65535).
is.port(arg):
- Returns
trueifargis a valid port number. - Returns
falseotherwise.
- Returns
as.port(arg):
- Returns
argif it is a valid port number. - Throws
TypeErrorifargis not a valid port number.
- Returns
Example:
is.port(80); // Returns true
is.port(70000); // Returns false
as.port(80); // Returns 80
as.port(70000); // Throws TypeError: Number is not a value that passed validationSafe Integer
is.safe(value) -> true | false
as.safe(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a safe integer (within the range of Number.MIN_SAFE_INTEGER and Number.MAX_SAFE_INTEGER).
is.safe(arg):
- Returns
trueifargis a safe integer. - Returns
falseotherwise.
- Returns
as.safe(arg):
- Returns
argif it is a safe integer. - Throws
TypeErrorifargis not a safe integer.
- Returns
Example:
is.safe(Number.MAX_SAFE_INTEGER); // Returns true
is.safe(Number.MAX_SAFE_INTEGER + 1); // Returns false
as.safe(Number.MAX_SAFE_INTEGER); // Returns Number.MAX_SAFE_INTEGER
as.safe(Number.MAX_SAFE_INTEGER + 1); // Throws TypeError: Number is not a value that passed validationPrecision
is.precision({ arg, value }) -> true | false
as.precision({ arg, value }) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument has the specified precision value.
- is.precision({ arg, value }):
- Returns `true
ifarghas the specified precisionvalue`.
Returns
falseotherwise.as.precision({ arg, value }):
- Returns
argif it has the specified precisionvalue. - Throws
TypeErrorifargdoes not have the specified precisionvalue.
- Returns
Example:
is.precision({ arg: 5.22, value: 2 }); // Returns true
is.precision({ arg: 5.2, value: 2 }); // Returns false
as.precision({ arg: 5.22, value: 2 }); // Returns 5.22
as.precision({ arg: 5.2, value: 2 }); // Throws TypeError: Number is not a value that passed validationDigits
is.digits({ arg, value }) -> true | false
as.digits({ arg, value }) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument has the specified number of digits value.
is.digits({ arg, value }):
- Returns
trueifarghas the specified number of digitsvalue. - Returns
falseotherwise.
- Returns
as.digits({ arg, value }):
- Returns
argif it has the specified number of digitsvalue. - Throws
TypeErrorifargdoes not have the specified number of digitsvalue.
- Returns
Example:
is.digits({ arg: 12345, value: 5 }); // Returns true
is.digits({ arg: 1234, value: 5 }); // Returns false
as.digits({ arg: 12345, value: 5 }); // Returns 12345
as.digits({ arg: 1234, value: 5 }); // Throws TypeError: Number is not a value that passed validationISBN-10
is.ISBN10(value) -> true | false
as.ISBN10(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a valid ISBN-10 number.
is.ISBN10(arg):
- Returns
trueifargis a valid ISBN-10 number. - Returns
falseotherwise.
- Returns
as.ISBN10(arg):
- Returns
argif it is a valid ISBN-10 number. - Throws
TypeErrorifargis not a valid ISBN-10 number.
- Returns
Example:
is.ISBN10(1234567890); // Returns true
is.ISBN10(123456789); // Returns false
as.ISBN10(1234567890); // Returns 1234567890
as.ISBN10(123456789); // Throws TypeError: Number is not a value that passed validationISBN-13
is.ISBN13(value) -> true | false
as.ISBN13(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a valid ISBN-13 number.
is.ISBN13(arg):
- Returns
trueifargis a valid ISBN-13 number. - Returns
falseotherwise.
- Returns
as.ISBN13(arg):
- Returns
argif it is a valid ISBN-13 number. - Throws
TypeErrorifargis not a valid ISBN-13 number.
- Returns
Example:
is.ISBN13(1234567890123); // Returns true
is.ISBN13(123456789012); // Returns false
as.ISBN13(1234567890123); // Returns 1234567890123
as.ISBN13(123456789012); // Throws TypeError: Number is not a value that passed validationEAN
is.EAN(value) -> true | false
as.EAN(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a valid EAN (European Article Number).
is.EAN(arg):
- Returns
trueifargis a valid EAN. - Returns
falseotherwise.
- Returns
as.EAN(arg):
- Returns
argif it is a valid EAN. - Throws
TypeErrorifargis not a valid EAN.
- Returns
Example:
is.EAN(1234567890123); // Returns true
is.EAN(123456789012); // Returns false
as.EAN(1234567890123); // Returns 1234567890123
as.EAN(123456789012); // Throws TypeError: Number is not a value that passed validationSSN
is.SSN(value) -> true | false
as.SSN(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a valid SSN (Social Security Number).
is.SSN(arg):
- Returns
trueifargis a valid SSN. - Returns
falseotherwise.
- Returns
as.SSN(arg):
- Returns
argif it is a valid SSN. - Throws
TypeErrorifargis not a valid SSN.
- Returns
Example:
is.SSN(123456789); // Returns true
is.SSN(12345678); // Returns false
as.SSN(123456789); // Returns 123456789
as.SSN(12345678); // Throws TypeError: Number is not a value that passed validationVIN
is.VIN(value) -> true | false
as.VIN(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a valid VIN (Vehicle Identification Number).
is.VIN(arg):
- Returns
trueifargis a valid VIN. - Returns
falseotherwise.
- Returns
as.VIN(arg):
- Returns
argif it is a valid VIN. - Throws
TypeErrorifargis not a valid VIN.
- Returns
Example:
is.VIN(12345678901234567); // Returns true
is.VIN(1234567890123456); // Returns false
as.VIN(12345678901234567); // Returns 12345678901234567
as.VIN(1234567890123456); // Throws TypeError: Number is not a value that passed validationINN-10
is.INN10(value) -> true | false
as.INN10(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a valid INN (Individual Taxpayer Number) with 10 digits.
is.INN10(arg):
- Returns
trueifargis a valid INN with 10 digits. - Returns
falseotherwise.
- Returns
as.INN10(arg):
- Returns
argif it is a valid INN with 10 digits. - Throws
TypeErrorifargis not a valid INN with 10 digits.
- Returns
Example:
is.INN10(1234567890); // Returns true
is.INN10(123456789); // Returns false
as.INN10(1234567890); // Returns 1234567890
as.INN10(123456789); // Throws TypeError: Number is not a value that passed validationINN-12
is.INN12(value) -> true | false
as.INN12(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a valid INN (Individual Taxpayer Number) with 12 digits.
is.INN12(arg):
- Returns
trueifargis a valid INN with 12 digits. - Returns
falseotherwise.
- Returns
as.INN12(arg):
- Returns
argif it is a valid INN with 12 digits. - Throws
TypeErrorifargis not a valid INN with 12 digits.
- Returns
Example:
is.INN12(123456789012); // Returns true
is.INN12(12345678901); // Returns false
as.INN12(123456789012); // Returns 123456789012
as.INN12(12345678901); // Throws TypeError: Number is not a value that passed validationGLN
is.GLN(value) -> true | false
as.GLN(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a valid GLN (Global Location Number).
- is.GLN(arg):
- Returns
trueifargis
- Returns
a valid GLN.
Returns
falseotherwise.as.GLN(arg):
- Returns
argif it is a valid GLN. - Throws
TypeErrorifargis not a valid GLN.
- Returns
Example:
is.GLN(1234567890123); // Returns true
is.GLN(123456789012); // Returns false
as.GLN(1234567890123); // Returns 1234567890123
as.GLN(123456789012); // Throws TypeError: Number is not a value that passed validationIMEI
is.IMEI(value) -> true | false
as.IMEI(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a valid IMEI (International Mobile Equipment Identity).
is.IMEI(arg):
- Returns
trueifargis a valid IMEI. - Returns
falseotherwise.
- Returns
as.IMEI(arg):
- Returns
argif it is a valid IMEI. - Throws
TypeErrorifargis not a valid IMEI.
- Returns
Example:
is.IMEI(123456789012345); // Returns true
is.IMEI(12345678901234); // Returns false
as.IMEI(123456789012345); // Returns 123456789012345
as.IMEI(12345678901234); // Throws TypeError: Number is not a value that passed validationNPI
is.NPI(value) -> true | false
as.NPI(value) -> value | TypeError: Number is not a value that passed validationDescription:
Checks if the provided argument is a valid NPI (National Provider Identifier).
is.NPI(arg):
- Returns
trueifargis a valid NPI. - Returns
falseotherwise.
- Returns
as.NPI(arg):
- Returns
argif it is a valid NPI. - Throws
TypeErrorifargis not a valid NPI.
- Returns
Example:
is.NPI(1234567890); // Returns true
is.NPI(123456789); // Returns false
as.NPI(1234567890); // Returns 1234567890
as.NPI(123456789); // Throws TypeError: Number is not a value that passed validationString Validators
Here is the restructured documentation for the string validation methods:
Alphabetic
is.alphabetic(value) -> true | false
as.alphabetic(value) -> value | TypeError: String is not alphabeticDescription:
Checks if the provided argument is an alphabetic string.
is.alphabetic(arg):
- Returns
trueifargcontains only alphabetic characters. - Returns
falseotherwise.
- Returns
as.alphabetic(arg):
- Returns
argif it contains only alphabetic characters. - Throws
TypeErrorifargdoes not contain only alphabetic characters.
- Returns
Example:
is.alphabetic('hello'); // Returns true
is.alphabetic('hello123'); // Returns false
as.alphabetic('hello'); // Returns 'hello'
as.alphabetic('hello123'); // Throws TypeError: String is not alphabeticDigit
is.digit(value) -> true | false
as.digit(value) -> value | TypeError: String is not digitDescription:
Checks if the provided argument is an digit string.
is.digit(arg):
- Returns
trueifargcontains only digit characters. - Returns
falseotherwise.
- Returns
as.digit(arg):
- Returns
argif it contains only digit characters. - Throws
TypeErrorifargdoes not contain only digit characters.
- Returns
Example:
is.digit('123'); // Returns true
is.digit('hello123'); // Returns false
as.digit('123'); // Returns '123'
as.digit('hello123'); // Throws TypeError: String is not digitLowercase
is.lowercase(value) -> true | false
as.lowercase(value) -> value | TypeError: String is not lowercaseDescription:
Checks if the provided argument is a lowercase string.
is.lowercase(arg):
- Returns
trueifargis a lowercase string. - Returns
falseotherwise.
- Returns
as.lowercase(arg):
- Returns
argif it is a lowercase string. - Throws
TypeErrorifargis not a lowercase string.
- Returns
Example:
is.lowercase('hello'); // Returns true
is.lowercase('Hello'); // Returns false
as.lowercase('hello'); // Returns 'hello'
as.lowercase('Hello'); // Throws TypeError: String is not lowercaseUppercase
is.uppercase(value) -> true | false
as.uppercase(value) -> value | TypeError: String is not uppercaseDescription:
Checks if the provided argument is an uppercase string.
is.uppercase(arg):
- Returns
trueifargis an uppercase string. - Returns
falseotherwise.
- Returns
as.uppercase(arg):
- Returns
argif it is an uppercase string. - Throws
TypeErrorifargis not an uppercase string.
- Returns
Example:
is.uppercase('HELLO'); // R10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
11 months ago
11 months ago
10 months ago
11 months ago
12 months ago
10 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago