Skip to content

Class: Is ​

Is - A collection of type-checking and validation utilities.

Author ​

Heliomar P. Marques https://navto.me/heliomarpm*

Is.cnpj ​

cnpj() ​

ts
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 ​

ts
Utils.cnpj("12.ABC.345/01DE-35") // Output: true

Is.cpf ​

cpf() ​

ts
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 ​

ts
Is.cpf("12345678909") // Output: true

Is.date ​

date() ​

ts
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 ​

ts
Is.date('2022-01-01'); //output: true
Is.date(new Date()); //output: true
Is.date('invalid date'); //output: false
Is.date(1633046400000); //output: true

Is.dateBetween ​

dateBetween() ​

ts
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 ​

ts
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: false

Is.email ​

email() ​

ts
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 ​

ts
Is.email('foo.bar@email.com'); //output: true
Is.email('invalid-email'); //output: false

Is.equals ​

equals() ​

ts
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.

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 ​

ts
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: false

Is.even ​

even() ​

ts
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 ​

ts
Is.even(2); //output: true
Is.even(3); //output: false

Is.function ​

function() ​

ts
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 ​

ts
Is.function(function() {}); //output: true
Is.function(() => {}); //output: true
Is.function('not a function'); //output: false

Is.json ​

json() ​

ts
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 ​

ts
Is.json('{"key": "value"}'); //output: true
Is.json('Invalid JSON'); //output: false

Is.leapYear ​

leapYear() ​

ts
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 ​

ts
const isLeapYear = Is.leapYear(2000);
console.log(isLeapYear); // true

Is.nullOrEmpty ​

nullOrEmpty() ​

ts
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 ​

ts
Is.nullOrEmpty(''); //output: true
Is.nullOrEmpty(null); //output: true
Is.nullOrEmpty(undefined); //output: true
Is.nullOrEmpty([]); //output: true
Is.nullOrEmpty({}); //output: true

Is.numeric ​

numeric() ​

ts
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 ​

ts
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: true

Is.object ​

object() ​

ts
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 ​

ts
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: false

Is.odd ​

odd() ​

ts
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 ​

ts
Is.odd(3); //output: true
Is.odd(2); //output: false

Is.plataform ​

plataform

plataform ​

ts
static plataform: object;

Namespace

Plarform - A collection of utilities to check the operating system and processor architecture.

arch_Arm ​

Get Signature ​
ts
get arch_Arm(): boolean;

Check if the processor architecture is arm.

Returns ​

boolean

boolean

arch_Arm64 ​

Get Signature ​
ts
get arch_Arm64(): boolean;

Check if the processor architecture is arm64.

Returns ​

boolean

boolean

arch_x64 ​

Get Signature ​
ts
get arch_x64(): boolean;

Check if the processor architecture is x64.

Returns ​

boolean

boolean

arch_x86 ​

Get Signature ​
ts
get arch_x86(): boolean;

Check if the processor architecture is ia32.

Returns ​

boolean

boolean

linuxOS ​

Get Signature ​
ts
get linuxOS(): boolean;

Verifies that it's running on the Linux OS.

Returns ​

boolean

boolean

macOS ​

Get Signature ​
ts
get macOS(): boolean;

Verifies that it's running on the Mac OS.

Returns ​

boolean

boolean

windowsOS ​

Get Signature ​
ts
get windowsOS(): boolean;

Verifies that it's running on the Windows OS.

Returns ​

boolean

boolean

Example ​

ts
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 false

Is.promise ​

promise() ​

ts
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 ​

ts
Is.promise(Promise.resolve()); //output: true
Is.promise(new Promise(() => {})); //output: true
Is.promise('not a promise'); //output: false

Is.url ​

url() ​

ts
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 ​

ts
Is.url('https://www.example.com'); //output: true
Is.url('invalid-url'); //output: false

Is.uuid ​

uuid() ​

ts
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 ​

ts
Is.uuid('12345678-1234-1234-1234-123456789012'); //output: true
Is.uuid('12345678-1234-1234-1234-1234567890123'); //output: false