🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@rainbowatcher/js-utils

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rainbowatcher/js-utils - npm Package Compare versions

Comparing version
0.0.9
to
0.1.1
+39
-37
dist/index.cjs
'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 = [

@@ -67,3 +80,3 @@ "Int8Array",

function isUndefined(value) {
return typeof value === "undefined";
return value === void 0;
}

@@ -85,11 +98,2 @@ function isNull(value) {

}
function isArray(value, assertion) {
if (!Array.isArray(value)) {
return false;
}
if (!isFunction(assertion)) {
return true;
}
return value.every((element) => assertion(element));
}
function isString(value) {

@@ -112,2 +116,11 @@ return typeof value === "string";

function isArray(value, assertion) {
if (!Array.isArray(value)) {
return false;
}
if (!isFunction(assertion)) {
return true;
}
return value.every((element) => assertion(element));
}
function isMap(value) {

@@ -125,16 +138,16 @@ return getObjectType(value) === "Map";

const is = {
number: isNumber,
string: isString,
array: isArray,
asyncFunction: isAsyncFunction,
boolean: isBoolean,
date: isDate,
function: isFunction,
htmlElement: isHtmlElement,
map: isMap,
null: isNull,
undefined: isUndefined,
number: isNumber,
object: isObject,
array: isArray,
map: isMap,
plainObject: isPlainObject,
set: isSet,
date: isDate,
function: isFunction,
asyncFunction: isAsyncFunction,
plainObject: isPlainObject,
htmlElement: isHtmlElement
string: isString,
undefined: isUndefined
};

@@ -161,20 +174,8 @@

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) {
if (isUndefined(str))
return true;
if (!isString(str))
if (!isString(str)) {
throw new TypeError("Strings.isEmpty accepts only string type parameters");
}
return trim ? str.trim().length === 0 : str.length === 0;

@@ -187,5 +188,6 @@ }

if (isUndefined(str))
return void 0;
if (!isString(str))
return;
if (!isString(str)) {
throw new TypeError("Strings.toUpperCase accepts only string type parameters");
}
return str?.toUpperCase();

@@ -201,4 +203,4 @@ }

exports.Lists = lists;
exports.Collections = collections;
exports.Strings = str;
exports.is = index;

@@ -0,2 +1,44 @@

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.

@@ -47,10 +89,2 @@ *

