@pro-script/as-is
Version:
Check your types at runtime with ESNext syntax by meta programing in node.js and browser with interfaces, types, strict object and more.
1,866 lines (1,519 loc) • 125 kB
Markdown
<span style="display:block;text-align:center">
<img src="logo.png">
</span>
# Pro-script Library Documentation
https://pro-script.dev
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
1. [Installation](#installation)
2. [Usage](#usage)
- [Instancing](#instancing)
3. [Summary of Features](#summary-of-features)
- [Supported types](#supported-types)
- [Integration](#integration)
4. [Type Checks](#type-checks)
- [String](#string)
- [Number](#number)
- [Boolean](#boolean)
- [Symbol](#symbol)
- [Function](#function)
- [BigInt](#bigint)
- [Array](#array)
- [Date](#date)
- [Object](#object)
- [Set](#set)
- [Map](#map)
- [WeakSet](#weakset)
- [WeakMap](#weakmap)
- [RegExp](#regexp)
- [Promise](#promise)
- [Generator](#generator)
- [TypedArray](#typedarray)
- [Buffer](#buffer)
- [SharedArrayBuffer](#sharedarraybuffer)
- [Date](#date)
- [Object](#object)
- [Class](#class)
- [Instance](#instance)
- [Iterator](#iterator)
- [Nullish](#nullish)
- [Error](#error)
- [RangeError](#rangeerror)
- [ReferenceError](#referenceerror)
- [SyntaxError](#syntaxerror)
- [TypeError](#typeerror)
- [Any](#any)
5. [Enum type](#Enum-type)
6. [Build-in validators](#Build-in-validators)
7. [Number Validators](#number-validators)
- [Zero](#zero)
- [Even](#even)
- [Odd](#odd)
- [Positive](#positive)
- [Negative](#negative)
- [Positive Integer](#positive-integer)
- [Negative Integer](#negative-integer)
- [Finite](#finite)
- [NaN](#nan)
- [Between](#between)
- [Greater](#greater)
- [Less](#less)
- [Equal or Greater](#equal-greater)
- [Equal or Less](#equal-less)
- [Max](#max)
- [Min](#min)
- [Multiple](#multiple)
- [Port](#port)
- [Safe Integer](#safe-integer)
- [Precision](#precision)
- [Digits](#digit)
- [ISBN-10](#isbn-10)
- [ISBN-13](#isbn-13)
- [EAN](#ean)
- [SSN](#ssn)
- [VIN](#vin)
- [INN-10](#inn-10)
- [INN-12](#inn-12)
- [GLN](#gln)
- [IMEI](#imei)
- [NPI](#npi)
8. [String Validators](#string-validators)
- [Alphabetic](#alphabetic)
- [Digit](#digit)
- [Lowercase](#lowercase)
- [Uppercase](#uppercase)
- [CamelCase](#camelcase)
- [SnakeCase](#snakeCase)
- [Kebab-Case](#kebab-case)
- [Train-Case](#train-case)
- [Path](#path)
- [UUID](#uuid)
- [HTTP URL](#http-url)
- [HTTPS URL](#https-url)
- [URL](#url)
- [Email](#email)
- [IPv4](#ipv4)
- [IPv6](#ipv6)
- [IP](#ip)
- [File Extension](#file-extension)
- [Hex Color](#hex-color)
- [Hex String](#hex-string)
- [Base64](#base64)
- [Data URL](#data-url)
- [Credit Card](#credit-card)
- [MasterCard](#mastercard)
- [Visa](#visa)
- [American Express](#american-express)
- [Diners Club](#diners-club)
- [Domain](#domain)
- [GUID](#guid)
- [Hostname](#hostname)
- [ISO Date](#iso-date)
- [ISO Duration](#iso-duration)
- [JWT](#jwt)
- [Emoji](#emoji)
- [Nanoid](#nanoid)
- [CUID](#cuid)
- [CUID2](#cuid2)
- [Excludes](#excludes)
- [Time (HH:MM:SS)](#time-hhmmss)
- [DateTime (YYYY-MM-DDTHH:MM:SS)](#datetime-yyyymmddthhmmss)
- [Date (YYYY-MM-DD)](#date-yyyymmdd)
- [SHA-256 Hash](#sha-256-hash)
- [BcryptHash](#bcrypt-hash)
- [ISO Time with Seconds](#iso-time-with-seconds)
- [ISO Timestamp](#iso-timestamp)
- [ISO Week](#iso-week)
- [MAC Address](#mac-address)
- [MAC-48 Address](#mac-48-address)
- [MAC-64 Address](#mac-64-address)
- [Past Date](#past-date)
- [Future Date](#future-date)
- [ASCII String](#ascii-string)
- [Base32](#base32)
- [Base58](#base58)
- [Date Before Specific Date](#date-before-specific-date)
- [Date After Specific Date](#date-after-specific-date)
- [Maximum String Length](#maximum-string-length)
- [Minimum String Length](#minimum-string-length)
- [Has Uppercase](#has-uppercase)
- [Has Lowercase](#has-lowercase)
- [Has Digit](#has-digit)
- [Has Special Character](#has-special-character)
- [Password](#password)
9. [Utility](#Utility)
10. [Settings](#settings)
11. [Aliases](#aliases)
12. [Micro-tests](#Micro-tests-basic-usage)
13. [Advanced techniques](#advanced-techniques)
- [Checking one repeated type](#checking-one-repeated-type)
- [Working with strict type](#strict-typing)
- [Multi type checking](#checking-multiple-types)
14. [Meta programing. Macros](#macros)
15. [Possible Errors](#possible-errors)
## Installation
```bash
npm install @pro-script/as-is @pro-script/as-is-plugins
```
### For Browsers
Without module:
```html
<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:
```html
<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)
```javascript
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)
```javascript
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:
```html
<script>
const { as, is } = new Checker({ integrate: Object.assign(NumbersValidator, StringsValidator) });
</script>
```
With module:
```html
<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:
```html
<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
```javascript
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
```javascript
Object.assign(global, { multi, Interface, as, is, Enum });
```
or
```javascript
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:**
- [className]
- [classInstance]
```
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 * })
```js
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 * }
```js
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.
```javascript
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 down
```
## Instancing
Minimal set of methods.
```javascript
const { as, is } = new Checker;
```
All methods without plugins.
```javascript
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.
```javascript
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
```javascript
is.string(value) -> true | false
as.string(value) -> value | TypeError: [get.type(value)] is not a(an) string
```
**Description:**
Checks if the provided argument is a string.
- **is.string(arg):**
- Returns `true` if `arg` is a string.
- Returns `false` otherwise.
- **as.string(arg):**
- Returns `arg` if it is a string.
- Throws `TypeError` if
`arg` is not a string.
**Example:**
```javascript
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) string
```
### Number
```javascript
is.number(value) -> true | false
as.number(value) -> value | TypeError: [get.type(value)] is not is not a(an) number
```
**Description:**
Checks if the provided argument is a number.
- **is.number(arg):**
- Returns `true` if `arg` is a number.
- Returns `false` otherwise.
- **as.number(arg):**
- Returns `arg` if it is a number.
- Throws `TypeError` if `arg` is not a number.
**Example:**
```javascript
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) number
```
### Boolean
```javascript
is.boolean(value) -> true | false
as.boolean(value) -> value | TypeError: [get.type(value)] is not a(an) boolean
```
**Description:**
Checks if the provided argument is a boolean.
- **is.boolean(arg):**
- Returns `true` if `arg` is a boolean.
- Returns `false` otherwise.
- **as.boolean(arg):**
- Returns `arg` if it is a boolean.
- Throws `TypeError` if `arg` is not a boolean.
**Example:**
```javascript
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) boolean
```
### Symbol
```javascript
is.symbol(value) -> true | false
as.symbol(value) -> value | TypeError: [get.type(value)] is not a(an) symbol
```
**Description:**
Checks if the provided argument is a symbol.
- **is.symbol(arg):**
- Returns `true` if `arg` is a symbol.
- Returns `false` otherwise.
- **as.symbol(arg):**
- Returns `arg` if it is a symbol.
- Throws `TypeError` if `arg` is not a symbol.
**Example:**
```javascript
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) symbol
```
### Function
```javascript
is.function(value) -> true | false
as.function(value) -> value | TypeError: [get.type(value)] is not a(an) function
```
**Description:**
Checks if the provided argument is a function.
- **is.function(arg):**
- Returns `true` if `arg` is a function.
- Returns `false` otherwise.
- **as.function(arg):**
- Returns `arg` if it is a function.
- Throws `TypeError` if `arg` is not a function.
**Example:**
```javascript
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) function
```
### BigInt
```javascript
is.bigInt(value) -> true | false
as.bigInt(value) -> value | TypeError: [get.type(value)] is not a(an) bigInt
```
**Description:**
Checks if the provided argument is a BigInt.
- **is.bigInt(arg):**
- Returns `true` if `arg` is a BigInt.
- Returns `false` otherwise.
- **as.bigInt(arg):**
- Returns `arg` if it is a BigInt.
- Throws `TypeError` if `arg` is not a BigInt.
**Example:**
```javascript
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) bigInt
```
### Array
```javascript
is.array(value) -> true | false
as.array(value) -> value | TypeError: [get.type(value)] is not a(an) bigInt
```
**Description:**
Checks if the provided argument is an array.
- **is.array(arg):**
- Returns `true` if `arg` is an array.
- Returns `false` otherwise.
- **as.array(arg):**
- Returns `arg` if it is an array.
- Throws `TypeError` if `arg` is not an array.
**Example:**
```javascript
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) array
```
### Date
```javascript
is.date(value) -> true | false
as.date(value) -> value | TypeError: [get.type(value)] is not a(an) date
```
**Description:**
Checks if the provided argument is a date.
- **is.date(arg):**
- Returns `true` if `arg` is a date.
- Returns `false` otherwise.
- **as.date(arg):**
- Returns `arg` if it is a date.
- Throws `TypeError` if `arg` is not a date.
**Example:**
```javascript
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) date
```
### Object
```javascript
is.object(value) -> true | false
as.object(value) -> value | TypeError: [get.type(value)] is not a(an) object
```
**Description:**
Checks if the provided argument is an object.
- **is.object(arg):**
- Returns `true` if `arg` is an object.
- Returns `false` otherwise.
- **as.object(arg):**
- Returns `arg` if it is an object.
- Throws `TypeError` if `arg` is not an object.
**Example:**
```javascript
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) object
```
### Set
```javascript
is.set(value) -> true | false
as.set(value) -> value | TypeError: [get.type(value)] is not a(an) set
```
**Description:**
Checks if the provided argument is a set.
- **is.set(arg):**
- Returns `true` if `arg` is a set.
- Returns `false` otherwise.
- **as.set(arg):**
- Returns `arg` if it is a set.
- Throws `TypeError` if `arg` is not a set.
**Example:**
```javascript
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) set
```
### Map
```javascript
is.map(value) -> true | false
as.map(value) -> value | TypeError: [get.type(value)] is not a(an) map
```
**Description:**
Checks if the provided argument is a map.
- **is.map(arg):**
- Returns `true` if `arg` is a map.
- Returns `false` otherwise.
- **as.map(arg):**
- Returns `arg` if it is a map.
- Throws `TypeError` if `arg` is not a map.
**Example:**
```javascript
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) map
```
### WeakSet
```javascript
is.weakSet(value) -> true | false
as.weakSet(value) -> value | TypeError: [get.type(value)] is not a(an) weakSet
```
**Description:**
Checks if the provided argument is a WeakSet.
- **is.weakSet(arg):**
- Returns `true` if `arg` is a WeakSet.
- Returns `false` otherwise.
- **as.weakSet(arg):**
- Returns `arg` if it is a WeakSet.
- Throws `TypeError` if `arg` is not a WeakSet.
**Example:**
```javascript
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) weakSet
```
### WeakMap
```javascript
is.weakMap(value) -> true | false
as.weakMap(value) -> value | TypeError: [get.type(value)] is not a(an) weakMap
```
**Description:**
Checks if the provided argument is a WeakMap.
- **is.weakMap(arg):**
- Returns `true` if `arg` is a WeakMap.
- Returns `false` otherwise.
- **as.weakMap(arg):**
- Returns `arg` if it is a WeakMap.
- Throws `TypeError` if `arg` is not a WeakMap.
**Example:**
```javascript
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) weakMap
```
### RegExp
```javascript
is.regExp(value) -> true | false
as.regExp(value) -> value | TypeError: [get.type(value)] is not a(an) regExp
```
**Description:**
Checks if the provided argument is a regular expression.
- **is.regExp(arg):**
- Returns `true` if `arg` is a regular expression.
- Returns `false` otherwise.
- **as.regExp(arg):**
- Returns `arg` if it is a regular expression.
- Throws `TypeError` if `arg` is not a regular expression.
**Example:**
```javascript
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) regExp
```
### Promise
```javascript
is.promise(value) -> true | false
as.promise(value) -> value | TypeError: [get.type(value)] is not a(an) promise
```
**Description:**
Checks if the provided argument is a Promise.
- **is.promise(arg):**
- Returns `true` if `arg` is a Promise.
- Returns `false` otherwise.
- **as.promise(arg):**
- Returns `arg` if it is a Promise.
- Throws `TypeError` if `arg` is not a Promise.
**Example:**
```javascript
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) promise
```
### Generator
```javascript
is.generator(value) -> true | false
as.generator(value) -> value | TypeError: [get.type(value)] is not a(an) generator
```
**Description:**
Checks if the provided argument is a Generator.
- **is.generator(arg):**
- Returns `true` if `arg` is a Generator.
- Returns `false` otherwise.
- **as.generator(arg):**
- Returns `arg` if it is a Generator.
- Throws `TypeError` if `arg` is not a Generator.
**Example:**
```javascript
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) generator
```
Here is the documentation for the additional type checks:
### TypedArray
```javascript
is.typedArray(value) -> true | false
as.typedArray(value) -> value | TypeError: TypedArray is not a value that passed validation
```
**Description:**
Checks if the provided argument is a TypedArray.
- **is.typedArray(arg):**
- Returns `true` if `arg` is a TypedArray.
- Returns `false` otherwise.
- **as.typedArray(arg):**
- Returns `arg` if it is a TypedArray.
- Throws `TypeError` if `arg` is not a TypedArray.
**Example:**
```javascript
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) typedArray
```
### Buffer
```javascript
is.buffer(value) -> true | false
as.buffer(value) -> value | TypeError: [get.type(value)] is not a(an) buffer
```
**Description:**
Checks if the provided argument is a Buffer.
- **is.buffer(arg):**
- Returns `true` if `arg` is a Buffer.
- Returns `false` otherwise.
- **as.buffer(arg):**
- Returns `arg` if it is a Buffer.
- Throws `TypeError` if `arg` is not a Buffer.
**Example:**
```javascript
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) buffer
```
### SharedArrayBuffer
```javascript
is.sharedArrayBuffer(value) -> true | false
as.sharedArrayBuffer(value) -> value | TypeError: [get.type(value)] is not a(an) sharedArrayBuffer
```
**Description:**
Checks if the provided argument is a SharedArrayBuffer.
- **is.sharedArrayBuffer(arg):**
- Returns `true` if `arg` is a SharedArrayBuffer.
- Returns `false` otherwise.
- **as.sharedArrayBuffer(arg):**
- Returns `arg` if it is a SharedArrayBuffer.
- Throws `TypeError` if `arg` is not a SharedArrayBuffer.
**Example:**
```javascript
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) sharedArrayBuffer
```
### Date
```javascript
is.date(value) -> true | false
as.date(value) -> value | TypeError: [get.type(value)] is not a(an) date
```
**Description:**
Checks if the provided argument is a Date object.
- **is.date(arg):**
- Returns `true` if `arg` is a Date object.
- Returns `false` otherwise.
- **as.date(arg):**
- Returns `arg` if it is a Date object.
- Throws `TypeError` if `arg` is not a Date object.
**Example:**
```javascript
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) date
```
### Object
```javascript
is.object(value) -> true | false
as.object(value) -> value | TypeError: [get.type(value)] is not a(an) object
```
**Description:**
Checks if the provided argument is an object.
- **is.object(arg):**
- Returns `true` if `arg` is an object.
- Returns `false` otherwise.
- **as.object(arg):**
- Returns `arg` if it is an object.
- Throws `TypeError` if `arg` is not an object.
**Example:**
```javascript
is.object({}); // Returns true
is.object('hello'); // Returns false
as.object({}); // Returns {}
as.object('hello'); // Throws TypeError: String is not a(an) object
```
### Class
```javascript
is.class(value) -> true | false
as.class(value) -> value | TypeError: [get.type(value)] is not a(an) class
```
**Description:**
Checks if the provided argument is a class.
- **is.class(arg):**
- Returns `true` if `arg` is a class.
- Returns `false` otherwise.
- **as.class(arg):**
- Returns `arg` if it is a class.
- Throws `TypeError` if `arg` is not a class.
**Example:**
```javascript
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) class
```
### Instance
```javascript
is.instance(value, constructor) -> true | false
as.instance(value, constructor) -> value | TypeError: [get.type(value)] is not a(an) instance
```
**Description:**
Checks if the provided argument is an instance of the specified class.
- **is.instance(arg, constructor):**
- Returns `true` if `arg` is an instance of `constructor`.
- Returns `false` otherwise.
- **as.instance(arg, constructor):**
- Returns `arg` if it is an instance of `constructor`.
- Throws `TypeError` if `arg` is not an instance of `constructor`.
**Example:**
```javascript
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) instance
```
### Iterator
```javascript
is.iterator(value) -> true | false
as.iterator(value) -> value | TypeError: [get.type(value)] is not a(an) iterator
```
**Description:**
Checks if the provided argument is an iterator.
- **is.iterator(arg):**
- Returns `true` if `arg` is an iterator.
- Returns `false` otherwise.
- **as.iterator(arg):**
- Returns `arg` if it is an iterator.
- Throws `TypeError` if `arg` is not an iterator.
**Example:**
```javascript
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) iterator
```
### Nullish
```javascript
is.nullish(value) -> true | false
as.nullish(value) -> value | TypeError: [get.type(value)] is not a(an) nullish
```
**Description:**
Checks if the provided argument is null or undefined.
- **is.nullish(arg):**
- Returns `true` if `arg` is null or undefined.
- Returns `false` otherwise.
- **as.nullish(arg):**
- Returns `arg` if it is null or undefined.
- Throws `TypeError` if `arg` is not null or undefined.
**Example:**
```javascript
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) nullish
```
### Error
```javascript
is.error(value) -> true | false
as.error(value) -> value | TypeError: [get.type(value)] is not a(an) error
```
**Description:**
Checks if the provided argument is an Error.
- **is.error(arg):**
- Returns `true` if `arg` is an Error.
- Returns `false` otherwise.
- **as.error(arg):**
- Returns `arg` if it is an Error.
- Throws `TypeError` if `arg` is not an Error.
**Example:**
```javascript
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) error
```
### RangeError
```javascript
is.rangeError(value) -> true | false
as.rangeError(value) -> value | TypeError: [get.type(value)] is not a(an) rangeError
```
**Description:**
Checks if the provided argument is a RangeError.
- **is.rangeError(arg):**
- Returns `true` if `arg` is a RangeError.
- Returns `false` otherwise.
- **as.rangeError(arg):**
- Returns `arg` if it is a RangeError.
- Throws `TypeError` if `arg` is not a RangeError.
**Example:**
```javascript
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) rangeError
```
### ReferenceError
```javascript
is.referenceError(value) -> true | false
as.referenceError(value) -> value | TypeError: [get.type(value)] is not a(an) referenceError
```
**Description:**
Checks if the provided argument is a ReferenceError.
- **is.referenceError(arg):**
- Returns `true` if `arg` is a ReferenceError.
- Returns `false` otherwise.
- **as.referenceError(arg):**
- Returns `arg` if it is a ReferenceError.
- Throws `TypeError` if `arg` is not a ReferenceError.
**Example:**
```javascript
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) referenceError
```
### SyntaxError
```javascript
is.syntaxError(value) -> true | false
as.syntaxError(value) -> value | TypeError: [get.type(value)] is not a(an) syntaxError
```
**Description:**
Checks if the provided argument is a SyntaxError.
- **is.syntaxError(arg):**
- Returns `true` if `arg` is a SyntaxError.
- Returns `false` otherwise.
- **as.syntaxError(arg):**
- Returns `arg` if it is a SyntaxError.
- Throws `TypeError` if `arg` is not a SyntaxError.
**Example:**
```javascript
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) syntaxError
```
### TypeError
```javascript
is.typeError(value) -> true | false
as.typeError(value) -> value | TypeError: [get.type(value)] is not a(an) typeError
```
**Description:**
Checks if the provided argument is a TypeError.
- **is.typeError(arg):**
- Returns `true` if `arg` is a TypeError.
- Returns `false` otherwise.
- **as.typeError(arg):**
- Returns `arg` if it is a TypeError.
- Throws `TypeError` if `arg` is not a TypeError.
**Example:**
```javascript
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) typeError
```
### Any
```javascript
is.any(value) -> true
as.any(value) -> value
```
**Description:**
Checks if the provided argument is any value.
- **is.any(arg):**
- Returns `true` if `arg` is any value.
- Returns `false` otherwise.
- **as.any(arg):**
- Returns `arg` if it is any value.
- Throws `TypeError` if `arg` is not any value.
**Example:**
```javascript
is.any('hello'); // Returns true
is.any(123); // Returns true
as.any('hello'); // Returns 'hello'
as.any(123); // Returns 123
```
## Enum type
### Enum type Basic
```js
Enum['name of stored enum']('enum object here')
```
### Enum type Basic usage
Use increment
```js
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 enum
```
Use decrement
```js
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
```js
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
```js
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
```js
as.Enum(enumExample) && as.enum(enumExample);
```
## Build-in validators
This list of validators works with a minimum set of methods.
### Empty
```javascript
is.empty(value) -> true | false
as.empty(value) -> value | TypeError: Value is not empty
```
**Description:**
Checks if the provided argument is empty.
- **is.empty(arg):**
- Returns `true` if `arg` is empty.
- Returns `false` otherwise.
- **as.empty(arg):**
- Returns `arg` if it is empty.
- Throws `TypeError` if `arg` is not empty.
**Example:**
```javascript
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 empty
```
### NotEmpty
```javascript
is.notEmpty(value) -> true | false
as.notEmpty(value) -> value | TypeError: Value is empty
```
**Description:**
Checks if the provided argument is not empty.
- **is.notEmpty(arg):**
- Returns `true` if `arg` is not empty.
- Returns `false` otherwise.
- **as.notEmpty(arg):**
- Returns `arg` if it is not empty.
- Throws `TypeError` if `arg` is empty.
**Example:**
```javascript
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 empty
```
### JSON
```javascript
is.json(value) -> true | false
as.json(value) -> value | TypeError: Value is not JSON
```
**Description:**
Checks if the provided argument is a valid JSON string.
- **is.json(arg):**
- Returns `true` if `arg` is a valid JSON string.
- Returns `false` otherwise.
- **
as.json(arg):**
- Returns `arg` if it is a valid JSON string.
- Throws `TypeError` if `arg` is not a valid JSON string.
**Example:**
```javascript
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 JSON
```
### JSON5
```javascript
is.json5(value) -> true | false
as.json5(value) -> value | TypeError: Value is not JSON5
```
**Description:**
Checks if the provided argument is a valid JSON5 string.
- **is.json5(arg):**
- Returns `true` if `arg` is a valid JSON5 string.
- Returns `false` otherwise.
- **as.json5(arg):**
- Returns `arg` if it is a valid JSON5 string.
- Throws `TypeError` if `arg` is not a valid JSON5 string.
**Example:**
```javascript
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 JSON5
```
### Null
```javascript
is.null(value) -> true | false
as.null(value) -> value | TypeError: Value is not null
```
**Description:**
Checks if the provided argument is null.
- **is.null(arg):**
- Returns `true` if `arg` is null.
- Returns `false` otherwise.
- **as.null(arg):**
- Returns `arg` if it is null.
- Throws `TypeError` if `arg` is not null.
**Example:**
```javascript
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 null
```
## Number Validators
Sure, I'll restructure the documentation as requested. Here is the first part of the updated documentation:
### Zero
```javascript
is.zero(value) -> true | false
as.zero(value) -> value | TypeError: Number is not a value that passed validation
```
**Description:**
Checks if the provided argument is exactly zero.
- **is.zero(arg):**
- Returns `true` if `arg` is `0`.
- Returns `false` otherwise.
- **as.zero(arg):**
- Returns `arg` if it is `0`.
- Throws `TypeError` if `arg` is not `0`.
**Example:**
```javascript
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 validation
```
### Even
```javascript
is.even(value) -> true | false
as.even(value) -> value | TypeError: Number is not a value that passed validation
```
**Description:**
Checks if the provided argument is an even number.
- **is.even(arg):**
- Returns `true` if `arg` is even.
- Returns `false` otherwise.
- **as.even(arg):**
- Returns `arg` if it is even.
- Throws `TypeError` if `arg` is not even.
**Example:**
```javascript
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 validation
```
### Odd
```javascript
is.odd(value) -> true | false
as.odd(value) -> value | TypeError: Number is not a value that passed validation
```
**Description:**
Checks if the provided argument is an odd number.
- **is.odd(arg):**
- Returns `true` if `arg` is odd.
- Returns `false` otherwise.
- **as.odd(arg):**
- Returns `arg` if it is odd.
- Throws `TypeError` if `arg` is not odd.
**Example:**
```javascript
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 validation
```
### Positive
```javascript
is.positive(value) -> true | false
as.positive(value) -> value | TypeError: Number is not a value that passed validation
```
**Description:**
Checks if the provided argument is a positive number.
- **is.positive(arg):**
- Returns `true` if `arg` is positive.
- Returns `false` otherwise.
- **as.positive(arg):**
- Returns `arg` if it is positive.
- Throws `TypeError` if `arg` is not positive.
**Example:**
```javascript
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 validation
```
### Negative
```javascript
is.negative(value) -> true | false
as.negative(value) -> value | TypeError: Number is not a value that passed validation
```
**Description:**
Checks if the provided argument is a negative number.
- **is.negative(arg):**
- Returns `true` if `arg` is negative.
- Returns `false` otherwise.
- **as.negative(arg):**
- Returns `arg` if it is negative.
- Throws `TypeError` if `arg` is not negative.
**Example:**
```javascript
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 validation
```
### Positive Integer
```javascript
is.positiveInteger(value) -> true | false
as.positiveInteger(value) -> value | TypeError: Number is not a value that passed validation
```
**Description:**
Checks if the provided argument is a positive integer.
- **is.positiveInteger(arg):**
- Returns `true` if `arg` is a positive integer.
- Returns `false` otherwise.
- **as.positiveInteger(arg):**
- Returns `arg` if it is a positive integer.
- Throws `TypeError` if `arg` is not a positive integer.
**Example:**
```javascript
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 validation
```
### Negative Integer
```javascript
is.negativeInteger(value) -> true | false
as.negativeInteger(value) -> value | TypeError: Number is not a value that passed validation
```
**Description:**
Checks if the provided argument is a negative integer.
- **is.negativeInteger(arg):**
- Returns `true` if `arg` is a negative integer.
- Returns `false` otherwise.
- **as.negativeInteger(arg):**
- Returns `arg` if it is a negative integer.
- Throws `TypeError` if `arg` is not a negative integer.
**Example:**
```javascript
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 validation
```
### Finite
```javascript
is.isFinite(value) -> true | false
as.isFinite(value) -> value | TypeError: Number is not a value that passed validation
```
**Description:**
Checks if the provided argument is a finite number.
- **is.isFinite(arg):**
- Returns `true` if `arg` is finite.
- Returns `false` otherwise.
- **as.isFinite(arg):**
- Returns `arg` if it is finite.
- Throws `TypeError` if `arg` is not finite.
**Example:**
```javascript
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 validation
```
### NaN
```javascript
is.NaN(value) -> true | false
as.NaN(value) -> value | TypeError: Number is not a value that passed validation
```
**Description:**
Checks if the provided argument is NaN (Not-a-Number).
- **is.NaN(arg):**
- Returns `true` if `arg` is NaN.
- Returns `false` otherwise.
- **as.NaN(arg):**
- Returns `arg` if it is NaN.
- Throws `TypeError` if `arg` is not NaN.
**Example:**
```javascript
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 validation
```
### Between
```javascript
is.between({ arg, min, max }) -> true | false
as.between({ arg, min, max }) -> value | TypeError: Number is not a value that passed validation
```
**Description:**
Checks if the provided argument is between `min` and `max` values.
- **is.between({ arg, min, max }):**
- Returns `true` if `arg` is between `min` and `max`.
- Returns `false` otherwise.
- **as.between({ arg, min, max }):**
- Returns `arg` if it is between `min` and `max`.
- Throws `TypeError` if `arg` is not between `min` and `max`.
**Example:**
```javascript
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 validation
```
### Greater
```javascript
is.greater({ arg, value }) -> true | false
as.greater({ arg, value }) -> value | TypeError: Number is not a value that passed validation
```
**Description:**
Checks if the provided argument is greater than the specified value.
- **is.greater({ arg, value }):**
- Returns `true` if `arg` is greater than `value`.
- Returns `
false` otherwise.
- **as.greater({ arg, value }):**
- Returns `arg` if it is greater than `value`.
- Throws `TypeError` if `arg` is not greater than `value`.
**Example:**
```javascript
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 validation
```
### Less
```javascript
is.less({ arg, value }) -> true | false
as.less({ arg, value }) -> value | TypeError: Number is not a value that passed validation
```
**Description:**
Checks if the provided argument is less than the specified value.
- **is.less({ arg, value }):**
- Returns `true` if `arg` is less than `value`.
- Returns `false` otherwise.
- **as.less({ arg, value }):**
- Returns `arg` if it is less than `value`.
- Throws `TypeError` if `arg` is not less than `value`.
**Example:**
```javascript
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 validation
```
### Equal or Greater
```javascript
is.equalGreater({ arg, value }) -> true | false
as.equalGreater({ arg, value }) -> value | TypeError: Number is not a value that passed validation
```
**Description:**
Checks if the provided argument is equal to or greater than the specified value.
- **is.equalGreater({ arg, value }):**
- Returns `true` if `arg` is equal to or greater than `value`.
- Returns `false` otherwise.
- **as.equalGreater({ arg, value }):**
- Returns `arg` if it is equal to or greater than `value`.
- Throws `TypeError` if `arg` is not equal to or greater than `value`.
**Example:**
```javascript
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 validation
```
### Equal or Less
```javascript
is.equalLess({ arg, value }) -> true | false
as.equalLess({ arg, value }) -> value | TypeError: Number is not a value that passed validation
```
**Description:**
Checks if the provided argument is equal to or less than the specified value.
- **is.equalLess({ arg, value }):**
- Returns `true` if `arg` is equal to or less than `value`.
- Returns `false` otherwise.
- **as.equalLess({ arg, value }):**
- Returns `arg` if it is equal to or less than `value`.
- Throws `TypeError` if `arg` is not equal to or less than `value`.
**Example:**
```javascript
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 validation
```
### Max
```javascript
is.max({ arg, value }) -> true | false
as.max({ arg, value }) -> value | TypeError: Number is not a value that passed validation
```
**