helper-fns
Advanced tools
Comparing version
@@ -36,63 +36,37 @@ declare const assert: (condition: boolean, message: string) => asserts condition; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {*} obj | ||
* @returns {boolean} | ||
* | ||
* check if object is empty | ||
* It returns true if the object is empty, false if it's not | ||
* @param {any} obj - any | ||
* @returns A function that takes in an object and returns a boolean. | ||
*/ | ||
declare const isEmpty: (obj: any) => boolean; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {( Record<string, any> | ArrayLike<unknown>)} obj | ||
* @returns | ||
* | ||
* remove empty | ||
* | ||
* It takes an object and returns a new object with all the null values removed | ||
* @param {Record<string, any> | ArrayLike<unknown>} obj - Record<string, any> | ArrayLike<unknown> | ||
* @returns An object with all the keys and values that are not null. | ||
*/ | ||
declare const removeEmpty: (obj: Record<string, any> | ArrayLike<unknown>) => {}; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @template T | ||
* @template K | ||
* @param {T} obj | ||
* @param {K[]} keys | ||
* @returns {Pick<T, K>} | ||
* | ||
* | ||
* Pick only specified keys from any object | ||
* | ||
* | ||
* It takes an object and an array of keys, and returns a new object with only those keys | ||
* @param {T} obj - T - the object to pick properties from | ||
* @param {K[]} keys - K[] | ||
* @returns Pick<T, K> | ||
*/ | ||
declare const pick: <T, K extends keyof T>(obj: T, keys: K[]) => Pick<T, K>; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {...any[]} args | ||
* @returns {string} | ||
* | ||
* this is for lodash memoize | ||
* It takes any number of arguments, and returns a stringified version of those arguments | ||
* @param {any[]} args - The arguments passed to the resolver. | ||
* @returns A stringified version of the arguments passed in. | ||
*/ | ||
declare const resolverArgs: (...args: any[]) => string; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {Array<number>} arr | ||
* @param {number} [initialValue=0] | ||
* @returns {number} | ||
* It takes an array of numbers and an optional initial value, and returns the sum of the array | ||
* @param arr - The array to be reduced. | ||
* @param [initialValue=0] - The initial value of the accumulator. | ||
* @returns [1, 2, 3, 4, 5] | ||
*/ | ||
declare const sumOfAnArray: (arr: Array<number>, initialValue?: number) => number; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {Iterable<unknown>} values | ||
* @returns {Iterable<unknown>} | ||
* Return an iterable of unique values from the given iterable. | ||
* @param values - Iterable<unknown> | ||
* @returns [...new Set(values)] | ||
*/ | ||
@@ -104,104 +78,81 @@ declare const unique: (values: Iterable<unknown>) => Iterable<unknown>; | ||
* @param {K[]} keys - K[] | ||
* @returns A function that takes a string and returns a string. | ||
* @returns { a: 1, b: 2 } | ||
*/ | ||
declare const omit: <T extends object, K extends keyof T>(obj: T, keys: K[]) => Omit<T, K>; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {*} arr | ||
* @param {any[]} props | ||
* @param {{ [x: string]: string }} orders | ||
* | ||
* order by a key | ||
* | ||
* It sorts an array of objects by a list of properties, in the order specified | ||
* @param {any} arr - The array to sort | ||
* @param {any[]} props - The properties to sort by. | ||
* @param orders - An array of strings that specifies the order of sorting. | ||
*/ | ||
declare const orderBy: (arr: any, props: any[], orders: Record<string, string>) => void; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {...any[]} fns | ||
* Pipes takes a list of functions and returns a function that is the composition of those functions. | ||
* @param {any[]} fns - an array of functions | ||
* @returns A function that takes in a list of functions and returns a function that takes in a list of | ||
* arguments. | ||
*/ | ||
declare const pipes: (...fns: any[]) => any; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {any[]} arr | ||
* @param {(string | number)} key | ||
* @returns {any[]} | ||
* Pluck takes an array of objects and returns an array of the values of a certain property in each | ||
* object | ||
* @param {any[]} arr - any[] - the array we want to pluck from | ||
* @param {string | number} key - string | number | ||
* @returns [1, 2, 3] | ||
*/ | ||
declare const pluck: (arr: any[], key: string | number) => any[]; | ||
/** | ||
* | ||
* rename object keys | ||
* | ||
* @export | ||
* @param {Record<string, any>} keysMap | ||
* @param {Record<string, any>} obj | ||
* It takes an object and a map of keys to new keys, and returns a new object with the keys renamed | ||
* according to the map, while keeping the values intact | ||
* @param keysMap - Record<string, any> | ||
* @param obj - The object to be renamed | ||
*/ | ||
declare const renameKeys: (keysMap: Record<string, any>, obj: Record<string, any>) => void; | ||
/** | ||
* "It takes an array of objects and returns an array of the values of a specific attribute of those | ||
* objects." | ||
* | ||
* | ||
* @export | ||
* @param {Array<unknown>} objectArray | ||
* @param {string} attr | ||
* @returns {Array<unknown>} | ||
* Here's an example of how to use it: | ||
* @param objectArray - The array of objects you want to convert. | ||
* @param {string} attr - The attribute of the object you want to extract. | ||
* @returns An array of the values of the attribute passed in. | ||
*/ | ||
declare const objectArrayToArray: (objectArray: Array<unknown>, attr: string) => Array<unknown>; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {number} num | ||
* @param {number} [fixed=2] | ||
* @returns {number} | ||
* | ||
* truncates a decimal number | ||
* It takes a number and returns a number with a fixed number of decimal places | ||
* @param {number} num - The number to be fixed. | ||
* @param [fixed=2] - The number of decimal places to round to. | ||
* @returns A function that takes a number and a fixed number and returns a number. | ||
*/ | ||
declare const fixedDecimal: (num: number, fixed?: number) => number; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {string} val | ||
* @returns {(string | number | boolean)} | ||
* It takes a string and returns a string, number, or boolean | ||
* @param {string} val - string - the value to be parsed | ||
*/ | ||
declare const autoParseValues: (val: string) => string | number | boolean; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {any[]} arr | ||
* @return {*} {any[]} | ||
* It takes an array of arrays and returns a new array with all the elements flattened | ||
* @param {any[]} arr - The array to flatten. | ||
* @returns [1, 2, 3, 4, 5, 6] | ||
*/ | ||
declare const flattenDeep: (arr: any[]) => any[]; | ||
/** | ||
* | ||
* difference between array A and B , returns a - b | ||
* | ||
* @export | ||
* @param {any[]} a | ||
* @param {any[]} b | ||
* @returns {any[]} | ||
* It returns an array of all the elements in the first array that are not in the second array | ||
* @param {any[]} a - any[] - The first array to compare | ||
* @param {any[]} b - any[] | ||
* @returns The difference between two arrays. | ||
*/ | ||
declare const difference: (a: any[], b: any[]) => any[]; | ||
/** | ||
* | ||
* common between array A and B , returns a includes b | ||
* | ||
* @export | ||
* @param {any[]} a | ||
* @param {any[]} b | ||
* @returns {any[]} | ||
* It takes two arrays and returns an array of the elements that are common to both | ||
* @param {any[]} a - any[] - The first array to compare | ||
* @param {any[]} b - any[] | ||
* @returns The common elements of the two arrays. | ||
*/ | ||
declare const common: (a: any[], b: any[]) => any[]; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {string} str | ||
* @return {*} {string} | ||
* If the string exists, return the first character capitalized and the rest of the string lowercase, | ||
* otherwise return an empty string. | ||
* @param {string} str - string - This is the string that we want to capitalize. | ||
* @returns A function that takes a string and returns a string. | ||
*/ | ||
@@ -220,87 +171,11 @@ declare const capitalize: (str: string) => string; | ||
declare const debounce: (func: Function, wait: number, immediate?: boolean) => (this: any) => void; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {} callback | ||
* @return {*} {number} | ||
*/ | ||
declare const timeTaken: (callback: Function) => number; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {string} str | ||
* @return {*} {string} | ||
*/ | ||
declare const unescapeHTML: (str: string) => string; | ||
/** | ||
* Throttling enforces a maximum number of times a function | ||
* can be called over time. | ||
* | ||
* @param func a function | ||
* @param wait time | ||
*/ | ||
declare const throttle: (func: Function, wait: number) => () => void; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {number} ms | ||
* @return {*} {string} | ||
*/ | ||
declare const formatDuration: (ms: number) => string; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {string} str | ||
* @return {*} {string} | ||
*/ | ||
declare const capitalizeEveryWord: (str: string) => string; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {string} str | ||
* @return {*} {string} | ||
*/ | ||
declare const lowerFirst: (str: string) => string; | ||
/** | ||
* | ||
* | ||
* @param {Array<unknown>} a | ||
* @param {Array<unknown>} b | ||
* @param {boolean} [duplicates=true] | ||
* @returns {Array<unknown>} | ||
*/ | ||
declare const union: (a: Array<unknown>, b: Array<unknown>, duplicates?: boolean) => Array<unknown>; | ||
/** | ||
* | ||
* checks if a date in a format is valid or not | ||
* | ||
* @export | ||
* @param {string} dateString | ||
* @returns {boolean} | ||
*/ | ||
declare const isDate: (dateString: string) => boolean; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {any[]} arr | ||
* @param {number} [n=1] | ||
* @return {*} {any[]} | ||
*/ | ||
declare const dropRight: (arr: any[], n?: number) => any[]; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {string} text | ||
* @param {{ key: string; iv: string }} config | ||
* @returns | ||
* | ||
* ENC_KEY and IV can be generated as crypto.randomBytes(32).toString('hex'); | ||
*/ | ||
declare const encrypt: (text: string, config: { | ||
@@ -310,20 +185,3 @@ key: string; | ||
}) => string; | ||
/** | ||
* | ||
* converts enum to string array | ||
* | ||
* @export | ||
* @param {object} _enum | ||
*/ | ||
declare const enumToString: (_enum: Record<any, any>) => void; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {string} encrypted | ||
* @param {{ key: string; iv: string }} config | ||
* @returns | ||
* | ||
* | ||
*/ | ||
declare const decrypt: (encrypted: string, config: { | ||
@@ -333,73 +191,8 @@ key: string; | ||
}) => string; | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {string} path | ||
* @returns | ||
*/ | ||
declare const readFile: (path: string) => Promise<unknown>; | ||
/** | ||
* | ||
* Helper to generate random number between two numbers | ||
* | ||
* @export | ||
* @param {number} [a=1] | ||
* @param {number} [b=9] | ||
* @return {*} {number} | ||
*/ | ||
declare const randomNumber: (a?: number, b?: number) => number; | ||
/** | ||
* | ||
* Helper to generate random string | ||
* | ||
* @export | ||
* @param {number} [length=4] | ||
* @returns | ||
*/ | ||
declare const randomString: (length?: number) => string; | ||
/** | ||
* It returns a random string of characters, concatenated with another random string of characters | ||
* @returns A function that returns a string of random characters. | ||
*/ | ||
declare const randomToken: () => string; | ||
/** | ||
* It replaces all instances of the identifier with a random number. | ||
* @param {string} str - The string format you want to replace the tokens in. | ||
* @param [identifier=X] - The identifier that will be replaced with a random number. | ||
* @returns A string with all instances of the identifier replaced with a random number. | ||
*/ | ||
declare const orderedToken: (str: string, identifier?: string) => string; | ||
/** | ||
* | ||
* Get string after a substring | ||
* | ||
* @export | ||
* @param {string} str | ||
* @param {string} substr | ||
* @returns | ||
*/ | ||
declare const strAfter: (str: string, substr: string) => string; | ||
/** | ||
* Get string before a substring | ||
* @param str | ||
* @param substr | ||
*/ | ||
declare const strBefore: (str: string, substr: string) => string; | ||
/** | ||
* | ||
* Check if value is not empty | ||
* @export | ||
* @param {*} value | ||
* @returns {boolean} | ||
*/ | ||
declare const isNotEmpty: (value: any) => boolean; | ||
/** | ||
* Clone class instance | ||
* | ||
* @export | ||
* @template T | ||
* @param {T} instance | ||
* @returns {T} | ||
*/ | ||
declare const clone: <T extends { | ||
@@ -495,3 +288,12 @@ constructor: Function; | ||
declare function paginate<T>({ limit, total, results, pages, page }: IPageOptions<T>): PaginatedDto<T>; | ||
/** | ||
* It takes in a length, and two optional parameters, symbols and numbers, and returns a random | ||
* string of the specified length | ||
* @param {number} length - number - The length of the string you want to generate. | ||
* @param {boolean} [symbols=false] - boolean = false | ||
* @param {boolean} [numbers=false] - boolean = false | ||
* @returns A random string of the length specified. | ||
*/ | ||
declare function randomString(length: number, symbols?: boolean, numbers?: boolean): string; | ||
export { IPageOptions, PaginatedDto, PaginationMeta, assert, autoParseValues, capitalize, capitalizeEveryWord, clearUndefined, clone, common, debounce, decrypt, difference, dropRight, encrypt, ensurePrefix, enumToString, fixedDecimal, flattenDeep, formatDuration, generateRandomString, groupBy, invertObj, isBoolean, isDate, isDef, isEmpty, isFunction, isNotEmpty, isNumber, isObject, isString, lowerFirst, noop, normalizeEmail, objectArrayToArray, omit, orderBy, orderedToken, paginate, pick, pipes, pluck, randomNumber, randomString, randomToken, readFile, removeEmpty, renameKeys, resolverArgs, shuffle, slash, slugify, strAfter, strBefore, stringifyQueryParams, sumOfAnArray, template, throttle, timeTaken, toString, unescapeHTML, union, unique }; | ||
export { IPageOptions, PaginatedDto, PaginationMeta, assert, autoParseValues, capitalize, capitalizeEveryWord, clearUndefined, clone, common, debounce, decrypt, difference, dropRight, encrypt, ensurePrefix, enumToString, fixedDecimal, flattenDeep, formatDuration, generateRandomString, groupBy, invertObj, isBoolean, isDate, isDef, isEmpty, isFunction, isNotEmpty, isNumber, isObject, isString, lowerFirst, noop, normalizeEmail, objectArrayToArray, omit, orderBy, orderedToken, paginate, pick, pipes, pluck, randomNumber, randomString, readFile, removeEmpty, renameKeys, resolverArgs, shuffle, slash, slugify, strAfter, strBefore, stringifyQueryParams, sumOfAnArray, template, throttle, timeTaken, toString, unescapeHTML, union, unique }; |
{ | ||
"name": "helper-fns", | ||
"type": "module", | ||
"version": "2.5.6", | ||
"version": "2.5.11", | ||
"packageManager": "pnpm@7.2.1", | ||
@@ -52,5 +52,5 @@ "description": "Some common utilities functions for everyday backend usage with zero dependencies", | ||
"@antfu/ni": "^0.17.2", | ||
"@types/node": "^18.0.6", | ||
"@types/node": "^18.6.4", | ||
"bumpp": "^8.2.1", | ||
"eslint": "^8.20.0", | ||
"eslint": "^8.21.0", | ||
"esno": "^0.16.3", | ||
@@ -60,5 +60,5 @@ "rimraf": "^3.0.2", | ||
"unbuild": "^0.7.6", | ||
"vite": "^3.0.2", | ||
"vitest": "^0.18.1" | ||
"vite": "^3.0.4", | ||
"vitest": "^0.21.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
0
-100%41749
-0.06%1010
-16.87%