@rainbowatcher/js-utils
Advanced tools
+179
| /** | ||
| * Checks if the given value is undefined. | ||
| * | ||
| * @param value - The value to be checked | ||
| * @return Returns true if the value is undefined, false otherwise | ||
| */ | ||
| declare function isUndefined(value: unknown): value is undefined; | ||
| /** | ||
| * Checks if the given value is null. | ||
| * | ||
| * @param value - The value to be checked | ||
| * @returns Returns true if the value is null, false otherwise | ||
| */ | ||
| declare function isNull(value: unknown): value is null; | ||
| /** | ||
| * Checks if the given value is a boolean. | ||
| * | ||
| * @param value - The value to be checked. | ||
| * @return Whether the value is a boolean or not. | ||
| */ | ||
| declare function isBoolean(value: unknown): value is boolean; | ||
| /** | ||
| * Checks if the value is a number. | ||
| * | ||
| * @param value - the value to be checked | ||
| * @return true if the value is a number, false otherwise | ||
| */ | ||
| declare function isNumber(value: unknown): value is number; | ||
| /** | ||
| * Checks if the given value is a function. | ||
| * | ||
| * @param value - the value to be checked | ||
| * @returns Returns true if the value is a function, false otherwise | ||
| */ | ||
| declare function isFunction(value: unknown): value is Function; | ||
| /** | ||
| * Checks if the given value is an object. | ||
| * | ||
| * 1. The value must be not null | ||
| * 2. The value's type must be "object" or "function" | ||
| * | ||
| * @param value - the value to be checked | ||
| * @return true if the value is an object, false otherwise | ||
| */ | ||
| declare function isObject(value: unknown): value is object; | ||
| /** | ||
| * Checks if the given value is an array and optionally matches the provided assertion. | ||
| * | ||
| * @param value - The value to check | ||
| * @param [assertion] - Optional assertion function | ||
| * @return Whether the value is an array that matches the assertion | ||
| */ | ||
| declare function isArray<T = unknown>(value: unknown, assertion?: (value: T) => value is T): value is T[]; | ||
| /** | ||
| * Checks if the given value is a string. | ||
| * | ||
| * just check if the type of value is string | ||
| * | ||
| * @param value - The value to be checked. | ||
| * @return Returns true if the value is a string, false otherwise. | ||
| */ | ||
| declare function isString(value: unknown): value is string; | ||
| /** | ||
| * Checks if the input value is a Date. | ||
| * | ||
| * @param value - the input value to be checked | ||
| * @return true if the input is a Date, false otherwise | ||
| */ | ||
| declare function isDate(value: any): value is Date; | ||
| /** | ||
| * Checks if the given function is an asynchronous function. | ||
| * | ||
| * @param fn - The function to check | ||
| * @return Whether the function is asynchronous or not | ||
| */ | ||
| declare function isAsyncFunction<T = unknown>(value: unknown): value is ((...args: any[]) => Promise<T>); | ||
| /** | ||
| * Checks if the given value is a plain object. | ||
| * | ||
| * 1. The value must be an object and is not null | ||
| * 2. The value must not have any prototype or it's prototype equals to Object.prototype or it's grandparent prototype is null | ||
| * 3. The value must not have the Symbol.toStringTag or Symbol.iterator properties | ||
| * | ||
| * @param value - The value to be checked. | ||
| * @return Whether the value is a plain object. | ||
| */ | ||
| declare function isPlainObject<Value = unknown>(value: unknown): value is Record<PropertyKey, Value>; | ||
| /** | ||
| * Type guard function to check if the input is a Map object. | ||
| * | ||
| * @param value - the object to be checked | ||
| * @return true if the input is a Map object, false otherwise | ||
| */ | ||
| declare function isMap<Key = unknown, Value = unknown>(value: unknown): value is Map<Key, Value>; | ||
| /** | ||
| * Checks if the given value is a Set. | ||
| * | ||
| * @param value - the value to be checked | ||
| * @return true if the value is a Set, false otherwise | ||
| */ | ||
| declare function isSet<T = unknown>(value: unknown): value is Set<T>; | ||
| /** | ||
| * Checks if the given value is an HTML element. | ||
| * | ||
| * 1. The value must be an object | ||
| * 2. The value must have the following properties: nodeName, nodeType | ||
| * 3. The value must not have any other properties | ||
| * | ||
| * @param value - The value to be checked. | ||
| * @return Whether the value is an HTML element. | ||
| */ | ||
| declare function isHtmlElement(value: unknown): value is HTMLElement; | ||
| declare const is: { | ||
| number: typeof isNumber; | ||
| string: typeof isString; | ||
| boolean: typeof isBoolean; | ||
| null: typeof isNull; | ||
| undefined: typeof isUndefined; | ||
| object: typeof isObject; | ||
| array: typeof isArray; | ||
| map: typeof isMap; | ||
| set: typeof isSet; | ||
| date: typeof isDate; | ||
| function: typeof isFunction; | ||
| asyncFunction: typeof isAsyncFunction; | ||
| plainObject: typeof isPlainObject; | ||
| htmlElement: typeof isHtmlElement; | ||
| }; | ||
| declare const index_is: typeof is; | ||
| declare const index_isArray: typeof isArray; | ||
| declare const index_isAsyncFunction: typeof isAsyncFunction; | ||
| declare const index_isBoolean: typeof isBoolean; | ||
| declare const index_isDate: typeof isDate; | ||
| declare const index_isFunction: typeof isFunction; | ||
| declare const index_isHtmlElement: typeof isHtmlElement; | ||
| declare const index_isMap: typeof isMap; | ||
| declare const index_isNull: typeof isNull; | ||
| declare const index_isNumber: typeof isNumber; | ||
| declare const index_isObject: typeof isObject; | ||
| declare const index_isPlainObject: typeof isPlainObject; | ||
| declare const index_isSet: typeof isSet; | ||
| declare const index_isString: typeof isString; | ||
| declare const index_isUndefined: typeof isUndefined; | ||
| declare namespace index { | ||
| export { index_is as is, index_isArray as isArray, index_isAsyncFunction as isAsyncFunction, index_isBoolean as isBoolean, index_isDate as isDate, index_isFunction as isFunction, index_isHtmlElement as isHtmlElement, index_isMap as isMap, index_isNull as isNull, index_isNumber as isNumber, index_isObject as isObject, index_isPlainObject as isPlainObject, index_isSet as isSet, index_isString as isString, index_isUndefined as isUndefined }; | ||
| } | ||
| declare function isEmpty$1<T>(arrayLike: ArrayLike<T> | undefined): boolean; | ||
| declare function isNotEmpty$1<T>(arrayLike: ArrayLike<T> | undefined): boolean; | ||
| declare namespace lists { | ||
| export { isEmpty$1 as isEmpty, isNotEmpty$1 as isNotEmpty }; | ||
| } | ||
| /** | ||
| * checks if a string is empty or not | ||
| * @param str input string | ||
| * @param trim trim white space in string | ||
| * @returns true for empty false for not | ||
| */ | ||
| declare function isEmpty(str: string | undefined, trim?: boolean): boolean; | ||
| declare function isNotEmpty(str: string | undefined, trim?: boolean): boolean; | ||
| /** | ||
| * Takes a parameter str that can either be a string or undefined type and returns the parameter str in upper case letters | ||
| */ | ||
| declare function toUpperCase(str: string | undefined): string | undefined; | ||
| declare const str_isEmpty: typeof isEmpty; | ||
| declare const str_isNotEmpty: typeof isNotEmpty; | ||
| declare const str_toUpperCase: typeof toUpperCase; | ||
| declare namespace str { | ||
| export { str_isEmpty as isEmpty, str_isNotEmpty as isNotEmpty, str_toUpperCase as toUpperCase }; | ||
| } | ||
| export { lists as Lists, str as Strings, index as is }; |
+179
| /** | ||
| * Checks if the given value is undefined. | ||
| * | ||
| * @param value - The value to be checked | ||
| * @return Returns true if the value is undefined, false otherwise | ||
| */ | ||
| declare function isUndefined(value: unknown): value is undefined; | ||
| /** | ||
| * Checks if the given value is null. | ||
| * | ||
| * @param value - The value to be checked | ||
| * @returns Returns true if the value is null, false otherwise | ||
| */ | ||
| declare function isNull(value: unknown): value is null; | ||
| /** | ||
| * Checks if the given value is a boolean. | ||
| * | ||
| * @param value - The value to be checked. | ||
| * @return Whether the value is a boolean or not. | ||
| */ | ||
| declare function isBoolean(value: unknown): value is boolean; | ||
| /** | ||
| * Checks if the value is a number. | ||
| * | ||
| * @param value - the value to be checked | ||
| * @return true if the value is a number, false otherwise | ||
| */ | ||
| declare function isNumber(value: unknown): value is number; | ||
| /** | ||
| * Checks if the given value is a function. | ||
| * | ||
| * @param value - the value to be checked | ||
| * @returns Returns true if the value is a function, false otherwise | ||
| */ | ||
| declare function isFunction(value: unknown): value is Function; | ||
| /** | ||
| * Checks if the given value is an object. | ||
| * | ||
| * 1. The value must be not null | ||
| * 2. The value's type must be "object" or "function" | ||
| * | ||
| * @param value - the value to be checked | ||
| * @return true if the value is an object, false otherwise | ||
| */ | ||
| declare function isObject(value: unknown): value is object; | ||
| /** | ||
| * Checks if the given value is an array and optionally matches the provided assertion. | ||
| * | ||
| * @param value - The value to check | ||
| * @param [assertion] - Optional assertion function | ||
| * @return Whether the value is an array that matches the assertion | ||
| */ | ||
| declare function isArray<T = unknown>(value: unknown, assertion?: (value: T) => value is T): value is T[]; | ||
| /** | ||
| * Checks if the given value is a string. | ||
| * | ||
| * just check if the type of value is string | ||
| * | ||
| * @param value - The value to be checked. | ||
| * @return Returns true if the value is a string, false otherwise. | ||
| */ | ||
| declare function isString(value: unknown): value is string; | ||
| /** | ||
| * Checks if the input value is a Date. | ||
| * | ||
| * @param value - the input value to be checked | ||
| * @return true if the input is a Date, false otherwise | ||
| */ | ||
| declare function isDate(value: any): value is Date; | ||
| /** | ||
| * Checks if the given function is an asynchronous function. | ||
| * | ||
| * @param fn - The function to check | ||
| * @return Whether the function is asynchronous or not | ||
| */ | ||
| declare function isAsyncFunction<T = unknown>(value: unknown): value is ((...args: any[]) => Promise<T>); | ||
| /** | ||
| * Checks if the given value is a plain object. | ||
| * | ||
| * 1. The value must be an object and is not null | ||
| * 2. The value must not have any prototype or it's prototype equals to Object.prototype or it's grandparent prototype is null | ||
| * 3. The value must not have the Symbol.toStringTag or Symbol.iterator properties | ||
| * | ||
| * @param value - The value to be checked. | ||
| * @return Whether the value is a plain object. | ||
| */ | ||
| declare function isPlainObject<Value = unknown>(value: unknown): value is Record<PropertyKey, Value>; | ||
| /** | ||
| * Type guard function to check if the input is a Map object. | ||
| * | ||
| * @param value - the object to be checked | ||
| * @return true if the input is a Map object, false otherwise | ||
| */ | ||
| declare function isMap<Key = unknown, Value = unknown>(value: unknown): value is Map<Key, Value>; | ||
| /** | ||
| * Checks if the given value is a Set. | ||
| * | ||
| * @param value - the value to be checked | ||
| * @return true if the value is a Set, false otherwise | ||
| */ | ||
| declare function isSet<T = unknown>(value: unknown): value is Set<T>; | ||
| /** | ||
| * Checks if the given value is an HTML element. | ||
| * | ||
| * 1. The value must be an object | ||
| * 2. The value must have the following properties: nodeName, nodeType | ||
| * 3. The value must not have any other properties | ||
| * | ||
| * @param value - The value to be checked. | ||
| * @return Whether the value is an HTML element. | ||
| */ | ||
| declare function isHtmlElement(value: unknown): value is HTMLElement; | ||
| declare const is: { | ||
| number: typeof isNumber; | ||
| string: typeof isString; | ||
| boolean: typeof isBoolean; | ||
| null: typeof isNull; | ||
| undefined: typeof isUndefined; | ||
| object: typeof isObject; | ||
| array: typeof isArray; | ||
| map: typeof isMap; | ||
| set: typeof isSet; | ||
| date: typeof isDate; | ||
| function: typeof isFunction; | ||
| asyncFunction: typeof isAsyncFunction; | ||
| plainObject: typeof isPlainObject; | ||
| htmlElement: typeof isHtmlElement; | ||
| }; | ||
| declare const index_is: typeof is; | ||
| declare const index_isArray: typeof isArray; | ||
| declare const index_isAsyncFunction: typeof isAsyncFunction; | ||
| declare const index_isBoolean: typeof isBoolean; | ||
| declare const index_isDate: typeof isDate; | ||
| declare const index_isFunction: typeof isFunction; | ||
| declare const index_isHtmlElement: typeof isHtmlElement; | ||
| declare const index_isMap: typeof isMap; | ||
| declare const index_isNull: typeof isNull; | ||
| declare const index_isNumber: typeof isNumber; | ||
| declare const index_isObject: typeof isObject; | ||
| declare const index_isPlainObject: typeof isPlainObject; | ||
| declare const index_isSet: typeof isSet; | ||
| declare const index_isString: typeof isString; | ||
| declare const index_isUndefined: typeof isUndefined; | ||
| declare namespace index { | ||
| export { index_is as is, index_isArray as isArray, index_isAsyncFunction as isAsyncFunction, index_isBoolean as isBoolean, index_isDate as isDate, index_isFunction as isFunction, index_isHtmlElement as isHtmlElement, index_isMap as isMap, index_isNull as isNull, index_isNumber as isNumber, index_isObject as isObject, index_isPlainObject as isPlainObject, index_isSet as isSet, index_isString as isString, index_isUndefined as isUndefined }; | ||
| } | ||
| declare function isEmpty$1<T>(arrayLike: ArrayLike<T> | undefined): boolean; | ||
| declare function isNotEmpty$1<T>(arrayLike: ArrayLike<T> | undefined): boolean; | ||
| declare namespace lists { | ||
| export { isEmpty$1 as isEmpty, isNotEmpty$1 as isNotEmpty }; | ||
| } | ||
| /** | ||
| * checks if a string is empty or not | ||
| * @param str input string | ||
| * @param trim trim white space in string | ||
| * @returns true for empty false for not | ||
| */ | ||
| declare function isEmpty(str: string | undefined, trim?: boolean): boolean; | ||
| declare function isNotEmpty(str: string | undefined, trim?: boolean): boolean; | ||
| /** | ||
| * Takes a parameter str that can either be a string or undefined type and returns the parameter str in upper case letters | ||
| */ | ||
| declare function toUpperCase(str: string | undefined): string | undefined; | ||
| declare const str_isEmpty: typeof isEmpty; | ||
| declare const str_isNotEmpty: typeof isNotEmpty; | ||
| declare const str_toUpperCase: typeof toUpperCase; | ||
| declare namespace str { | ||
| export { str_isEmpty as isEmpty, str_isNotEmpty as isNotEmpty, str_toUpperCase as toUpperCase }; | ||
| } | ||
| export { lists as Lists, str as Strings, index as is }; |
+161
-48
| 'use strict'; | ||
| function isEmpty$1(arrayLike) { | ||
| return arrayLike ? arrayLike.length === 0 : true; | ||
| const typedArrayTypeNames = [ | ||
| "Int8Array", | ||
| "Uint8Array", | ||
| "Uint8ClampedArray", | ||
| "Int16Array", | ||
| "Uint16Array", | ||
| "Int32Array", | ||
| "Uint32Array", | ||
| "Float32Array", | ||
| "Float64Array", | ||
| "BigInt64Array", | ||
| "BigUint64Array" | ||
| ]; | ||
| const objectTypeNames = [ | ||
| "Function", | ||
| "Generator", | ||
| "AsyncGenerator", | ||
| "GeneratorFunction", | ||
| "AsyncGeneratorFunction", | ||
| "AsyncFunction", | ||
| "Observable", | ||
| "Array", | ||
| "Buffer", | ||
| "Blob", | ||
| "Object", | ||
| "RegExp", | ||
| "Date", | ||
| "Error", | ||
| "Map", | ||
| "Set", | ||
| "WeakMap", | ||
| "WeakSet", | ||
| "WeakRef", | ||
| "ArrayBuffer", | ||
| "SharedArrayBuffer", | ||
| "DataView", | ||
| "Promise", | ||
| "URL", | ||
| "FormData", | ||
| "URLSearchParams", | ||
| "HTMLElement", | ||
| "NaN", | ||
| ...typedArrayTypeNames | ||
| ]; | ||
| const DOM_PROPERTIES_TO_CHECK = [ | ||
| "innerHTML", | ||
| "ownerDocument", | ||
| "style", | ||
| "attributes", | ||
| "nodeValue" | ||
| ]; | ||
| function getObjectType(value) { | ||
| const objectTypeName = Object.prototype.toString.call(value).slice(8, -1); | ||
| if (/HTML\w+Element/.test(objectTypeName) && isHtmlElement(value)) { | ||
| return "HTMLElement"; | ||
| } | ||
| if (objectTypeNames.includes(objectTypeName)) { | ||
| return objectTypeName; | ||
| } | ||
| return void 0; | ||
| } | ||
| function isNotEmpty$1(arrayLike) { | ||
| return !isEmpty$1(arrayLike); | ||
| } | ||
| const lists = { | ||
| __proto__: null, | ||
| isEmpty: isEmpty$1, | ||
| isNotEmpty: isNotEmpty$1 | ||
| }; | ||
| function isUndefined(obj) { | ||
| return typeof obj === "undefined"; | ||
| function isUndefined(value) { | ||
| return typeof value === "undefined"; | ||
| } | ||
| function isAsyncFunction(fn) { | ||
| if (!fn) | ||
| function isNull(value) { | ||
| return value === null; | ||
| } | ||
| function isBoolean(value) { | ||
| return typeof value === "boolean"; | ||
| } | ||
| function isNumber(value) { | ||
| return typeof value === "number"; | ||
| } | ||
| function isFunction(value) { | ||
| return typeof value === "function"; | ||
| } | ||
| function isObject(value) { | ||
| return !isNull(value) && typeof value === "object" || isFunction(value); | ||
| } | ||
| function isArray(value, assertion) { | ||
| if (!Array.isArray(value)) { | ||
| return false; | ||
| return Object.getPrototypeOf(fn)[Symbol.toStringTag] === "AsyncFunction"; | ||
| } | ||
| function isDeepEquals(first, second, keys) { | ||
| if (!first || !second) { | ||
| return first === second; | ||
| } | ||
| if (typeof first !== "object" || typeof second !== "object") { | ||
| return first === second; | ||
| if (!isFunction(assertion)) { | ||
| return true; | ||
| } | ||
| if (Array.isArray(first) && Array.isArray(second)) { | ||
| if (first.length !== second.length) { | ||
| return false; | ||
| } else { | ||
| return first.every((item, index) => isDeepEquals(item, second[index])); | ||
| } | ||
| } | ||
| const keys1 = keys ?? Object.keys(first); | ||
| const keys2 = keys ?? Object.keys(second); | ||
| if (keys1.length !== keys2.length) { | ||
| return value.every((element) => assertion(element)); | ||
| } | ||
| function isString(value) { | ||
| return typeof value === "string"; | ||
| } | ||
| function isDate(value) { | ||
| return getObjectType(value) === "Date"; | ||
| } | ||
| function isAsyncFunction(value) { | ||
| return getObjectType(value) === "AsyncFunction"; | ||
| } | ||
| function isPlainObject(value) { | ||
| if (!isObject(value) || isNull(value)) { | ||
| return false; | ||
| } | ||
| for (const key of keys1) { | ||
| if (!keys2.includes(key) || !isDeepEquals(first[key], second[key])) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| const prototype = Object.getPrototypeOf(value); | ||
| return (isNull(prototype) || prototype === Object.prototype || isNull(Object.getPrototypeOf(prototype))) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value); | ||
| } | ||
| function isString(obj) { | ||
| return typeof obj === "string"; | ||
| function isMap(value) { | ||
| return getObjectType(value) === "Map"; | ||
| } | ||
| function isSet(value) { | ||
| return getObjectType(value) === "Set"; | ||
| } | ||
| function isHtmlElement(value) { | ||
| return isObject(value) && value.nodeType === Node.ELEMENT_NODE && isString(value.nodeName) && !isPlainObject(value) && DOM_PROPERTIES_TO_CHECK.every((property) => property in value); | ||
| } | ||
| const is = { | ||
| number: isNumber, | ||
| string: isString, | ||
| boolean: isBoolean, | ||
| null: isNull, | ||
| undefined: isUndefined, | ||
| object: isObject, | ||
| array: isArray, | ||
| map: isMap, | ||
| set: isSet, | ||
| date: isDate, | ||
| function: isFunction, | ||
| asyncFunction: isAsyncFunction, | ||
| plainObject: isPlainObject, | ||
| htmlElement: isHtmlElement | ||
| }; | ||
| const index = { | ||
| __proto__: null, | ||
| is: is, | ||
| isArray: isArray, | ||
| isAsyncFunction: isAsyncFunction, | ||
| isBoolean: isBoolean, | ||
| isDate: isDate, | ||
| isFunction: isFunction, | ||
| isHtmlElement: isHtmlElement, | ||
| isMap: isMap, | ||
| isNull: isNull, | ||
| isNumber: isNumber, | ||
| isObject: isObject, | ||
| isPlainObject: isPlainObject, | ||
| isSet: isSet, | ||
| isString: isString, | ||
| isUndefined: isUndefined | ||
| }; | ||
| function isEmpty$1(arrayLike) { | ||
| return arrayLike ? arrayLike.length === 0 : true; | ||
| } | ||
| function isNotEmpty$1(arrayLike) { | ||
| return !isEmpty$1(arrayLike); | ||
| } | ||
| const lists = { | ||
| __proto__: null, | ||
| isEmpty: isEmpty$1, | ||
| isNotEmpty: isNotEmpty$1 | ||
| }; | ||
| function isEmpty(str, trim = false) { | ||
@@ -73,7 +189,6 @@ if (isUndefined(str)) | ||
| const str = { | ||
| __proto__: null, | ||
| isEmpty: isEmpty, | ||
| isNotEmpty: isNotEmpty, | ||
| isString: isString, | ||
| toUpperCase: toUpperCase | ||
| __proto__: null, | ||
| isEmpty: isEmpty, | ||
| isNotEmpty: isNotEmpty, | ||
| toUpperCase: toUpperCase | ||
| }; | ||
@@ -83,4 +198,2 @@ | ||
| exports.Strings = str; | ||
| exports.isAsyncFunction = isAsyncFunction; | ||
| exports.isDeepEquals = isDeepEquals; | ||
| exports.isUndefined = isUndefined; | ||
| exports.is = index; |
+154
-17
@@ -0,1 +1,152 @@ | ||
| /** | ||
| * Checks if the given value is undefined. | ||
| * | ||
| * @param value - The value to be checked | ||
| * @return Returns true if the value is undefined, false otherwise | ||
| */ | ||
| declare function isUndefined(value: unknown): value is undefined; | ||
| /** | ||
| * Checks if the given value is null. | ||
| * | ||
| * @param value - The value to be checked | ||
| * @returns Returns true if the value is null, false otherwise | ||
| */ | ||
| declare function isNull(value: unknown): value is null; | ||
| /** | ||
| * Checks if the given value is a boolean. | ||
| * | ||
| * @param value - The value to be checked. | ||
| * @return Whether the value is a boolean or not. | ||
| */ | ||
| declare function isBoolean(value: unknown): value is boolean; | ||
| /** | ||
| * Checks if the value is a number. | ||
| * | ||
| * @param value - the value to be checked | ||
| * @return true if the value is a number, false otherwise | ||
| */ | ||
| declare function isNumber(value: unknown): value is number; | ||
| /** | ||
| * Checks if the given value is a function. | ||
| * | ||
| * @param value - the value to be checked | ||
| * @returns Returns true if the value is a function, false otherwise | ||
| */ | ||
| declare function isFunction(value: unknown): value is Function; | ||
| /** | ||
| * Checks if the given value is an object. | ||
| * | ||
| * 1. The value must be not null | ||
| * 2. The value's type must be "object" or "function" | ||
| * | ||
| * @param value - the value to be checked | ||
| * @return true if the value is an object, false otherwise | ||
| */ | ||
| declare function isObject(value: unknown): value is object; | ||
| /** | ||
| * Checks if the given value is an array and optionally matches the provided assertion. | ||
| * | ||
| * @param value - The value to check | ||
| * @param [assertion] - Optional assertion function | ||
| * @return Whether the value is an array that matches the assertion | ||
| */ | ||
| declare function isArray<T = unknown>(value: unknown, assertion?: (value: T) => value is T): value is T[]; | ||
| /** | ||
| * Checks if the given value is a string. | ||
| * | ||
| * just check if the type of value is string | ||
| * | ||
| * @param value - The value to be checked. | ||
| * @return Returns true if the value is a string, false otherwise. | ||
| */ | ||
| declare function isString(value: unknown): value is string; | ||
| /** | ||
| * Checks if the input value is a Date. | ||
| * | ||
| * @param value - the input value to be checked | ||
| * @return true if the input is a Date, false otherwise | ||
| */ | ||
| declare function isDate(value: any): value is Date; | ||
| /** | ||
| * Checks if the given function is an asynchronous function. | ||
| * | ||
| * @param fn - The function to check | ||
| * @return Whether the function is asynchronous or not | ||
| */ | ||
| declare function isAsyncFunction<T = unknown>(value: unknown): value is ((...args: any[]) => Promise<T>); | ||
| /** | ||
| * Checks if the given value is a plain object. | ||
| * | ||
| * 1. The value must be an object and is not null | ||
| * 2. The value must not have any prototype or it's prototype equals to Object.prototype or it's grandparent prototype is null | ||
| * 3. The value must not have the Symbol.toStringTag or Symbol.iterator properties | ||
| * | ||
| * @param value - The value to be checked. | ||
| * @return Whether the value is a plain object. | ||
| */ | ||
| declare function isPlainObject<Value = unknown>(value: unknown): value is Record<PropertyKey, Value>; | ||
| /** | ||
| * Type guard function to check if the input is a Map object. | ||
| * | ||
| * @param value - the object to be checked | ||
| * @return true if the input is a Map object, false otherwise | ||
| */ | ||
| declare function isMap<Key = unknown, Value = unknown>(value: unknown): value is Map<Key, Value>; | ||
| /** | ||
| * Checks if the given value is a Set. | ||
| * | ||
| * @param value - the value to be checked | ||
| * @return true if the value is a Set, false otherwise | ||
| */ | ||
| declare function isSet<T = unknown>(value: unknown): value is Set<T>; | ||
| /** | ||
| * Checks if the given value is an HTML element. | ||
| * | ||
| * 1. The value must be an object | ||
| * 2. The value must have the following properties: nodeName, nodeType | ||
| * 3. The value must not have any other properties | ||
| * | ||
| * @param value - The value to be checked. | ||
| * @return Whether the value is an HTML element. | ||
| */ | ||
| declare function isHtmlElement(value: unknown): value is HTMLElement; | ||
| declare const is: { | ||
| number: typeof isNumber; | ||
| string: typeof isString; | ||
| boolean: typeof isBoolean; | ||
| null: typeof isNull; | ||
| undefined: typeof isUndefined; | ||
| object: typeof isObject; | ||
| array: typeof isArray; | ||
| map: typeof isMap; | ||
| set: typeof isSet; | ||
| date: typeof isDate; | ||
| function: typeof isFunction; | ||
| asyncFunction: typeof isAsyncFunction; | ||
| plainObject: typeof isPlainObject; | ||
| htmlElement: typeof isHtmlElement; | ||
| }; | ||
| declare const index_is: typeof is; | ||
| declare const index_isArray: typeof isArray; | ||
| declare const index_isAsyncFunction: typeof isAsyncFunction; | ||
| declare const index_isBoolean: typeof isBoolean; | ||
| declare const index_isDate: typeof isDate; | ||
| declare const index_isFunction: typeof isFunction; | ||
| declare const index_isHtmlElement: typeof isHtmlElement; | ||
| declare const index_isMap: typeof isMap; | ||
| declare const index_isNull: typeof isNull; | ||
| declare const index_isNumber: typeof isNumber; | ||
| declare const index_isObject: typeof isObject; | ||
| declare const index_isPlainObject: typeof isPlainObject; | ||
| declare const index_isSet: typeof isSet; | ||
| declare const index_isString: typeof isString; | ||
| declare const index_isUndefined: typeof isUndefined; | ||
| declare namespace index { | ||
| export { index_is as is, index_isArray as isArray, index_isAsyncFunction as isAsyncFunction, index_isBoolean as isBoolean, index_isDate as isDate, index_isFunction as isFunction, index_isHtmlElement as isHtmlElement, index_isMap as isMap, index_isNull as isNull, index_isNumber as isNumber, index_isObject as isObject, index_isPlainObject as isPlainObject, index_isSet as isSet, index_isString as isString, index_isUndefined as isUndefined }; | ||
| } | ||
| declare function isEmpty$1<T>(arrayLike: ArrayLike<T> | undefined): boolean; | ||
@@ -5,9 +156,5 @@ declare function isNotEmpty$1<T>(arrayLike: ArrayLike<T> | undefined): boolean; | ||
| declare namespace lists { | ||
| export { | ||
| isEmpty$1 as isEmpty, | ||
| isNotEmpty$1 as isNotEmpty, | ||
| }; | ||
| export { isEmpty$1 as isEmpty, isNotEmpty$1 as isNotEmpty }; | ||
| } | ||
| declare function isString(obj: any): boolean; | ||
| /** | ||
@@ -28,17 +175,7 @@ * checks if a string is empty or not | ||
| declare const str_isNotEmpty: typeof isNotEmpty; | ||
| declare const str_isString: typeof isString; | ||
| declare const str_toUpperCase: typeof toUpperCase; | ||
| declare namespace str { | ||
| export { | ||
| str_isEmpty as isEmpty, | ||
| str_isNotEmpty as isNotEmpty, | ||
| str_isString as isString, | ||
| str_toUpperCase as toUpperCase, | ||
| }; | ||
| export { str_isEmpty as isEmpty, str_isNotEmpty as isNotEmpty, str_toUpperCase as toUpperCase }; | ||
| } | ||
| declare function isUndefined(obj: any): boolean; | ||
| declare function isAsyncFunction(fn?: (...args: any) => any): boolean; | ||
| declare function isDeepEquals(first: any, second: any, keys?: string[]): boolean; | ||
| export { lists as Lists, str as Strings, isAsyncFunction, isDeepEquals, isUndefined }; | ||
| export { lists as Lists, str as Strings, index as is }; |
+161
-46
@@ -1,52 +0,168 @@ | ||
| function isEmpty$1(arrayLike) { | ||
| return arrayLike ? arrayLike.length === 0 : true; | ||
| const typedArrayTypeNames = [ | ||
| "Int8Array", | ||
| "Uint8Array", | ||
| "Uint8ClampedArray", | ||
| "Int16Array", | ||
| "Uint16Array", | ||
| "Int32Array", | ||
| "Uint32Array", | ||
| "Float32Array", | ||
| "Float64Array", | ||
| "BigInt64Array", | ||
| "BigUint64Array" | ||
| ]; | ||
| const objectTypeNames = [ | ||
| "Function", | ||
| "Generator", | ||
| "AsyncGenerator", | ||
| "GeneratorFunction", | ||
| "AsyncGeneratorFunction", | ||
| "AsyncFunction", | ||
| "Observable", | ||
| "Array", | ||
| "Buffer", | ||
| "Blob", | ||
| "Object", | ||
| "RegExp", | ||
| "Date", | ||
| "Error", | ||
| "Map", | ||
| "Set", | ||
| "WeakMap", | ||
| "WeakSet", | ||
| "WeakRef", | ||
| "ArrayBuffer", | ||
| "SharedArrayBuffer", | ||
| "DataView", | ||
| "Promise", | ||
| "URL", | ||
| "FormData", | ||
| "URLSearchParams", | ||
| "HTMLElement", | ||
| "NaN", | ||
| ...typedArrayTypeNames | ||
| ]; | ||
| const DOM_PROPERTIES_TO_CHECK = [ | ||
| "innerHTML", | ||
| "ownerDocument", | ||
| "style", | ||
| "attributes", | ||
| "nodeValue" | ||
| ]; | ||
| function getObjectType(value) { | ||
| const objectTypeName = Object.prototype.toString.call(value).slice(8, -1); | ||
| if (/HTML\w+Element/.test(objectTypeName) && isHtmlElement(value)) { | ||
| return "HTMLElement"; | ||
| } | ||
| if (objectTypeNames.includes(objectTypeName)) { | ||
| return objectTypeName; | ||
| } | ||
| return void 0; | ||
| } | ||
| function isNotEmpty$1(arrayLike) { | ||
| return !isEmpty$1(arrayLike); | ||
| } | ||
| const lists = { | ||
| __proto__: null, | ||
| isEmpty: isEmpty$1, | ||
| isNotEmpty: isNotEmpty$1 | ||
| }; | ||
| function isUndefined(obj) { | ||
| return typeof obj === "undefined"; | ||
| function isUndefined(value) { | ||
| return typeof value === "undefined"; | ||
| } | ||
| function isAsyncFunction(fn) { | ||
| if (!fn) | ||
| function isNull(value) { | ||
| return value === null; | ||
| } | ||
| function isBoolean(value) { | ||
| return typeof value === "boolean"; | ||
| } | ||
| function isNumber(value) { | ||
| return typeof value === "number"; | ||
| } | ||
| function isFunction(value) { | ||
| return typeof value === "function"; | ||
| } | ||
| function isObject(value) { | ||
| return !isNull(value) && typeof value === "object" || isFunction(value); | ||
| } | ||
| function isArray(value, assertion) { | ||
| if (!Array.isArray(value)) { | ||
| return false; | ||
| return Object.getPrototypeOf(fn)[Symbol.toStringTag] === "AsyncFunction"; | ||
| } | ||
| function isDeepEquals(first, second, keys) { | ||
| if (!first || !second) { | ||
| return first === second; | ||
| } | ||
| if (typeof first !== "object" || typeof second !== "object") { | ||
| return first === second; | ||
| if (!isFunction(assertion)) { | ||
| return true; | ||
| } | ||
| if (Array.isArray(first) && Array.isArray(second)) { | ||
| if (first.length !== second.length) { | ||
| return false; | ||
| } else { | ||
| return first.every((item, index) => isDeepEquals(item, second[index])); | ||
| } | ||
| } | ||
| const keys1 = keys ?? Object.keys(first); | ||
| const keys2 = keys ?? Object.keys(second); | ||
| if (keys1.length !== keys2.length) { | ||
| return value.every((element) => assertion(element)); | ||
| } | ||
| function isString(value) { | ||
| return typeof value === "string"; | ||
| } | ||
| function isDate(value) { | ||
| return getObjectType(value) === "Date"; | ||
| } | ||
| function isAsyncFunction(value) { | ||
| return getObjectType(value) === "AsyncFunction"; | ||
| } | ||
| function isPlainObject(value) { | ||
| if (!isObject(value) || isNull(value)) { | ||
| return false; | ||
| } | ||
| for (const key of keys1) { | ||
| if (!keys2.includes(key) || !isDeepEquals(first[key], second[key])) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| const prototype = Object.getPrototypeOf(value); | ||
| return (isNull(prototype) || prototype === Object.prototype || isNull(Object.getPrototypeOf(prototype))) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value); | ||
| } | ||
| function isString(obj) { | ||
| return typeof obj === "string"; | ||
| function isMap(value) { | ||
| return getObjectType(value) === "Map"; | ||
| } | ||
| function isSet(value) { | ||
| return getObjectType(value) === "Set"; | ||
| } | ||
| function isHtmlElement(value) { | ||
| return isObject(value) && value.nodeType === Node.ELEMENT_NODE && isString(value.nodeName) && !isPlainObject(value) && DOM_PROPERTIES_TO_CHECK.every((property) => property in value); | ||
| } | ||
| const is = { | ||
| number: isNumber, | ||
| string: isString, | ||
| boolean: isBoolean, | ||
| null: isNull, | ||
| undefined: isUndefined, | ||
| object: isObject, | ||
| array: isArray, | ||
| map: isMap, | ||
| set: isSet, | ||
| date: isDate, | ||
| function: isFunction, | ||
| asyncFunction: isAsyncFunction, | ||
| plainObject: isPlainObject, | ||
| htmlElement: isHtmlElement | ||
| }; | ||
| const index = { | ||
| __proto__: null, | ||
| is: is, | ||
| isArray: isArray, | ||
| isAsyncFunction: isAsyncFunction, | ||
| isBoolean: isBoolean, | ||
| isDate: isDate, | ||
| isFunction: isFunction, | ||
| isHtmlElement: isHtmlElement, | ||
| isMap: isMap, | ||
| isNull: isNull, | ||
| isNumber: isNumber, | ||
| isObject: isObject, | ||
| isPlainObject: isPlainObject, | ||
| isSet: isSet, | ||
| isString: isString, | ||
| isUndefined: isUndefined | ||
| }; | ||
| function isEmpty$1(arrayLike) { | ||
| return arrayLike ? arrayLike.length === 0 : true; | ||
| } | ||
| function isNotEmpty$1(arrayLike) { | ||
| return !isEmpty$1(arrayLike); | ||
| } | ||
| const lists = { | ||
| __proto__: null, | ||
| isEmpty: isEmpty$1, | ||
| isNotEmpty: isNotEmpty$1 | ||
| }; | ||
| function isEmpty(str, trim = false) { | ||
@@ -71,9 +187,8 @@ if (isUndefined(str)) | ||
| const str = { | ||
| __proto__: null, | ||
| isEmpty: isEmpty, | ||
| isNotEmpty: isNotEmpty, | ||
| isString: isString, | ||
| toUpperCase: toUpperCase | ||
| __proto__: null, | ||
| isEmpty: isEmpty, | ||
| isNotEmpty: isNotEmpty, | ||
| toUpperCase: toUpperCase | ||
| }; | ||
| export { lists as Lists, str as Strings, isAsyncFunction, isDeepEquals, isUndefined }; | ||
| export { lists as Lists, str as Strings, index as is }; |
+11
-11
| { | ||
| "name": "@rainbowatcher/js-utils", | ||
| "version": "0.0.8", | ||
| "version": "0.0.9", | ||
| "description": "Opinionated collection of common JavaScript / TypeScript utils by @rainbowatcher", | ||
@@ -34,13 +34,13 @@ "author": "rainbowatcher <rainbow-w@qq.com>", | ||
| "devDependencies": { | ||
| "@commitlint/types": "^17.4.4", | ||
| "@rainbowatcher/eslint-config-json": "^0.3.0", | ||
| "@rainbowatcher/eslint-config-ts": "^0.3.0", | ||
| "changelogen": "^0.5.4", | ||
| "commitlint": "^17.6.7", | ||
| "eslint": "^8.45.0", | ||
| "lint-staged": "^13.2.3", | ||
| "@commitlint/types": "^18.4.4", | ||
| "@rainbowatcher/eslint-config-json": "^0.3.7", | ||
| "@rainbowatcher/eslint-config-ts": "^0.3.7", | ||
| "changelogen": "^0.5.5", | ||
| "commitlint": "^18.4.4", | ||
| "eslint": "^8.56.0", | ||
| "lint-staged": "^15.2.0", | ||
| "simple-git-hooks": "^2.9.0", | ||
| "typescript": "^5.1.6", | ||
| "unbuild": "^1.2.1", | ||
| "vitest": "^0.33.0" | ||
| "typescript": "^5.3.3", | ||
| "unbuild": "^2.0.0", | ||
| "vitest": "^0.34.6" | ||
| }, | ||
@@ -47,0 +47,0 @@ "simple-git-hooks": { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
31881
257.49%8
33.33%538
186.17%1
Infinity%