@rainbowatcher/js-utils
Advanced tools
| var S=Object.defineProperty;var f=(e,n)=>{for(var c in n)S(e,c,{get:n[c],enumerable:!0})};var O={};f(O,{isEmpty:()=>E,isNotEmpty:()=>N});function E(e){return e?e.length===0:!0}function N(e){return!E(e)}var w={};f(w,{is:()=>F,isArray:()=>T,isAsyncFunction:()=>b,isBoolean:()=>m,isDate:()=>l,isFunction:()=>u,isHtmlElement:()=>s,isMap:()=>d,isNull:()=>r,isNumber:()=>y,isObject:()=>a,isPlainObject:()=>p,isSet:()=>g,isString:()=>t,isUndefined:()=>i});var M=["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"],x=["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",...M],A=["innerHTML","ownerDocument","style","attributes","nodeValue"];function o(e){let n=Object.prototype.toString.call(e).slice(8,-1);if(/HTML\w+Element/.test(n)&&s(e))return"HTMLElement";if(x.includes(n))return n}function i(e){return e===void 0}function r(e){return e===null}function m(e){return typeof e=="boolean"}function y(e){return typeof e=="number"}function u(e){return typeof e=="function"}function a(e){return!r(e)&&typeof e=="object"||u(e)}function t(e){return typeof e=="string"}function l(e){return o(e)==="Date"}function b(e){return o(e)==="AsyncFunction"}function p(e){if(!a(e)||r(e))return!1;let n=Object.getPrototypeOf(e);return(r(n)||n===Object.prototype||r(Object.getPrototypeOf(n)))&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function T(e,n){return Array.isArray(e)?u(n)?e.every(c=>n(c)):!0:!1}function d(e){return o(e)==="Map"}function g(e){return o(e)==="Set"}function s(e){return a(e)&&e.nodeType===Node.ELEMENT_NODE&&t(e.nodeName)&&!p(e)&&A.every(n=>n in e)}var F={array:T,asyncFunction:b,boolean:m,date:l,function:u,htmlElement:s,map:d,null:r,number:y,object:a,plainObject:p,set:g,string:t,undefined:i};var k={};f(k,{isEmpty:()=>j,isNotEmpty:()=>H,toUpperCase:()=>P});function j(e,n=!1){if(i(e))return!0;if(!t(e))throw new TypeError("Strings.isEmpty accepts only string type parameters");return n?e.trim().length===0:e.length===0}function H(e,n=!1){return!j(e,n)}function P(e){if(!i(e)){if(!t(e))throw new TypeError("Strings.toUpperCase accepts only string type parameters");return e?.toUpperCase()}}export{O as Collections,k as Strings,w as is}; |
+5
-40
| { | ||
| "name": "@rainbowatcher/js-utils", | ||
| "type": "module", | ||
| "version": "0.1.1", | ||
| "version": "0.2.0", | ||
| "description": "Opinionated collection of common JavaScript / TypeScript utils by @rainbowatcher", | ||
@@ -15,8 +15,6 @@ "author": "rainbowatcher <rainbow-w@qq.com>", | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.mjs", | ||
| "require": "./dist/index.cjs" | ||
| "import": "./dist/index.js" | ||
| } | ||
| }, | ||
| "main": "dist/index.cjs", | ||
| "module": "./dist/index.mjs", | ||
| "module": "./dist/index.js", | ||
| "types": "./dist/index.d.ts", | ||
@@ -27,40 +25,7 @@ "files": [ | ||
| "engines": { | ||
| "node": ">=18" | ||
| "node": ">=20" | ||
| }, | ||
| "devDependencies": { | ||
| "@commitlint/types": "^19.0.3", | ||
| "@rainbowatcher/eslint-config": "^0.6.3", | ||
| "@rainbowatcher/eslint-config-ignore": "^0.6.3", | ||
| "@rainbowatcher/eslint-config-js": "^0.6.3", | ||
| "@rainbowatcher/eslint-config-json": "^0.6.3", | ||
| "@rainbowatcher/eslint-config-md": "^0.6.3", | ||
| "@rainbowatcher/eslint-config-prettier": "^0.6.3", | ||
| "@rainbowatcher/eslint-config-ts": "^0.6.3", | ||
| "bumpp": "^9.4.1", | ||
| "commitlint": "^19.3.0", | ||
| "eslint": "^9.2.0", | ||
| "git-cliff": "^2.2.2", | ||
| "happy-dom": "^14.11.0", | ||
| "lint-staged": "^15.2.2", | ||
| "simple-git-hooks": "^2.11.1", | ||
| "typescript": "^5.4.5", | ||
| "unbuild": "^2.0.0", | ||
| "vitest": "^1.6.0" | ||
| }, | ||
| "simple-git-hooks": { | ||
| "pre-commit": "npx lint-staged", | ||
| "commit-msg": "npx commitlint --edit $1" | ||
| }, | ||
| "lint-staged": { | ||
| "*.{ts,json}": "eslint" | ||
| }, | ||
| "scripts": { | ||
| "build": "unbuild", | ||
| "lint": "eslint .", | ||
| "lint:fix": "eslint . --fix", | ||
| "test": "vitest", | ||
| "typecheck": "tsc --noEmit", | ||
| "changelog": "git-cliff -lp CHANGELOG.md", | ||
| "release": "bumpp --all -x 'pnpm changelog' && pnpm build && pnpm publish" | ||
| "build": "tsup" | ||
| } | ||
| } |
-199
| 'use strict'; | ||
| function isEmpty$1(arrayLike) { | ||
| return arrayLike ? arrayLike.length === 0 : true; | ||
| } | ||
| function isNotEmpty$1(arrayLike) { | ||
| return !isEmpty$1(arrayLike); | ||
| } | ||
| const collections = { | ||
| __proto__: null, | ||
| isEmpty: isEmpty$1, | ||
| isNotEmpty: isNotEmpty$1 | ||
| }; | ||
| 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 isUndefined(value) { | ||
| return value === void 0; | ||
| } | ||
| 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 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; | ||
| } | ||
| const prototype = Object.getPrototypeOf(value); | ||
| return (isNull(prototype) || prototype === Object.prototype || isNull(Object.getPrototypeOf(prototype))) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value); | ||
| } | ||
| function isArray(value, assertion) { | ||
| if (!Array.isArray(value)) { | ||
| return false; | ||
| } | ||
| if (!isFunction(assertion)) { | ||
| return true; | ||
| } | ||
| return value.every((element) => assertion(element)); | ||
| } | ||
| 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 = { | ||
| array: isArray, | ||
| asyncFunction: isAsyncFunction, | ||
| boolean: isBoolean, | ||
| date: isDate, | ||
| function: isFunction, | ||
| htmlElement: isHtmlElement, | ||
| map: isMap, | ||
| null: isNull, | ||
| number: isNumber, | ||
| object: isObject, | ||
| plainObject: isPlainObject, | ||
| set: isSet, | ||
| string: isString, | ||
| undefined: isUndefined | ||
| }; | ||
| 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(str, trim = false) { | ||
| if (isUndefined(str)) | ||
| return true; | ||
| if (!isString(str)) { | ||
| throw new TypeError("Strings.isEmpty accepts only string type parameters"); | ||
| } | ||
| return trim ? str.trim().length === 0 : str.length === 0; | ||
| } | ||
| function isNotEmpty(str, trim = false) { | ||
| return !isEmpty(str, trim); | ||
| } | ||
| function toUpperCase(str) { | ||
| if (isUndefined(str)) | ||
| return; | ||
| if (!isString(str)) { | ||
| throw new TypeError("Strings.toUpperCase accepts only string type parameters"); | ||
| } | ||
| return str?.toUpperCase(); | ||
| } | ||
| const str = { | ||
| __proto__: null, | ||
| isEmpty: isEmpty, | ||
| isNotEmpty: isNotEmpty, | ||
| toUpperCase: toUpperCase | ||
| }; | ||
| exports.Collections = collections; | ||
| exports.Strings = str; | ||
| exports.is = index; |
-179
| declare function isEmpty$1<T>(arrayLike: ArrayLike<T> | undefined): boolean; | ||
| declare function isNotEmpty$1<T>(arrayLike: ArrayLike<T> | undefined): boolean; | ||
| declare namespace collections { | ||
| export { isEmpty$1 as isEmpty, isNotEmpty$1 as isNotEmpty }; | ||
| } | ||
| /** | ||
| * 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[]; | ||
| /** | ||
| * 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; | ||
| /** | ||
| * 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 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>; | ||
| declare const is: { | ||
| array: typeof isArray; | ||
| asyncFunction: typeof isAsyncFunction; | ||
| boolean: typeof isBoolean; | ||
| date: typeof isDate; | ||
| function: typeof isFunction; | ||
| htmlElement: typeof isHtmlElement; | ||
| map: typeof isMap; | ||
| null: typeof isNull; | ||
| number: typeof isNumber; | ||
| object: typeof isObject; | ||
| plainObject: typeof isPlainObject; | ||
| set: typeof isSet; | ||
| string: typeof isString; | ||
| undefined: typeof isUndefined; | ||
| }; | ||
| 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 }; | ||
| } | ||
| /** | ||
| * 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 { collections as Collections, str as Strings, index as is }; |
-179
| declare function isEmpty$1<T>(arrayLike: ArrayLike<T> | undefined): boolean; | ||
| declare function isNotEmpty$1<T>(arrayLike: ArrayLike<T> | undefined): boolean; | ||
| declare namespace collections { | ||
| export { isEmpty$1 as isEmpty, isNotEmpty$1 as isNotEmpty }; | ||
| } | ||
| /** | ||
| * 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[]; | ||
| /** | ||
| * 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; | ||
| /** | ||
| * 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 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>; | ||
| declare const is: { | ||
| array: typeof isArray; | ||
| asyncFunction: typeof isAsyncFunction; | ||
| boolean: typeof isBoolean; | ||
| date: typeof isDate; | ||
| function: typeof isFunction; | ||
| htmlElement: typeof isHtmlElement; | ||
| map: typeof isMap; | ||
| null: typeof isNull; | ||
| number: typeof isNumber; | ||
| object: typeof isObject; | ||
| plainObject: typeof isPlainObject; | ||
| set: typeof isSet; | ||
| string: typeof isString; | ||
| undefined: typeof isUndefined; | ||
| }; | ||
| 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 }; | ||
| } | ||
| /** | ||
| * 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 { collections as Collections, str as Strings, index as is }; |
-195
| function isEmpty$1(arrayLike) { | ||
| return arrayLike ? arrayLike.length === 0 : true; | ||
| } | ||
| function isNotEmpty$1(arrayLike) { | ||
| return !isEmpty$1(arrayLike); | ||
| } | ||
| const collections = { | ||
| __proto__: null, | ||
| isEmpty: isEmpty$1, | ||
| isNotEmpty: isNotEmpty$1 | ||
| }; | ||
| 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 isUndefined(value) { | ||
| return value === void 0; | ||
| } | ||
| 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 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; | ||
| } | ||
| const prototype = Object.getPrototypeOf(value); | ||
| return (isNull(prototype) || prototype === Object.prototype || isNull(Object.getPrototypeOf(prototype))) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value); | ||
| } | ||
| function isArray(value, assertion) { | ||
| if (!Array.isArray(value)) { | ||
| return false; | ||
| } | ||
| if (!isFunction(assertion)) { | ||
| return true; | ||
| } | ||
| return value.every((element) => assertion(element)); | ||
| } | ||
| 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 = { | ||
| array: isArray, | ||
| asyncFunction: isAsyncFunction, | ||
| boolean: isBoolean, | ||
| date: isDate, | ||
| function: isFunction, | ||
| htmlElement: isHtmlElement, | ||
| map: isMap, | ||
| null: isNull, | ||
| number: isNumber, | ||
| object: isObject, | ||
| plainObject: isPlainObject, | ||
| set: isSet, | ||
| string: isString, | ||
| undefined: isUndefined | ||
| }; | ||
| 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(str, trim = false) { | ||
| if (isUndefined(str)) | ||
| return true; | ||
| if (!isString(str)) { | ||
| throw new TypeError("Strings.isEmpty accepts only string type parameters"); | ||
| } | ||
| return trim ? str.trim().length === 0 : str.length === 0; | ||
| } | ||
| function isNotEmpty(str, trim = false) { | ||
| return !isEmpty(str, trim); | ||
| } | ||
| function toUpperCase(str) { | ||
| if (isUndefined(str)) | ||
| return; | ||
| if (!isString(str)) { | ||
| throw new TypeError("Strings.toUpperCase accepts only string type parameters"); | ||
| } | ||
| return str?.toUpperCase(); | ||
| } | ||
| const str = { | ||
| __proto__: null, | ||
| isEmpty: isEmpty, | ||
| isNotEmpty: isNotEmpty, | ||
| toUpperCase: toUpperCase | ||
| }; | ||
| export { collections as Collections, str as Strings, index as is }; |
-13
| [](https://packagephobia.com/result?p=@rainbowatcher/js-utils) | ||
| [](https://github.com/rainbowatcher/js-utils/actions) | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
| # Js-utils | ||
| Some helpful js functions. |
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.
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
0
-100%10830
-66.49%4
-50%181
-66.61%4
100%2
100%0
-100%1
Infinity%