Class: Is
Is - A collection of type-checking and validation utilities.
Author
Heliomar P. Marques https://navto.me/heliomarpm*
Is.cnpj
cnpj()
static cnpj(value): boolean;Validates a given value as a CNPJ (Brazilian National Register of Legal Entities). Starting from July 1st, 2026, the CNPJ will transition to a new format with letters and numbers. This implementation will automatically detect the format and validate it accordingly.
Parameters
value
string
The value to be validated as a CNPJ.
Returns
boolean
true if the input value is a valid CNPJ, false otherwise.
Example
Utils.cnpj("12.ABC.345/01DE-35") // Output: trueIs.cpf
cpf()
static cpf(value): boolean;Validates a given value as a CPF (Brazilian National Register of Individuals).
Parameters
value
string
The value to be validated as a CPF.
Returns
boolean
true if the input value is a valid CPF, false otherwise.
Example
Is.cpf("12345678909") // Output: trueIs.date
date()
static date(value): boolean;Determines if the given value is a valid date. Converts string or number types to Date objects for validation.
Parameters
value
The value to be checked. Can be a Date object, a string, or a number.
string | number
Returns
boolean
true if the value is a valid date, false otherwise.
Example
Is.date('2022-01-01'); //output: true
Is.date(new Date()); //output: true
Is.date('invalid date'); //output: false
Is.date(1633046400000); //output: trueIs.dateBetween
dateBetween()
static dateBetween(
date,
start,
end): boolean;Checks if a date is between two other dates.
Parameters
date
Date
The date to be checked.
start
Date
The start date of the range.
end
Date
The end date of the range.
Returns
boolean
true if the date is between the start and end dates, false otherwise.
Example
Is.dateBetween(new Date('2022-01-15'), new Date('2022-01-01'), new Date('2022-01-31')); //output: true
Is.dateBetween(new Date('2022-02-01'), new Date('2022-01-01'), new Date('2022-01-31')); //output: falseIs.email
email()
static email(value): boolean;Verifies if the given value is a valid email address.
Parameters
value
string
The email to be verified.
Returns
boolean
true if the value is a valid email address, false otherwise.
Example
Is.email('foo.bar@email.com'); //output: true
Is.email('invalid-email'); //output: falseIs.equals
equals()
static equals<T, U>(
left,
right,
ignoreOrder): boolean;Verifies if two values are equal.
Type Parameters
T
T
U
U
Parameters
left
T
The first value to be compared.
right
U
The second value to be compared.
ignoreOrder
boolean = false
If true, ignores the order of elements in arrays and objects.
Returns
boolean
true if the values are equal, false otherwise.
Example
Is.equals({ a: 1, b: 2 }, { b: 2, a: 1 }); //output: true
Is.equals([1, 2, 3], [3, 2, 1], true); //output: true
Is.equals({ a: 1, b: 2 }, { a: 1, b: 3 }); //output: false
Is.equals([1, 2, 3], [1, 2, 3]); //output: true
Is.equals('hello', 'hello'); //output: true
Is.equals(new Set[1], new Set[2]); //output: falseIs.even
even()
static even(value): boolean;Verifies if the given value is an even number.
Parameters
value
number
The value to be verified.
Returns
boolean
true if the value is an even number, false otherwise.
Example
Is.even(2); //output: true
Is.even(3); //output: falseIs.function
function()
static function(value): boolean;Checks if the given value is a function.
Parameters
value
unknown
The value to be checked.
Returns
boolean
true if the value is a function, false otherwise.
Example
Is.function(function() {}); //output: true
Is.function(() => {}); //output: true
Is.function('not a function'); //output: falseIs.json
json()
static json(value): boolean;Checks if the given value is a valid JSON string.
Parameters
value
string
The value to be checked.
Returns
boolean
true if the value is a valid JSON string, false otherwise.
Example
Is.json('{"key": "value"}'); //output: true
Is.json('Invalid JSON'); //output: falseIs.leapYear
leapYear()
static leapYear: (year?) => boolean;Checks if a given year is a leap year.
A year is a leap year if it is divisible by 4, except for end-of-century years which must be divisible by 400. This means that the year 2000 was a leap year, although 1900 was not.
Parameters
year?
number = ...
The year to check.
Returns
boolean
True if the year is a leap year, false otherwise.
Example
const isLeapYear = Is.leapYear(2000);
console.log(isLeapYear); // trueIs.nullOrEmpty
nullOrEmpty()
static nullOrEmpty(value): boolean;Verifies if the given value is null, undefined, an empty string, or an empty object/array.
Parameters
value
unknown
The value to be verified.
Returns
boolean
true if the value is null, undefined, an empty string, or an empty object/array, false otherwise.
Example
Is.nullOrEmpty(''); //output: true
Is.nullOrEmpty(null); //output: true
Is.nullOrEmpty(undefined); //output: true
Is.nullOrEmpty([]); //output: true
Is.nullOrEmpty({}); //output: trueIs.numeric
numeric()
static numeric<T>(value): boolean;Verifies if the given value is a valid number. A valid number is either a number primitive or a string that can be parsed to a number.
Type Parameters
T
T
Parameters
value
T
The value to be verified.
Returns
boolean
true if the value is a valid number, false otherwise.
Example
Is.numeric('123'); //output: true
Is.numeric('123.45'); //output: true
Is.numeric('abc'); //output: false
Is.numeric(NaN); //output: false
Is.numeric(3); //output: trueIs.object
object()
static object(value): boolean;Verifies if the given value is a valid object.
Parameters
value
unknown
The value to be verified.
Returns
boolean
true if the value is a valid object, false otherwise.
Example
Is.object({ a: 1 }); //output: true
Is.object({}); //output: true
Is.object([]); //output: false
Is.object([{a:1}]); //output: false
Is.object(null); //output: false
Is.object(undefined); //output: falseIs.odd
odd()
static odd(value): boolean;Verifies if the given value is an odd number.
Parameters
value
number
The value to be verified.
Returns
boolean
true if the value is an odd number, false otherwise.
Example
Is.odd(3); //output: true
Is.odd(2); //output: falseIs.plataform
plataform
plataform
static plataform: object;Namespace
Plarform - A collection of utilities to check the operating system and processor architecture.
arch_Arm
Get Signature
get arch_Arm(): boolean;Check if the processor architecture is arm.
Returns
boolean
boolean
arch_Arm64
Get Signature
get arch_Arm64(): boolean;Check if the processor architecture is arm64.
Returns
boolean
boolean
arch_x64
Get Signature
get arch_x64(): boolean;Check if the processor architecture is x64.
Returns
boolean
boolean
arch_x86
Get Signature
get arch_x86(): boolean;Check if the processor architecture is ia32.
Returns
boolean
boolean
linuxOS
Get Signature
get linuxOS(): boolean;Verifies that it's running on the Linux OS.
Returns
boolean
boolean
macOS
Get Signature
get macOS(): boolean;Verifies that it's running on the Mac OS.
Returns
boolean
boolean
windowsOS
Get Signature
get windowsOS(): boolean;Verifies that it's running on the Windows OS.
Returns
boolean
boolean
Example
import { Is } from '@heliomarpm/helpers';
console.log(Is.plataform.windowsOS); // Output: true or false
console.log(Is.plataform.linuxOS); // Output: true or false
console.log(Is.plataform.macOS); // Output: true or false
console.log(Is.plataform.arch_x86); // Output: true or false
console.log(Is.plataform.arch_x64); // Output: true or false
console.log(Is.plataform.arch_Arm); // Output: true or false
console.log(Is.plataform.arch_Arm64); // Output: true or falseIs.promise
promise()
static promise(value): boolean;Verifies if the given value is a promise.
Parameters
value
unknown
The value to be verified.
Returns
boolean
true if the value is a promise, false otherwise.
Example
Is.promise(Promise.resolve()); //output: true
Is.promise(new Promise(() => {})); //output: true
Is.promise('not a promise'); //output: falseIs.url
url()
static url(value): boolean;Checks if the given value is a valid URL.
Parameters
value
string
The value to be checked.
Returns
boolean
true if the value is a valid URL, false otherwise.
Example
Is.url('https://www.example.com'); //output: true
Is.url('invalid-url'); //output: falseIs.uuid
uuid()
static uuid(value): boolean;Verifies if the given value is a valid UUID.
Parameters
value
string
The value to be verified.
Returns
boolean
true if the value is a valid UUID, false otherwise.
Example
Is.uuid('12345678-1234-1234-1234-123456789012'); //output: true
Is.uuid('12345678-1234-1234-1234-1234567890123'); //output: false