amigo-js
v1.0.2
Published
Amigo JS 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
Downloads
294
Maintainers
Readme
Amigo JS
Amigo JS 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.
Installation
NPM
npm install amigo-js
YARN
yarn add amigo-js
Awesome Utils
debounce
Return debounced callback after param delay
Function Signature
debounce(callBack: Function, delay: number): Function
Examples
const getSearchSuggestion = () => {
/* send request ...*/
};
const debouncedSearchRequest = debounce(getSearchSuggestion, 1000); // type of delay is ms
debouncedSearchRequest();
sleep (my best util 💪🏼)
Await the any async method
Function Signature
await sleep(time): Promise<void>
Examples
const startLoader = async () => {
// ...
await sleep(500); // ms
// ...
};
deepClone
Clone data from any data (disconnect any data binding)
Function Signature
deepClone(val: any): typeof val
Examples
const clonedVal = deepClone({ name: "test" });
expect(clonedVal).not.toBe({ name: "test" }); // reference equal
expect(clonedVal).toEqual(clonedVal); // soft equal
Compare
isEqual
Checks the equality of two values.
Function Signature
isEqual(valOne: any, valTwo: any): boolean
Examples
isEqual(10, 10); // true
isEqual("test", 1); // false
isEqual(null, 1); // false
isEqual(null, NaN); // false
isEqual(NaN, NaN); // false
isEqual({ name: "john" }, { name: "john" }); // true
isEqual(["john"], ["john"]); // true
isEqual([{ key: "value" }], [{ key: "value" }]); // true
isNotEqual
Checks the not equality of two values.
Function Signature
isNotEqual(valOne: any, valTwo: any): boolean
Examples
isNotEqual(10, 10); // false
isNotEqual("test", 1); // true
isNotEqual({ name: "john" }, { name: "john" }); // false
isNotEqual(["john"], ["john"]); // true
isNotEqual([{ key: "value" }], [{ key: "value" }]); // false
isBefore
Controls the ordering of two values relative to each other
Function Signature
isBefore(numberOne: number, numberTwo: number): boolean
Examples
isBefore(10, 10); // false
isBefore(-1, -2); // false
isBefore(new Date("01-01-2024").getTime(), new Date("01-01-2025").getTime()); // true
isAfter
Controls the ordering of two values relative to each other
Function Signature
isAfter(numberOne: number, numberTwo: number): boolean
Examples
isAfter(10, 10); // false
isAfter(-1, -2); // true
isAfter(new Date("01-01-2024").getTime(), new Date("01-01-2025").getTime()); // false
Date Compare
isDateBefore
Controls the ordering of two date values relative to each other
Function Signature
isDateBefore(dateOne: Date, dateTwo: Date): boolean
Examples
isDateBefore(new Date(), new Date("2025-03-20")); // true
isDateBefore(new Date(), new Date("2022-03-20")); // false
isDateAfter
Controls the ordering of two date values relative to each other
Function Signature
isDateAfter(dateOne: Date, dateTwo: Date): boolean
Examples
isDateAfter(new Date(), new Date("2025-03-20")); // false
isDateAfter(new Date(), new Date("2022-03-20")); // true
Type Check
isObject
Check if val is an object
Function Signature
isObject(val: any): boolean
Examples
isObject([]); // true
isObject(null); // false
isObject(undefined); // false
isObject(NaN); // false
isObject({}); //
isObject(new Date()); // true
isDate
Check if val is an date
Function Signature
isDate(val: any): boolean
Examples
isDate(Date); // false
isDate(null); // false
isDate("12-22-2023"); // false
isDate(new Date()); // true
isBoolean
Check if val is true or false (boolean)
Function Signature
isBoolean(val: any): boolean
Examples
isBoolean(null); // false
isBoolean(false); // true
isBoolean(true); // true
isBoolean(Boolean); // false
isBoolean(0); // false
isArray
Check if val is an array
Function Signature
isArray(val: any): boolean
Examples
isArray(null); // false
isArray({}); // false
isArray([]); // true
isArray(new Array([])); // true
isNumber
Check if val is an number
Function Signature
isNumber(val: any): boolean
Examples
isNumber(null); // false
isNumber(NaN); // true
isNumber(1); // true
isNumber("1"); // false
isNumber
Check if val is an function
Function Signature
isFunction(val: any): boolean
Examples
isFunction(NaN); // false
isFunction(() => {}); // true
created by Ahmet ilhan