Package Exports
- @ahmetilhn/handy-utils
- @ahmetilhn/handy-utils/build/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ahmetilhn/handy-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
handy-utils
Handy utils offers developers a powerful and easy-to-use toolset. With its clean, modular and scalable code structure, it accelerates development processes and reduces code complexity. With a wide range of functions, it offers ready-made methods for solving common problems.
## InstallationNPM
npm install @ahmetilhn/handy-utilsYARN
yarn add @ahmetilhn/handy-utilsAwesome Utils
deepClone
Clone data from any data (disconnect any data binding)
Function Signature
deepClone(val: any): typeof valExamples
const clonedVal = deepClone({ name: "test" });
expect(clonedVal).not.toBe({ name: "test" }); // reference equal
expect(clonedVal).toEqual(clonedVal); // soft equalsleep
Wait for the execution process as long as you want
Function Signature
sleep(time: number): Promise<void>isServer
Function Signature
// it should return true on node runtime
isServer(); // trueisClient
Function Signature
// it should return true on browser
isClient(); // trueExamples
const jobEverySecond = async () => {
// Codes
await sleep(1000); // sleep for 1 second
};Compare
isDeepEqual
Checks the equality of two values.
Function Signature
isDeepEqual(valOne: any, valTwo: any): booleanExamples
isDeepEqual(10, 10); // true
isDeepEqual("test", 1); // false
isDeepEqual(null, 1); // false
isDeepEqual(null, NaN); // false
isDeepEqual(NaN, NaN); // false
isDeepEqual({ name: "john" }, { name: "john" }); // true
isDeepEqual(["john"], ["john"]); // true
isDeepEqual([{ key: "value" }], [{ key: "value" }]); // trueType Check
isObject
Check if val is an object
Function Signature
isObject(val: any): booleanExamples
isObject([]); // true
isObject(null); // false
isObject(undefined); // false
isObject(NaN); // false
isObject({}); //
isObject(new Date()); // trueisDate
Check if val is an date
Function Signature
isDate(val: any): booleanExamples
isDate(Date); // false
isDate(null); // false
isDate("12-22-2023"); // false
isDate(new Date()); // trueisBoolean
Check if val is true or false (boolean)
Function Signature
isBoolean(val: any): booleanExamples
isBoolean(null); // false
isBoolean(false); // true
isBoolean(true); // true
isBoolean(Boolean); // false
isBoolean(0); // falseisArray
Check if val is an array
Function Signature
isArray(val: any): booleanExamples
isArray(null); // false
isArray({}); // false
isArray([]); // true
isArray(new Array([])); // trueisNumber
Check if val is an number
Function Signature
isNumber(val: any): booleanExamples
isNumber(null); // false
isNumber(NaN); // true
isNumber(1); // true
isNumber("1"); // falseisFunction
Check if val is an function
Function Signature
isFunction(val: any): booleanExamples
isFunction(NaN); // false
isFunction(() => {}); // trueisUndefined
Check if val isn't defined
Function Signature
isUndefined(val: any): booleanExamples
const user = {
name: "John",
};
isUndefined(user.name); // false
isUndefined(user.lastName); // trueisDefined
Check if val is defined
Function Signature
isDefined(val: any): booleanExamples
const user = {
name: "John",
};
isDefined(user.name); // true
isDefined(user.lastName); // falseTest Coverage Result
branches: 94 functions: 100 lines: 100 statements: 97
created by Ahmet ilhan