README

Pro-script Library Documentation
https://pro-script.gitbook.io/as-is
Please update to 1.6+ version. Major bugs have been fixed, and a validation error feature has been added.
The NEW Enum functionality !!!
This is example of old variant
Enum.init('enum object here'); // where init is mandatoryThis is new functionality
Enum.roles({ // now roles it's a name of stored enum inside of the as/is proxy
admin: 0,
user: 1
});
as.roles('admin'); // -> admin
as.roles('fakeRole'); // -> TypeError: String is not a(an) member of roles enum
Ofc an old Enum checker works too
const enumName = Enum.roles({
admin: 0,
user: 1
});
as.Enum(enumName); // -> Enum { '0': 'admin', '1': 'user', admin: 0, user: 1 }Now you can use enums in types like this
The Check password added to strings validator.
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
For Browsers
Without module:
With module:
Usage
Node.js (ESM)
Node.js (CommonJS)
Browser
Without module:
With module:
With import map:
in global scope
or
in global scope
After that you can use an as or is etc in other files without an import.
Everything in one code block
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
Strict type object:
Class checking:
[className]
[classInstance]
Interface Interfaces works only in the set way where IName = { * interface data * }, not like IName({ * interface data * })
Types Types works only in the apply way where TName({ * types data * }), not like interfaces TName = { * types data * }
Integration
You can integrate any feature you want.
Instancing
Minimal set of methods.
All methods without plugins.
All methods with plugins.
Type Checks
String
Description:
Checks if the provided argument is a string.
is.string(arg):
Returns
trueifargis a string.Returns
falseotherwise.
as.string(arg):
Returns
argif it is a string.Throws
TypeErrorif
arg is not a string.
Example:
Number
Description:
Checks if the provided argument is a number.
is.number(arg):
Returns
trueifargis a number.Returns
falseotherwise.
as.number(arg):
Returns
argif it is a number.Throws
TypeErrorifargis not a number.
Example:
Boolean
Description:
Checks if the provided argument is a boolean.
is.boolean(arg):
Returns
trueifargis a boolean.Returns
falseotherwise.
as.boolean(arg):
Returns
argif it is a boolean.Throws
TypeErrorifargis not a boolean.
Example:
Symbol
Description:
Checks if the provided argument is a symbol.
is.symbol(arg):
Returns
trueifargis a symbol.Returns
falseotherwise.
as.symbol(arg):
Returns
argif it is a symbol.Throws
TypeErrorifargis not a symbol.
Example:
Function
Description:
Checks if the provided argument is a function.
is.function(arg):
Returns
trueifargis a function.Returns
falseotherwise.
as.function(arg):
Returns
argif it is a function.Throws
TypeErrorifargis not a function.
Example:
BigInt
Description:
Checks if the provided argument is a BigInt.
is.bigInt(arg):
Returns
trueifargis a BigInt.Returns
falseotherwise.
as.bigInt(arg):
Returns
argif it is a BigInt.Throws
TypeErrorifargis not a BigInt.
Example:
Array
Description:
Checks if the provided argument is an array.
is.array(arg):
Returns
trueifargis an array.Returns
falseotherwise.
as.array(arg):
Returns
argif it is an array.Throws
TypeErrorifargis not an array.
Example:
Date
Description:
Checks if the provided argument is a date.
is.date(arg):
Returns
trueifargis a date.Returns
falseotherwise.
as.date(arg):
Returns
argif it is a date.Throws
TypeErrorifargis not a date.
Example:
Object
Description:
Checks if the provided argument is an object.
is.object(arg):
Returns
trueifargis an object.Returns
falseotherwise.
as.object(arg):
Returns
argif it is an object.Throws
TypeErrorifargis not an object.
Example:
Set
Description:
Checks if the provided argument is a set.
is.set(arg):
Returns
trueifargis a set.Returns
falseotherwise.
as.set(arg):
Returns
argif it is a set.Throws
TypeErrorifargis not a set.
Example:
Map
Description:
Checks if the provided argument is a map.
is.map(arg):
Returns
trueifargis a map.Returns
falseotherwise.
as.map(arg):
Returns
argif it is a map.Throws
TypeErrorifargis not a map.
Example:
WeakSet
Description:
Checks if the provided argument is a WeakSet.
is.weakSet(arg):
Returns
trueifargis a WeakSet.Returns
falseotherwise.
as.weakSet(arg):
Returns
argif it is a WeakSet.Throws
TypeErrorifargis not a WeakSet.
Example:
WeakMap
Description:
Checks if the provided argument is a WeakMap.
is.weakMap(arg):
Returns
trueifargis a WeakMap.Returns
falseotherwise.
as.weakMap(arg):
Returns
argif it is a WeakMap.Throws
TypeErrorifargis not a WeakMap.
Example:
RegExp
Description:
Checks if the provided argument is a regular expression.
is.regExp(arg):
Returns
trueifargis a regular expression.Returns
falseotherwise.
as.regExp(arg):
Returns
argif it is a regular expression.Throws
TypeErrorifargis not a regular expression.
Example:
Promise
Description:
Checks if the provided argument is a Promise.
is.promise(arg):
Returns
trueifargis a Promise.Returns
falseotherwise.
as.promise(arg):
Returns
argif it is a Promise.Throws
TypeErrorifargis not a Promise.
Example:
Generator
Description:
Checks if the provided argument is a Generator.
is.generator(arg):
Returns
trueifargis a Generator.Returns
falseotherwise.
as.generator(arg):
Returns
argif it is a Generator.Throws
TypeErrorifargis not a Generator.
Example:
Here is the documentation for the additional type checks:
TypedArray
Description:
Checks if the provided argument is a TypedArray.
is.typedArray(arg):
Returns
trueifargis a TypedArray.Returns
falseotherwise.
as.typedArray(arg):
Returns
argif it is a TypedArray.Throws
TypeErrorifargis not a TypedArray.
Example:
Buffer
Description:
Checks if the provided argument is a Buffer.
is.buffer(arg):
Returns
trueifargis a Buffer.Returns
falseotherwise.
as.buffer(arg):
Returns
argif it is a Buffer.Throws
TypeErrorifargis not a Buffer.
Example:
SharedArrayBuffer
Description:
Checks if the provided argument is a SharedArrayBuffer.
is.sharedArrayBuffer(arg):
Returns
trueifargis a SharedArrayBuffer.Returns
falseotherwise.
as.sharedArrayBuffer(arg):
Returns
argif it is a SharedArrayBuffer.Throws
TypeErrorifargis not a SharedArrayBuffer.
Example:
Date
Description:
Checks if the provided argument is a Date object.
is.date(arg):
Returns
trueifargis a Date object.Returns
falseotherwise.
as.date(arg):
Returns
argif it is a Date object.Throws
TypeErrorifargis not a Date object.
Example:
Object
Description:
Checks if the provided argument is an object.
is.object(arg):
Returns
trueifargis an object.Returns
falseotherwise.
as.object(arg):
Returns
argif it is an object.Throws
TypeErrorifargis not an object.
Example:
Class
Description:
Checks if the provided argument is a class.
is.class(arg):
Returns
trueifargis a class.Returns
falseotherwise.
as.class(arg):
Returns
argif it is a class.Throws
TypeErrorifargis not a class.
Example:
Instance
Description:
Checks if the provided argument is an instance of the specified class.
is.instance(arg, constructor):
Returns
trueifargis an instance ofconstructor.Returns
falseotherwise.
as.instance(arg, constructor):
Returns
argif it is an instance ofconstructor.Throws
TypeErrorifargis not an instance ofconstructor.
Example:
Iterator
Description:
Checks if the provided argument is an iterator.
is.iterator(arg):
Returns
trueifargis an iterator.Returns
falseotherwise.
as.iterator(arg):
Returns
argif it is an iterator.Throws
TypeErrorifargis not an iterator.
Example:
Undefined
It's a very specific type checking. To check if a value is exactly undefined.
Description:
Checks if the provided argument is undefined.
is.undefined(arg):
Returns
trueifargis undefined.Returns
falseotherwise.
as.undefined(arg):
Returns
argif it is undefined.Throws
TypeErrorifargis not Example:
Nullish
Description:
Checks if the provided argument is null or undefined.
is.nullish(arg):
Returns
trueifargis null or undefined.Returns
falseotherwise.
as.nullish(arg):
Returns
argif it is null or undefined.Throws
TypeErrorifargis not null or undefined.
Example:
Error
Description:
Checks if the provided argument is an Error.
is.error(arg):
Returns
trueifargis an Error.Returns
falseotherwise.
as.error(arg):
Returns
argif it is an Error.Throws
TypeErrorifargis not an Error.
Example:
RangeError
Description:
Checks if the provided argument is a RangeError.
is.rangeError(arg):
Returns
trueifargis a RangeError.Returns
falseotherwise.
as.rangeError(arg):
Returns
argif it is a RangeError.Throws
TypeErrorifargis not a RangeError.
Example:
ReferenceError
Description:
Checks if the provided argument is a ReferenceError.
is.referenceError(arg):
Returns
trueifargis a ReferenceError.Returns
falseotherwise.
as.referenceError(arg):
Returns
argif it is a ReferenceError.Throws
TypeErrorifargis not a ReferenceError.
Example:
SyntaxError
Description:
Checks if the provided argument is a SyntaxError.
is.syntaxError(arg):
Returns
trueifargis a SyntaxError.Returns
falseotherwise.
as.syntaxError(arg):
Returns
argif it is a SyntaxError.Throws
TypeErrorifargis not a SyntaxError.
Example:
TypeError
Description:
Checks if the provided argument is a TypeError.
is.typeError(arg):
Returns
trueifargis a TypeError.Returns
falseotherwise.
as.typeError(arg):
Returns
argif it is a TypeError.Throws
TypeErrorifargis not a TypeError.
Example:
Any
Description:
Checks if the provided argument is any value.
is.any(arg):
Returns
trueifargis any value.Returns
falseotherwise.
as.any(arg):
Returns
argif it is any value.Throws
TypeErrorifargis not any value.
Example:
Enum type
Enum type Basic
Enum type Basic usage
Use increment
Use decrement
Use both
Use with step
Check the Enum type like this
Build-in validators
This list of validators works with a minimum set of methods.
Empty
Description:
Checks if the provided argument is empty.
is.empty(arg):
Returns
trueifargis empty.Returns
falseotherwise.
as.empty(arg):
Returns
argif it is empty.Throws
TypeErrorifargis not empty.
Example:
NotEmpty
Description:
Checks if the provided argument is not empty.
is.notEmpty(arg):
Returns
trueifargis not empty.Returns
falseotherwise.
as.notEmpty(arg):
Returns
argif it is not empty.Throws
TypeErrorifargis empty.
Example:
JSON
Description:
Checks if the provided argument is a valid JSON string.
is.json(arg):
Returns
trueifargis a valid JSON string.Returns
falseotherwise.
**
as.json(arg):**
Returns
argif it is a valid JSON string.Throws
TypeErrorifargis not a valid JSON string.
Example:
JSON5
Description:
Checks if the provided argument is a valid JSON5 string.
is.json5(arg):
Returns
trueifargis a valid JSON5 string.Returns
falseotherwise.
as.json5(arg):
Returns
argif it is a valid JSON5 string.Throws
TypeErrorifargis not a valid JSON5 string.
Example:
Null
Description:
Checks if the provided argument is null.
is.null(arg):
Returns
trueifargis null.Returns
falseotherwise.
as.null(arg):
Returns
argif it is null.Throws
TypeErrorifargis not null.
Example:
Number Validators
Sure, I'll restructure the documentation as requested. Here is the first part of the updated documentation:
Zero
Description:
Checks if the provided argument is exactly zero.
is.zero(arg):
Returns
trueifargis0.Returns
falseotherwise.
as.zero(arg):
Returns
argif it is0.Throws
TypeErrorifargis not0.
Example:
Even
Description:
Checks if the provided argument is an even number.
is.even(arg):
Returns
trueifargis even.Returns
falseotherwise.
as.even(arg):
Returns
argif it is even.Throws
TypeErrorifargis not even.
Example:
Odd
Description:
Checks if the provided argument is an odd number.
is.odd(arg):
Returns
trueifargis odd.Returns
falseotherwise.
as.odd(arg):
Returns
argif it is odd.Throws
TypeErrorifargis not odd.
Example:
Positive
Description:
Checks if the provided argument is a positive number.
is.positive(arg):
Returns
trueifargis positive.Returns
falseotherwise.
as.positive(arg):
Returns
argif it is positive.Throws
TypeErrorifargis not positive.
Example:
Negative
Description:
Checks if the provided argument is a negative number.
is.negative(arg):
Returns
trueifargis negative.Returns
falseotherwise.
as.negative(arg):
Returns
argif it is negative.Throws
TypeErrorifargis not negative.
Example:
Positive Integer
Description:
Checks if the provided argument is a positive integer.
is.positiveInteger(arg):
Returns
trueifargis a positive integer.Returns
falseotherwise.
as.positiveInteger(arg):
Returns
argif it is a positive integer.Throws
TypeErrorifargis not a positive integer.
Example:
Negative Integer
Description:
Checks if the provided argument is a negative integer.
is.negativeInteger(arg):
Returns
trueifargis a negative integer.Returns
falseotherwise.
as.negativeInteger(arg):
Returns
argif it is a negative integer.Throws
TypeErrorifargis not a negative integer.
Example:
Finite
Description:
Checks if the provided argument is a finite number.
is.isFinite(arg):
Returns
trueifargis finite.Returns
falseotherwise.
as.isFinite(arg):
Returns
argif it is finite.Throws
TypeErrorifargis not finite.
Example:
NaN
Description:
Checks if the provided argument is NaN (Not-a-Number).
is.NaN(arg):
Returns
trueifargis NaN.Returns
falseotherwise.
as.NaN(arg):
Returns
argif it is NaN.Throws
TypeErrorifargis not NaN.
Example:
Between
Description:
Checks if the provided argument is between min and max values.
is.between({ arg, min, max }):
Returns
trueifargis betweenminandmax.Returns
falseotherwise.
as.between({ arg, min, max }):
Returns
argif it is betweenminandmax.Throws
TypeErrorifargis not betweenminandmax.
Example:
Greater
Description:
Checks if the provided argument is greater than the specified value.
is.greater({ arg, value }):
Returns
trueifargis greater thanvalue.Returns `
false` otherwise.
as.greater({ arg, value }):
Returns
argif it is greater thanvalue.Throws
TypeErrorifargis not greater thanvalue.
Example:
Less
Description:
Checks if the provided argument is less than the specified value.
is.less({ arg, value }):
Returns
trueifargis less thanvalue.Returns
falseotherwise.
as.less({ arg, value }):
Returns
argif it is less thanvalue.Throws
TypeErrorifargis not less thanvalue.
Example:
Equal or Greater
Description:
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.
as.equalGreater({ arg, value }):
Returns
argif it is equal to or greater thanvalue.Throws
TypeErrorifargis not equal to or greater thanvalue.
Example:
Equal or Less
Description:
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.
as.equalLess({ arg, value }):
Returns
argif it is equal to or less thanvalue.Throws
TypeErrorifargis not equal to or less thanvalue.
Example:
Max
Description:
Checks if the provided argument is equal to the specified maximum value.
is.max({ arg, value }):
Returns
trueifargis equal to the maximumvalue.Returns
falseotherwise.
as.max({ arg, value }):
Returns
argif it is equal to the maximumvalue.Throws
TypeErrorifargis not equal to the maximumvalue.
Example:
Min
Description:
Checks if the provided argument is equal to the specified minimum value.
is.min({ arg, value }):
Returns
trueifargis equal to the minimumvalue.Returns
falseotherwise.
as.min({ arg, value }):
Returns
argif it is equal to the minimumvalue.Throws
TypeErrorifargis not equal to the minimumvalue.
Example:
Multiple
Description:
Checks if the provided argument is a multiple of the specified value.
is.multiple({ arg, value }):
Returns
trueifargis a multiple ofvalue.Returns
falseotherwise.
as.multiple({ arg, value }):
Returns
argif it is a multiple ofvalue.Throws
TypeErrorifargis not a multiple ofvalue.
Example:
Port
Description:
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.
as.port(arg):
Returns
argif it is a valid port number.Throws
TypeErrorifargis not a valid port number.
Example:
Safe Integer
Description:
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.
as.safe(arg):
Returns
argif it is a safe integer.Throws
TypeErrorifargis not a safe integer.
Example:
Precision
Description:
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.
Example:
Digits
Description:
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.
as.digits({ arg, value }):
Returns
argif it has the specified number of digitsvalue.Throws
TypeErrorifargdoes not have the specified number of digitsvalue.
Example:
ISBN-10
Description:
Checks if the provided argument is a valid ISBN-10 number.
is.ISBN10(arg):
Returns
trueifargis a valid ISBN-10 number.Returns
falseotherwise.
as.ISBN10(arg):
Returns
argif it is a valid ISBN-10 number.Throws
TypeErrorifargis not a valid ISBN-10 number.
Example:
ISBN-13
Description:
Checks if the provided argument is a valid ISBN-13 number.
is.ISBN13(arg):
Returns
trueifargis a valid ISBN-13 number.Returns
falseotherwise.
as.ISBN13(arg):
Returns
argif it is a valid ISBN-13 number.Throws
TypeErrorifargis not a valid ISBN-13 number.
Example:
EAN
Description:
Checks if the provided argument is a valid EAN (European Article Number).
is.EAN(arg):
Returns
trueifargis a valid EAN.Returns
falseotherwise.
as.EAN(arg):
Returns
argif it is a valid EAN.Throws
TypeErrorifargis not a valid EAN.
Example:
SSN
Description:
Checks if the provided argument is a valid SSN (Social Security Number).
is.SSN(arg):
Returns
trueifargis a valid SSN.Returns
falseotherwise.
as.SSN(arg):
Returns
argif it is a valid SSN.Throws
TypeErrorifargis not a valid SSN.
Example:
VIN
Description:
Checks if the provided argument is a valid VIN (Vehicle Identification Number).
is.VIN(arg):
Returns
trueifargis a valid VIN.Returns
falseotherwise.
as.VIN(arg):
Returns
argif it is a valid VIN.Throws
TypeErrorifargis not a valid VIN.
Example:
INN-10
Description:
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.
as.INN10(arg):
Returns
argif it is a valid INN with 10 digits.Throws
TypeErrorifargis not a valid INN with 10 digits.
Example:
INN-12
Description:
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.
as.INN12(arg):
Returns
argif it is a valid INN with 12 digits.Throws
TypeErrorifargis not a valid INN with 12 digits.
Example:
GLN
Description:
Checks if the provided argument is a valid GLN (Global Location Number).
is.GLN(arg):
Returns
trueifargis
a valid GLN.
Returns
falseotherwise.as.GLN(arg):
Returns
argif it is a valid GLN.Throws
TypeErrorifargis not a valid GLN.
Example:
IMEI
Description:
Checks if the provided argument is a valid IMEI (International Mobile Equipment Identity).
is.IMEI(arg):
Returns
trueifargis a valid IMEI.Returns
falseotherwise.
as.IMEI(arg):
Returns
argif it is a valid IMEI.Throws
TypeErrorifargis not a valid IMEI.
Example:
NPI
Description:
Checks if the provided argument is a valid NPI (National Provider Identifier).
is.NPI(arg):
Returns
trueifargis a valid NPI.Returns
falseotherwise.
as.NPI(arg):
Returns
argif it is a valid NPI.Throws
TypeErrorifargis not a valid NPI.
Example:
String Validators
Here is the restructured documentation for the string validation methods:
Alphabetic
Description:
Checks if the provided argument is an alphabetic string.
is.alphabetic(arg):
Returns
trueifargcontains only alphabetic characters.Returns
falseotherwise.
as.alphabetic(arg):
Returns
argif it contains only alphabetic characters.Throws
TypeErrorifargdoes not contain only alphabetic characters.
Example:
Digit
Description:
Checks if the provided argument is an digit string.
is.digit(arg):
Returns
trueifargcontains only digit characters.Returns
falseotherwise.
as.digit(arg):
Returns
argif it contains only digit characters.Throws
TypeErrorifargdoes not contain only digit characters.
Example:
Lowercase
Description:
Checks if the provided argument is a lowercase string.
is.lowercase(arg):
Returns
trueifargis a lowercase string.Returns
falseotherwise.
as.lowercase(arg):
Returns
argif it is a lowercase string.Throws
TypeErrorifargis not a lowercase string.
Example:
Uppercase
Description:
Checks if the provided argument is an uppercase string.
is.uppercase(arg):
Returns
trueifargis an uppercase string.Returns
falseotherwise.
as.uppercase(arg):
Returns
argif it is an uppercase string.Throws
TypeErrorifargis not an uppercase string.
Example:
CamelCase
Description:
Checks if the provided argument is a camelCase string.
is.camelCase(arg):
Returns
trueifargis a camelCase string.Returns
falseotherwise.
as.camelCase(arg):
Returns
argif it is a camelCase string.Throws
TypeErrorifargis not a camelCase string.
Example:
snakeCase
Description:
Checks if the provided argument is a snakeCase string.
is.snakeCase(arg):
Returns
trueifargis a snakeCase string.Returns
falseotherwise.
as.snakeCase(arg):
Returns
argif it is a snakeCase string.Throws
TypeErrorifargis not a snakeCase string.
Example:
Kebab-Case
Description:
Checks if the provided argument is a kebab-case string.
is.kebabCase(arg):
Returns
trueifargis a kebab-case string.Returns
falseotherwise.
as.kebabCase(arg):
Returns
argif it is a kebab-case string.Throws
TypeErrorifargis not a kebab-case string.
Example:
Train-Case
Description:
Checks if the provided argument is a train-Case string.
is.trainCase(arg):
Returns
trueifargis a train-Case string.Returns
falseotherwise.
as.trainCase(arg):
Returns
argif it is a train-Case string.Throws
TypeErrorifargis not a train-Case string.
Example:
Path
Description:
Checks if the provided argument is a valid path.
is.path(arg):
Returns
trueifargis a valid path.Returns
falseotherwise.
as.path(arg):
Returns
argif it is a valid path.Throws
TypeErrorifargis not a valid path.
Example:
UUID
Description:
Checks if the provided argument is a valid UUID.
is.uuid(arg):
Returns
trueifargis a valid UUID.Returns
falseotherwise.
as.uuid(arg):
Returns
argif it is a valid UUID.Throws
TypeErrorifargis not a valid UUID.
Example:
HTTP URL
Description:
Checks if the provided argument is a valid HTTP URL.
is.http(arg):
Returns
trueifargis a valid HTTP URL.Returns
falseotherwise.
as.http(arg):
Returns
argif it is a valid HTTP URL.Throws
TypeErrorifargis not a valid HTTP URL.
Example:
HTTPS URL
Description:
Checks if the provided argument is a valid HTTPS URL.
is.https(arg):
Returns
trueifargis a valid HTTPS URL.Returns
falseotherwise
.
as.https(arg):
Returns
argif it is a valid HTTPS URL.Throws
TypeErrorifargis not a valid HTTPS URL.
Example:
URL
Description:
Checks if the provided argument is a valid URL.
is.url(arg):
Returns
trueifargis a valid URL.Returns
falseotherwise.
as.url(arg):
Returns
argif it is a valid URL.Throws
TypeErrorifargis not a valid URL.
Example:
Email
Description:
Checks if the provided argument is a valid email address.
is.email(arg):
Returns
trueifargis a valid email address.Returns
falseotherwise.
as.email(arg):
Returns
argif it is a valid email address.Throws
TypeErrorifargis not a valid email address.
Example:
IPv4
Description:
Checks if the provided argument is a valid IPv4 address.
is.ipv4(arg):
Returns
trueifargis a valid IPv4 address.Returns
falseotherwise.
as.ipv4(arg):
Returns
argif it is a valid IPv4 address.Throws
TypeErrorifargis not a valid IPv4 address.
Example:
IPv6
Description:
Checks if the provided argument is a valid IPv6 address.
is.ipv6(arg):
Returns
trueifargis a valid IPv6 address.Returns
falseotherwise.
as.ipv6(arg):
Returns
argif it is a valid IPv6 address.Throws
TypeErrorifargis not a valid IPv6 address.
Example:
IP
Description:
Checks if the provided argument is a valid IP address (either IPv4 or IPv6).
is.ip(arg):
Returns
trueifargis a valid IP address.Returns
falseotherwise.
as.ip(arg):
Returns
argif it is a valid IP address.Throws
TypeErrorifargis not a valid IP address.
Example:
File Extension
Description:
Checks if the provided argument is a valid file extension.
is.fileExtension(arg):
Returns
trueifargis a valid file extension.Returns
falseotherwise.
as.fileExtension(arg):
Returns
argif it is a valid file extension.Throws
TypeErrorifargis not a valid file extension.
Example:
Hex Color
Description:
Checks if the provided argument is a valid hex color code.
is.hexColor(arg):
Returns
trueifargis a valid hex color code.Returns
falseotherwise.
as.hexColor(arg):
Returns
argif it is a valid hex color code.Throws
TypeErrorifargis not a valid hex color code.
Example:
Base64
Description:
Checks if the provided argument is a valid base64 encoded string.
is.base64(arg):
Returns
trueifargis a valid base64 encoded string.Returns
falseotherwise.
as.base64(arg):
Returns
argif it is a valid base64 encoded string.Throws
TypeErrorifargis not a valid base64 encoded string.
Example:
Data URL
Description:
Checks if the provided argument is a valid data URL.
is.dataURL(arg):
Returns
trueifargis a valid data URL.Returns
falseotherwise.
as.dataURL(arg):
Returns
argif it is a valid data
URL.
Throws
TypeErrorifargis not a valid data URL.
Example:
Credit Card
Description:
Checks if the provided argument is a valid credit card number.
is.creditCard(arg):
Returns
trueifargis a valid credit card number.Returns
falseotherwise.
as.creditCard(arg):
Returns
argif it is a valid credit card number.Throws
TypeErrorifargis not a valid credit card number.
Example:
MasterCard
Description:
Checks if the provided argument is a valid MasterCard number.
is.masterCard(arg):
Returns
trueifargis a valid MasterCard number.Returns
falseotherwise.
as.masterCard(arg):
Returns
argif it is a valid MasterCard number.Throws
TypeErrorifargis not a valid MasterCard number.
Example:
Visa
Description:
Checks if the provided argument is a valid Visa number.
is.visa(arg):
Returns
trueifargis a valid Visa number.Returns
falseotherwise.
as.visa(arg):
Returns
argif it is a valid Visa number.Throws
TypeErrorifargis not a valid Visa number.
Example:
American Express
Description:
Checks if the provided argument is a valid American Express number.
is.americanExpress(arg):
Returns
trueifargis a valid American Express number.Returns
falseotherwise.
as.americanExpress(arg):
Returns
argif it is a valid American Express number.Throws
TypeErrorifargis not a valid American Express number.
Example:
Diners Club
Description:
Checks if the provided argument is a valid Diners Club number.
is.dinersClub(arg):
Returns
trueifargis a valid Diners Club number.Returns
falseotherwise.
as.dinersClub(arg):
Returns
argif it is a valid Diners Club number.Throws
TypeErrorifargis not a valid Diners Club number.
Example:
Domain
Description:
Checks if the provided argument is a valid domain.
is.domain(arg):
Returns
trueifargis a valid domain.Returns
falseotherwise.
as.domain(arg):
Returns
argif it is a valid domain.Throws
TypeErrorifargis not a valid domain.
Example:
GUID
Description:
Checks if the provided argument is a valid GUID.
is.guid(arg):
Returns
trueifargis a valid GUID.Returns
falseotherwise.
as.guid(arg):
Returns
argif it is a valid GUID.Throws
TypeErrorifargis not a valid GUID.
Example:
Hostname
Description:
Checks if the provided argument is a valid hostname.
is.hostname(arg):
Returns
trueifargis a valid hostname.Returns
falseotherwise.
as.hostname(arg):
Returns
argif it is a valid hostname.Throws
TypeErrorifargis not a valid hostname.
Example:
ISO Date
Description:
Checks if the provided argument is a valid ISO date.
is.isoDate(arg):
Returns
trueifargis a valid ISO date.Returns
falseotherwise.
as.isoDate(arg):
Returns
argif it is a valid ISO date.Throws
TypeErrorifargis not a valid ISO date.
Example:
ISO Duration
Description:
Checks if the provided argument is a valid ISO duration.
is.isoDuration(arg):
Returns
trueifargis a valid ISO duration.Returns
falseotherwise.
as.isoDuration(arg):
Returns
argif it is a valid ISO duration.Throws
TypeErrorifargis not a valid ISO duration.
Example:
JWT
Description:
Checks if the provided argument is a valid JWT.
is.jwt(arg):
Returns
trueifargis a valid JWT.Returns
falseotherwise.
as.jwt(arg):
Returns
argif it is a valid JWT.Throws
TypeErrorifargis not a valid JWT.
Example:
Emoji
Description:
Checks if the provided argument is a valid emoji.
is.emoji(arg):
Returns
trueifargis a valid emoji.Returns
falseotherwise.
as.emoji(arg):
Returns
argif it is a valid emoji.Throws
TypeErrorifargis not a valid emoji.
Example:
Nanoid
Description:
Checks if the provided argument is a valid nanoid.
is.nanoid(arg):
Returns
trueifargis a valid nanoid.Returns
falseotherwise.
as.nanoid(arg):
Returns
argif it is a valid nanoid.Throws
TypeErrorifargis not a valid nanoid.
Example:
CUID
Description:
Checks if the provided argument is a valid CUID.
is.cuid(arg):
Returns
trueifargis a valid CUID.Returns
falseotherwise.
as.cuid(arg):
Returns
argif it is a valid CUID.Throws
TypeErrorifargis not a valid CUID.
Example:
CUID2
Description:
Checks if the provided argument is a valid CUID2.
is.cuid2(arg):
Returns
trueifargis a valid CUID2.Returns
falseotherwise.
as.cuid2(arg):
Returns
argif it is a valid CUID2.Throws
TypeErrorifargis not a valid CUID2.
Example:
Excludes
Description:
Checks if the provided argument excludes a given substring.
is.excludes({ arg, value }):
Returns
trueifargexcludesvalue.Returns
falseotherwise.
as.excludes({ arg, value }):
Returns
argif it excludesvalue.Throws
TypeErrorifargincludesvalue.
Example:
Time (HH:MM:SS)
Description:
Checks if the provided argument is a valid time in the format HH:MM:SS.
is.time(arg):
Returns
trueifargis a valid time.Returns
falseotherwise.
as.time(arg):
Returns
argif it is a valid time.Throws
TypeErrorifargis not a valid time.
Example:
DateTime (YYYY-MM-DDTHH:MM:SS)
Description:
Checks if the provided argument is a valid datetime in the format YYYY-MM-DDTHH:MM:SS.
is.datetime(arg):
Returns
trueifargis a valid datetime.Returns
falseotherwise.
as.datetime(arg):
Returns `
arg` if it is a valid datetime.
Throws
TypeErrorifargis not a valid datetime.
Example:
Date (YYYY-MM-DD)
Description:
Checks if the provided argument is a valid date in the format YYYY-MM-DD.
is.date(arg):
Returns
trueifargis a valid date.Returns
falseotherwise.
as.date(arg):
Returns
argif it is a valid date.Throws
TypeErrorifargis not a valid date.
Example:
SHA-256 Hash
Description:
Checks if the provided argument is a valid SHA-256 hash.
is.hash(arg):
Returns
trueifargis a valid SHA-256 hash.Returns
falseotherwise.
as.hash(arg):
Returns
argif it is a valid SHA-256 hash.Throws
TypeErrorifargis not a valid SHA-256 hash.
Example:
ISO Time with Seconds
Description:
Checks if the provided argument is a valid ISO time with seconds.
is.isoTimeSecond(arg):
Returns
trueifargis a valid ISO time with seconds.Returns
falseotherwise.
as.isoTimeSecond(arg):
Returns
argif it is a valid ISO time with seconds.Throws
TypeErrorifargis not a valid ISO time with seconds.
Example:
ISO Timestamp
Description:
Checks if the provided argument is a valid ISO timestamp.
is.isoTimestamp(arg):
Returns
trueifargis a valid ISO timestamp.Returns
falseotherwise.
as.isoTimestamp(arg):
Returns
argif it is a valid ISO timestamp.Throws
TypeErrorifargis not a valid ISO timestamp.
Example:
ISO Week
Description:
Checks if the provided argument is a valid ISO week.
is.isoWeek(arg):
Returns
trueifargis a valid ISO week.Returns
falseotherwise.
as.isoWeek(arg):
Returns
argif it is a valid ISO week.Throws
TypeErrorifargis not a valid ISO week.
Example:
MAC Address
Description:
Checks if the provided argument is a valid MAC address.
is.mac(arg):
Returns
trueifargis a valid MAC address.Returns
falseotherwise.
as.mac(arg):
Returns
argif it is a valid MAC address.Throws
TypeErrorifargis not a valid MAC address.
Example:
MAC-48 Address
Description:
Checks if the provided argument is a valid MAC-48 address.
is.mac48(arg):
Returns
trueifargis a valid MAC-48 address.Returns
falseotherwise.
as.mac48(arg):
Returns
argif it is a valid MAC-48 address.Throws
TypeErrorifargis not a valid MAC-48 address.
Example:
MAC-64 Address
Description:
Checks if the provided argument is a valid MAC-64 address.
is.mac64(arg):
Returns
trueifargis a valid MAC-64 address.Returns
falseotherwise.
as.mac64(arg):
Returns
argif it is a valid MAC-64 address.Throws
TypeErrorifargis not a valid MAC-64 address.
Example:
Past Date
Description:
Checks if the provided argument is a date in the past.
is.past(arg):
Returns
trueif `
arg` is a date in the past.
Returns
falseotherwise.as.past(arg):
Returns
argif it is a date in the past.Throws
TypeErrorifargis not a date in the past.
Example:
Future Date
Description:
Checks if the provided argument is a date in the future.
is.future(arg):
Returns
trueifargis a date in the future.Returns
falseotherwise.
as.future(arg):
Returns
argif it is a date in the future.Throws
TypeErrorifargis not a date in the future.
Example:
ASCII String
Description:
Checks if the provided argument is an ASCII string.
is.ascii(arg):
Returns
trueifargis an ASCII string.Returns
falseotherwise.
as.ascii(arg):
Returns
argif it is an ASCII string.Throws
TypeErrorifargis not an ASCII string.
Example:
Base32
Description:
Checks if the provided argument is a valid Base32 encoded string.
is.base32(arg):
Returns
trueifargis a valid Base32 encoded string.Returns
falseotherwise.
as.base32(arg):
Returns
argif it is a valid Base32 encoded string.Throws
TypeErrorifargis not a valid Base32 encoded string.
Example:
Base58
Description:
Checks if the provided argument is a valid Base58 encoded string.
is.base58(arg):
Returns
trueifargis a valid Base58 encoded string.Returns
falseotherwise.
as.base58(arg):
Returns
argif it is a valid Base58 encoded string.Throws
TypeErrorifargis not a valid Base58 encoded string.
Example:
Date Before Specific Date
Description:
Checks if the provided argument is a date before a specific date.
is.before({ arg, value }):
Returns
trueifargis beforevalue.Returns
falseotherwise.
as.before({ arg, value }):
Returns
argif it is beforevalue.Throws
TypeErrorifargis not beforevalue.
Example:
Date After Specific Date
Description:
Checks if the provided argument is a date after a specific date.
is.after({ arg, value }):
Returns
trueifargis aftervalue.Returns
falseotherwise.
as.after({ arg, value }):
Returns
argif it is aftervalue.Throws
TypeErrorifargis not aftervalue.
Example:
Maximum String Length
Description:
Checks if the provided argument's length is less than or equal to a specific value.
is.maxStr({ arg, value }):
Returns
trueifarglength is less than or equal tovalue.Returns
falseotherwise.
as.maxStr({ arg, value }):
Returns
argif its length is less than or equal tovalue.Throws
TypeErrorifarglength is greater thanvalue.
Example:
Minimum String Length
Description:
Checks if the provided argument's length is greater than or equal to a specific value.
is.minStr({ arg, value }):
Returns
trueifarglength is greater than or equal tovalue.Returns
falseotherwise.
as.minStr({ arg, value }):
Returns
argif its length is greater than or equal tovalue.Throws
TypeErrorifarglength is less thanvalue.
Example:
Has Uppercase
Description:
Checks if the provided string contains at least one uppercase letter (A-Z).
is.hasUppercase({ arg }):
Returns
trueif the string contains uppercase letters.Returns
falseotherwise.
as.hasUppercase({ arg }):
Returns the original string
argif it contains at least one uppercase letter.Throws
TypeError(e.g.,"String must contain at least one uppercase letter") otherwise.
Example:
Has Lowercase
Description:
Checks if the provided string contains at least one lowercase letter (a-z).
is.hasLowercase({ arg }):
Returns
trueif the string contains lowercase letters.Returns
falseotherwise.
as.hasLowercase({ arg }):
Returns the original string
argif contains at least one lowercase letter.Throws
TypeError(e.g.,"String must contain at least one lowercase letter") otherwise.
Example:
Has Digit
Description:
Checks if the provided string contains at least one digit (0-9).
is.hasDigit({ arg }):
Returns
trueif the string has a digit.Returns
falseotherwise.
as.hasDigit({ arg }):
Returns the original string
argif string contains at least one digit.Throws
TypeError(e.g.,"String must contain at least one digit") otherwise.
Example:
Has Special Character
Description:
Checks if the provided string contains at least one special character (example, !@#$%^&*(),.?":{}|<>).
is.hasSpecialCharacter({ arg }):
Returns
truecontains at least one special character.Returns
falseotherwise.
as.hasSpecialCharacter({ arg }):
Returns the original string
arg, if it contains at least one special character.Throws
TypeError(e.g.,"String must contain at least one special character") otherwise.
Example:
Password
Description:
Checks if the provided string meets all of the following requirements:
Contains at least one uppercase letter.
Contains at least one lowercase letter.
Contains at least one digit.
Contains at least one special character.
Has a minimum 8 characters.
is.password({ arg }):
Returns
truestring meets all of the following requirementsReturns
falseotherwise.
as.password({ arg }):
Returns
arg, if string meets all of the following requirements.Throws
TypeError(example,"String must meet password requirements") otherwise.
Example:
Settings
To customize error messages, you can override Checker.errorMsg. To disable throwing errors, set checker.disabled = true.
Example:
Utility
A simple method to get the type of argument
Aliases
You can check the following types by "is", "as" or javascript, but this looks more readable
Micro-tests Basic usage
There are only five main methods: METHOD, PROPERTY, IS, passed and failed.
METHOD usage
METHOD strictly checks methods.
PROPERTY usage
PROPERTY strictly checks properties.
IS usage
The IS function is a wrapper of "is" method, but with four additional methods like: true, false, ok, notOk. You can check any type with IS, what can do "is".
Any testing framework has many methods and you should learn them before testing. Such as ().to.be.equal or assert.isOk() and more and that means a test development takes more time. Using the one percent improvement principle, you can reduce this time to a minimum by using only IS.true or IS.false and IS.ok or IS.notOk. Nothing else is needed for microtesting. When you need to test anything, you will use a different testing framework.
passed and failed usage
This small functionality will be useful when you need to build your own testing scenario, but don't want to use IS for checking.
IF/ELSE/END
These commands are an alias for the "is" command and are added to make the code easier to read.
IF/ELSE/END Basic usage
When you need to use a couple of variants of function or method calls, you can do the following
Advanced techniques
Checking one repeated type
In object, array, set and map. All types ending in 's' will be checked.
Strict typing
Basics
Basic usage
Use strictObject.values() to get all values.
Once the strict instance has been created, you can do the following:
Strict has reserved variable names: get, set, values, types, variable, lastType. This means that you can do the following;
Only one strict object in one file is possible, if you want to instantiate any other object, you will get a reference to the first one. This is because Strict must have access to the checker engine.
Any tricks will not help you get the second strict object. Maybe I'll find a solution for this because I think it's a bug, not a feature :)
Checking multiple types. It looks like generics in typescript, but more simple implementation.
When a variable is part of more than one type, you can also check for that.
Basic
Basic usage
Macros
To manage syntax and write human-readable code, you might need metaprogramming tools such as macros. When using the architectural pattern of Domain-Driven Design (DDD), you may need to perform a series of validations or type checks for a domain entity. These checks are often required repeatedly, resulting in code that is difficult to read. You could, of course, create your own type or interface, but what do you do when you need to perform some action in addition to type checking and validation that is part of the business logic? In such cases, you can use macros to hide the technical checks under the hood, and the name of the macro will explain what is happening in the domain language.
Basic
[callback1, callback2, ... callbackN].macro is starting array of callbacks. That's it. When [].macro found an object it start his method by name.
Basic usage
callbacks example
Object example
Objects method returns a callback
Only when the array is contain an object or a callback you can repeat the macro.
Weird syntax
If you need to make something weird or unusual you can try this working syntax.
Possible Errors
If you encounter the following error:
Ensure you have a semicolon ; at the end of the previous line.
No Dependencies
This library has no external dependencies.
Last updated