/**
* 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.

@@ -90,44 +124,17 @@ *

/**
* 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;
array: typeof isArray;
asyncFunction: typeof isAsyncFunction;
boolean: typeof isBoolean;
date: typeof isDate;
function: typeof isFunction;
htmlElement: typeof isHtmlElement;
map: typeof isMap;
null: typeof isNull;
undefined: typeof isUndefined;
number: typeof isNumber;
object: typeof isObject;
array: typeof isArray;
map: typeof isMap;
plainObject: typeof isPlainObject;
set: typeof isSet;
date: typeof isDate;
function: typeof isFunction;
asyncFunction: typeof isAsyncFunction;
plainObject: typeof isPlainObject;
htmlElement: typeof isHtmlElement;
string: typeof isString;
undefined: typeof isUndefined;
};

@@ -154,9 +161,2 @@

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 };
}
/**

@@ -182,2 +182,2 @@ * checks if a string is empty or not

export { lists as Lists, str as Strings, index as is };
export { collections as Collections, str as Strings, index as is };

@@ -0,2 +1,44 @@

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.

@@ -47,10 +89,2 @@ *

/**
* 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.

@@ -90,44 +124,17 @@ *

/**
* 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;
array: typeof isArray;
asyncFunction: typeof isAsyncFunction;
boolean: typeof isBoolean;
date: typeof isDate;
function: typeof isFunction;
htmlElement: typeof isHtmlElement;
map: typeof isMap;
null: typeof isNull;
undefined: typeof isUndefined;
number: typeof isNumber;
object: typeof isObject;
array: typeof isArray;
map: typeof isMap;
plainObject: typeof isPlainObject;
set: typeof isSet;
date: typeof isDate;
function: typeof isFunction;
asyncFunction: typeof isAsyncFunction;
plainObject: typeof isPlainObject;
htmlElement: typeof isHtmlElement;
string: typeof isString;
undefined: typeof isUndefined;
};

@@ -154,9 +161,2 @@

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 };
}
/**

@@ -182,2 +182,2 @@ * checks if a string is empty or not

export { lists as Lists, str as Strings, index as is };
export { collections as Collections, str as Strings, index as is };

@@ -0,2 +1,44 @@

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.

@@ -47,10 +89,2 @@ *

/**
* 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.

@@ -90,44 +124,17 @@ *

/**
* 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;
array: typeof isArray;
asyncFunction: typeof isAsyncFunction;
boolean: typeof isBoolean;
date: typeof isDate;
function: typeof isFunction;
htmlElement: typeof isHtmlElement;
map: typeof isMap;
null: typeof isNull;
undefined: typeof isUndefined;
number: typeof isNumber;
object: typeof isObject;
array: typeof isArray;
map: typeof isMap;
plainObject: typeof isPlainObject;
set: typeof isSet;
date: typeof isDate;
function: typeof isFunction;
asyncFunction: typeof isAsyncFunction;
plainObject: typeof isPlainObject;
htmlElement: typeof isHtmlElement;
string: typeof isString;
undefined: typeof isUndefined;
};

@@ -154,9 +161,2 @@

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 };
}
/**

@@ -182,2 +182,2 @@ * checks if a string is empty or not

export { lists as Lists, str as Strings, index as is };
export { collections as Collections, str as Strings, index as is };

@@ -0,1 +1,14 @@

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 = [

@@ -65,3 +78,3 @@ "Int8Array",

function isUndefined(value) {
return typeof value === "undefined";
return value === void 0;
}

@@ -83,11 +96,2 @@ function isNull(value) {

}
function isArray(value, assertion) {
if (!Array.isArray(value)) {
return false;
}
if (!isFunction(assertion)) {
return true;
}
return value.every((element) => assertion(element));
}
function isString(value) {

@@ -110,2 +114,11 @@ return typeof value === "string";

function isArray(value, assertion) {
if (!Array.isArray(value)) {
return false;
}
if (!isFunction(assertion)) {
return true;
}
return value.every((element) => assertion(element));
}
function isMap(value) {

@@ -123,16 +136,16 @@ return getObjectType(value) === "Map";

const is = {
number: isNumber,
string: isString,
array: isArray,
asyncFunction: isAsyncFunction,
boolean: isBoolean,
date: isDate,
function: isFunction,
htmlElement: isHtmlElement,
map: isMap,
null: isNull,
undefined: isUndefined,
number: isNumber,
object: isObject,
array: isArray,
map: isMap,
plainObject: isPlainObject,
set: isSet,
date: isDate,
function: isFunction,
asyncFunction: isAsyncFunction,
plainObject: isPlainObject,
htmlElement: isHtmlElement
string: isString,
undefined: isUndefined
};

@@ -159,20 +172,8 @@

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) {
if (isUndefined(str))
return true;
if (!isString(str))
if (!isString(str)) {
throw new TypeError("Strings.isEmpty accepts only string type parameters");
}
return trim ? str.trim().length === 0 : str.length === 0;

@@ -185,5 +186,6 @@ }

if (isUndefined(str))
return void 0;
if (!isString(str))
return;
if (!isString(str)) {
throw new TypeError("Strings.toUpperCase accepts only string type parameters");
}
return str?.toUpperCase();

@@ -199,2 +201,2 @@ }

export { lists as Lists, str as Strings, index as is };
export { collections as Collections, str as Strings, index as is };
{
"name": "@rainbowatcher/js-utils",
"version": "0.0.9",
"type": "module",
"version": "0.1.1",
"description": "Opinionated collection of common JavaScript / TypeScript utils by @rainbowatcher",

@@ -14,4 +15,4 @@ "author": "rainbowatcher <rainbow-w@qq.com>",

"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}

@@ -25,23 +26,24 @@ },

],
"scripts": {
"build": "unbuild",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test": "vitest",
"typecheck": "tsc --noEmit",
"prepare": "simple-git-hooks",
"release": "pnpm build && changelogen --release && npm publish && git push --follow-tags"
"engines": {
"node": ">=18"
},
"devDependencies": {
"@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.3.3",
"@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": "^0.34.6"
"vitest": "^1.6.0"
},

@@ -54,3 +56,12 @@ "simple-git-hooks": {

"*.{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"
}
}

@@ -10,4 +10,5 @@ [![install size](https://packagephobia.com/badge?p=@rainbowatcher/js-utils)](https://packagephobia.com/result?p=@rainbowatcher/js-utils)

![node-lts](https://img.shields.io/node/v-lts/@rainbowatcher/js-utils)
# Js-utils
Some helpful js functions.
Some helpful js functions.