@heliomarpm/helpers
Version:
A library with many useful features
217 lines (216 loc) • 7.5 kB
TypeScript
export declare enum eOS {
Windows = "win32",
Linux = "linux",
MacOS = "darwin"
}
export declare enum eArchitecture {
x86 = "ia32",
x64 = "x64",
Arm = "arm",
Arm64 = "arm64"
}
export declare const Is: {
plataform: {
/**
* Verifies that it's running on the Windows OS.
*
* @returns boolean
*/
readonly windowsOS: boolean;
/**
* Verifies that it's running on the Linux OS.
*
* @returns boolean
*/
readonly linuxOS: boolean;
/**
* Verifies that it's running on the Mac OS.
*
* @returns boolean
*/
readonly macOS: boolean;
/**
* Check if the processor architecture is ia32.
*
* @returns boolean
*/
readonly arch_x86: boolean;
/**
* Check if the processor architecture is x64.
*
* @returns boolean
*/
readonly arch_x64: boolean;
/**
* Check if the processor architecture is arm.
*
* @returns boolean
*/
readonly arch_Arm: boolean;
/**
* Check if the processor architecture is arm64.
*
* @returns boolean
*/
readonly arch_Arm64: boolean;
};
/**
* Validates a given value as a CPF (Brazilian National Register of Individuals).
*
* @param value - The value to be validated as a CPF.
* @returns `true` if the input value is a valid CPF, `false` otherwise.
*/
cpf(value: string): 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.
*
* @param value - The value to be validated as a CNPJ.
* @returns `true` if the input value is a valid CNPJ, `false` otherwise.
*
* @example
*
* Utils.cnpj("12.ABC.345/01DE-35") // Output: true
*/
cnpj(value: string): 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.
* @param value The value to be verified.
* @returns {boolean} `true` if the value is a valid number, `false` otherwise.
*/
numeric<T>(value: T): boolean;
/**
* Verifies if two values are equal.
* @param a The first value to be compared.
* @param b The second value to be compared.
* @param ignoreOrder 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: false
*/
equals<T, U>(left: T, right: U, ignoreOrder?: boolean): boolean;
/**
* Verifies if the given value is a valid date.
* @param value The value to be verified.
* @returns {boolean} `true` if the value is a valid date, `false` otherwise.
*/
date(value: unknown): boolean;
/**
* Verifies if the given value is null, undefined, an empty string, or an empty object/array.
* @param value 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: true
*/
nullOrEmpty(value: unknown): boolean;
/**
* Verifies if the given value is a valid object.
* @param value 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: false
*/
object(value: unknown): boolean;
/**
* Verifies if the given value is a valid email address.
* @param value The value to be verified.
* @returns {boolean} `true` if the value is a valid email address, `false` otherwise.
*
* @example
* Is.email('heliomarpm@proton.me'); //output: true
*/
email(value: string): boolean;
/**
* Verifies if the given value is an odd number.
* @param value 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: false
*/
odd(value: number): boolean;
/**
* Verifies if the given value is an even number.
* @param value 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: false
*/
even(value: number): boolean;
/**
* Verifies if the given value is a valid UUID.
* @param value 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
*/
uuid(value: string): boolean;
/**
* Verifies if the given value is a promise.
* @param value 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: false
*/
promise(value: unknown): boolean;
/**
* Checks if the given value is a function.
* @param value 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: false
*/
function(value: unknown): boolean;
/**
* Checks if the given value is a valid URL.
* @param value 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: false
*/
url(value: string): boolean;
/**
* Checks if the given value is a valid JSON string.
* @param value 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: false
*/
json(value: string): boolean;
};