helper-fns
Advanced tools
Comparing version 2.5.20 to 2.5.22
@@ -10,4 +10,22 @@ declare const assert: (condition: boolean, message: string) => asserts condition; | ||
} | ||
interface IRandomStringOptions { | ||
length: number; | ||
symbols?: boolean; | ||
numbers?: boolean; | ||
} | ||
interface IDebounceOptions { | ||
func: Function; | ||
wait: number; | ||
immediate?: boolean; | ||
} | ||
interface IEncryptOptions { | ||
text: string; | ||
config: { | ||
key: string; | ||
iv: string; | ||
}; | ||
} | ||
declare const isEmpty: (obj: any) => boolean; | ||
declare const removeEmpty: (obj: Record<string, any> | ArrayLike<unknown>) => {}; | ||
declare const removeEmpty: (obj: Record<string, any> | Array<unknown>) => {}; | ||
declare const pick: <T, K extends keyof T>(obj: T, keys: K[]) => Pick<T, K>; | ||
@@ -18,4 +36,5 @@ declare const resolverArgs: (...args: any[]) => string; | ||
declare const omit: <T extends object, K extends keyof T>(obj: T, keys: K[]) => Omit<T, K>; | ||
declare const orderBy: (arr: any, props: any[], orders: Record<string, string>) => void; | ||
declare const pluck: (arr: any[], key: string | number) => any[]; | ||
declare const orderBy: <T extends Object, K extends keyof T>(arr: T[], props: K[], orders: Record<string, string>) => void; | ||
declare const pipe: (...fns: any[]) => (input: any) => any; | ||
declare const pluck: <T, K extends keyof T>(arr: any[], key: keyof K) => any[]; | ||
declare const renameKeys: (keysMap: Record<string, any>, obj: Record<string, any>) => void; | ||
@@ -25,7 +44,7 @@ declare const objectArrayToArray: (objectArray: Array<unknown>, attr: string) => Array<unknown>; | ||
declare const autoParseValues: (val: string) => string | number | boolean; | ||
declare const flattenDeep: (arr: any[]) => any[]; | ||
declare const difference: (a: any[], b: any[]) => any[]; | ||
declare const common: (a: any[], b: any[]) => any[]; | ||
declare const flattenDeep: (arr: unknown[]) => unknown[]; | ||
declare const difference: (a: unknown[], b: unknown[]) => unknown[]; | ||
declare const common: (a: unknown[], b: unknown[]) => unknown[]; | ||
declare const capitalize: (str: string) => string; | ||
declare const debounce: (func: Function, wait: number, immediate?: boolean) => (this: any) => void; | ||
declare const debounce: (options: IDebounceOptions) => (this: any) => void; | ||
declare const timeTaken: (callback: Function) => number; | ||
@@ -39,12 +58,6 @@ declare const unescapeHTML: (str: string) => string; | ||
declare const isDate: (dateString: string) => boolean; | ||
declare const dropRight: (arr: any[], n?: number) => any[]; | ||
declare const encrypt: (text: string, config: { | ||
key: string; | ||
iv: string; | ||
}) => string; | ||
declare const dropRight: (arr: unknown[], n?: number) => unknown[]; | ||
declare const encrypt: (options: IEncryptOptions) => string; | ||
declare const enumToString: (_enum: Record<any, any>) => string[]; | ||
declare const decrypt: (encrypted: string, config: { | ||
key: string; | ||
iv: string; | ||
}) => string; | ||
declare const decrypt: (options: IEncryptOptions) => string; | ||
declare const readFile: (path: string) => Promise<unknown>; | ||
@@ -56,3 +69,3 @@ declare const randomNumber: (a?: number, b?: number) => number; | ||
declare const strBefore: (str: string, substr: string) => string; | ||
declare const isNotEmpty: (value: any) => boolean; | ||
declare const isNotEmpty: (value: unknown) => boolean; | ||
declare const clone: <T extends { | ||
@@ -63,4 +76,4 @@ constructor: Function; | ||
declare const shuffle: <T>(array: T[]) => T[]; | ||
declare const normalizeEmail: (email: string) => any; | ||
declare const slugify: (str: string, options?: ISlugifyOptions) => string; | ||
declare const normalizeEmail: (email: string) => string; | ||
declare const slugify: (str: string, options: ISlugifyOptions) => string; | ||
declare const clearUndefined: <T extends Record<string, any>>(obj: T) => T; | ||
@@ -73,8 +86,8 @@ declare const slash: (str: string) => string; | ||
declare const template: (str: any, mix: Record<string, any>) => any; | ||
declare function randomString(length: number, symbols?: boolean, numbers?: boolean): string; | ||
declare function randomString(options: IRandomStringOptions): string; | ||
declare const composeAsync: (...fns: any[]) => (input: any) => any; | ||
declare const intersection: (a: any[], b: any[]) => any[]; | ||
declare const intersection: (a: any[], b: any[]) => unknown[]; | ||
declare const isSameDate: (dateA: Date, dateB: Date) => boolean; | ||
declare const dropWhile: (arr: string | any[], func: (arg0: any) => any) => string | any[]; | ||
declare const drop: (arr: string | any[], n?: number) => string | any[]; | ||
declare const dropWhile: (arr: string | unknown[], func: (arg0: any) => any) => string | unknown[]; | ||
declare const drop: (arr: string | unknown[], n?: number) => string | unknown[]; | ||
@@ -88,2 +101,2 @@ declare const isDef: <T = any>(val?: T | undefined) => val is T; | ||
export { assert, autoParseValues, capitalize, capitalizeEveryWord, clearUndefined, clone, common, composeAsync, debounce, decrypt, difference, drop, dropRight, dropWhile, encrypt, ensurePrefix, enumToString, fixedDecimal, flattenDeep, formatDuration, generateRandomString, groupBy, intersection, invertObj, isBoolean, isDate, isDef, isEmpty, isFunction, isNotEmpty, isNumber, isObject, isSameDate, isString, lowerFirst, noop, normalizeEmail, objectArrayToArray, omit, orderBy, orderedToken, pick, pluck, randomHex, randomNumber, randomString, readFile, removeEmpty, renameKeys, resolverArgs, shuffle, slash, slugify, strAfter, strBefore, stringifyQueryParams, sumOfAnArray, template, throttle, timeTaken, toString, unescapeHTML, union, unique }; | ||
export { assert, autoParseValues, capitalize, capitalizeEveryWord, clearUndefined, clone, common, composeAsync, debounce, decrypt, difference, drop, dropRight, dropWhile, encrypt, ensurePrefix, enumToString, fixedDecimal, flattenDeep, formatDuration, generateRandomString, groupBy, intersection, invertObj, isBoolean, isDate, isDef, isEmpty, isFunction, isNotEmpty, isNumber, isObject, isSameDate, isString, lowerFirst, noop, normalizeEmail, objectArrayToArray, omit, orderBy, orderedToken, pick, pipe, pluck, randomHex, randomNumber, randomString, readFile, removeEmpty, renameKeys, resolverArgs, shuffle, slash, slugify, strAfter, strBefore, stringifyQueryParams, sumOfAnArray, template, throttle, timeTaken, toString, unescapeHTML, union, unique }; |
@@ -1,1 +0,1 @@ | ||
var d=(t,e)=>{if(!t)throw new Error(e)},l=t=>Object.prototype.toString.call(t),h=()=>{};import p from"crypto";import g from"fs";var f=/\./g,y=t=>[Object,Array].includes((t||{}).constructor)&&!Object.entries(t||{}).length,S=t=>Object.entries(t).reduce((e,[n,r])=>r===null?e:{...e,[n]:r},{}),O=(t,e)=>{let n={};return e.forEach(r=>{n[r]=t[r]}),n},A=(...t)=>JSON.stringify(t),k=(t,e=0)=>t.reduce((n,r)=>n+r,e),M=t=>[...new Set(t)],R=(t,e)=>{let n={...t};return e.forEach(r=>delete n[r]),n},E=(t,e,n)=>{[...t].sort((r,o)=>e.reduce((s,i,a)=>{if(s===0){let[c,u]=n&&n[a]==="desc"?[o[i],r[i]]:[r[i],o[i]];s=c>u?1:c<u?-1:0}return s},0))};var N=(t,e)=>t.map(n=>n[e]),D=(t,e)=>{Object.keys(e).reduce((n,r)=>({...n,[t[r]||r]:e[r]}),{})},F=(t,e)=>t.map(n=>n[e]),j=(t,e=2)=>{let n=new RegExp(`^-?\\d+(?:.\\d{0,${e||-1}})?`);return parseFloat(t.toString().match(n)[0])},v=t=>!!JSON.parse(t)===JSON.parse(t)?JSON.parse(t.toLowerCase()):isNaN(Number(t))?t:parseFloat(t),C=t=>t.flat(1/0),m=(t,e)=>t.filter(n=>!e.includes(n)),L=(t,e)=>t.filter(n=>e.includes(n)),I=t=>t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"",K=(t,e,n)=>{let r;return function(){let o=this,s=arguments,i=function(){r=null,n||t.apply(o,s)},a=n&&!r;clearTimeout(r),r=setTimeout(i,e),a&&t.apply(o,s)}},P=t=>{console.time("timeTaken");let e=t();return console.timeEnd("timeTaken"),e},B=t=>t.replace(/&|<|>|'|"/g,e=>({"&":"&","<":"<",">":">","'":"'",""":'"'})[e]||e),z=(t,e)=>{let n=null,r=null,o=void 0,s=()=>{t.apply(o,r),n=null};return function(){n||(r=arguments,n=setTimeout(s,e))}},$=t=>{t<0&&(t=-t);let e={day:Math.floor(t/864e5),hour:Math.floor(t/36e5)%24,minute:Math.floor(t/6e4)%60,second:Math.floor(t/1e3)%60,millisecond:Math.floor(t)%1e3};return Object.entries(e).filter(n=>n[1]!==0).map(([n,r])=>`${r} ${n}${r!==1?"s":""}`).join(", ")},J=t=>t.replace(/\b[a-z]/g,e=>e.toUpperCase()),U=t=>t?t.charAt(0).toLowerCase()+t.slice(1):"",q=(t,e,n=!0)=>n?Array.from([...t,...e]):Array.from(new Set([...t,...e])),V=t=>new Date(t)instanceof Date,W=(t,e=1)=>t.slice(0,-e),_=(t,e)=>{let n=Buffer.from(e.key,"hex"),r=Buffer.from(e.iv,"hex"),o=p.createCipheriv("aes-256-cbc",n,r),s=o.update(t,"utf8","base64");return s+=o.final("base64"),s},G=t=>Object.keys(t).map(e=>t[e]).filter(e=>typeof e=="string"),H=(t,e)=>{let n=Buffer.from(e.key,"hex"),r=Buffer.from(e.iv,"hex"),o=p.createDecipheriv("aes-256-cbc",n,r);return o.update(t,"base64","utf8")+o.final("utf8")},X=t=>new Promise((e,n)=>{g.readFile(t,{encoding:"utf-8"},(r,o)=>{r?n(r):e(o)})}),x=(t=1,e=9)=>{let n=Math.ceil(Math.min(t,e)),r=Math.floor(Math.max(t,e));return Math.floor(n+Math.random()*(r-n+1))},Y=t=>[...Array(t)].map(()=>Math.floor(Math.random()*16).toString(16)).join(""),Q=(t,e="X")=>{for(;t.includes(e);)t=t.replace(e,String(x()));return t},Z=(t,e)=>t.split(e)[1],tt=(t,e)=>t.split(e)[0],et=t=>!y(t),nt=t=>{let e=new t.constructor;return Object.assign(e,t),e},rt=(t,e)=>t.reduce((n,r)=>(n[r[e]]||(n[r[e]]=[]),n[r[e]].push(r),n),{}),ot=t=>{let e=t.length;for(;e>0;){let n=Math.floor(Math.random()*e--),r=t[e];t[e]=t[n],t[n]=r}return t},st=t=>{let[e,n]=t.split("@"),[r]=e.split("+");r=r.replace(f,"");let o=`${r.toLowerCase()}@${n.toLowerCase()}`;return Number(o),o},it=(t,e={lowercase:!0,separator:"-",trim:!0})=>{let n=t.toString().normalize("NFD").replace(/[\u0300-\u036F]/g,"");return e.lowercase&&n.toLowerCase(),e.trim&&n.trim(),n.replace(/[^a-z0-9 -]/g,"").replace(/\s+/g,e.separator)},at=t=>(Object.keys(t).forEach(e=>t[e]===void 0?delete t[e]:{}),t),ct=t=>t.replace(/\\/g,"/"),ut=(t,e)=>e.startsWith(t)?e:t+e,lt=t=>{let e={};for(let n in t)t.hasOwnProperty(n)&&(e[t[n]]=n);return e},pt=(t={})=>new URLSearchParams(t).toString(),gt=(t=6)=>Math.random().toString(20).substr(2,t),ft=(t,e)=>{let n=/{{(.*?)}}/g;return t.replace(n,(r,o,s)=>{for(r=0,s=e,o=o.trim().split(".");s&&r<o.length;)s=s[o[r++]];return s??""})};function yt(t,e=!1,n=!1){let r="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",o="0123456789",s="!@#$%^&*_-+=",i=r;n&&(i+=o),e&&(i+=s);let a="";for(let c=0;c<t;c++)a+=i.charAt(Math.floor(Math.random()*i.length));return a}var mt=(...t)=>e=>t.reduceRight((n,r)=>n.then(r),Promise.resolve(e)),xt=(t,e)=>m(t,e),dt=(t,e)=>t.toISOString()===e.toISOString(),ht=(t,e)=>{for(;t.length>0&&!e(t[0]);)t=t.slice(1);return t},bt=(t,e=1)=>t.slice(e);var St=t=>typeof t<"u",Ot=t=>typeof t=="boolean",At=t=>typeof t=="function",kt=t=>typeof t=="number",Mt=t=>typeof t=="string",Rt=t=>l(t)==="[object Object]";export{d as assert,v as autoParseValues,I as capitalize,J as capitalizeEveryWord,at as clearUndefined,nt as clone,L as common,mt as composeAsync,K as debounce,H as decrypt,m as difference,bt as drop,W as dropRight,ht as dropWhile,_ as encrypt,ut as ensurePrefix,G as enumToString,j as fixedDecimal,C as flattenDeep,$ as formatDuration,gt as generateRandomString,rt as groupBy,xt as intersection,lt as invertObj,Ot as isBoolean,V as isDate,St as isDef,y as isEmpty,At as isFunction,et as isNotEmpty,kt as isNumber,Rt as isObject,dt as isSameDate,Mt as isString,U as lowerFirst,h as noop,st as normalizeEmail,F as objectArrayToArray,R as omit,E as orderBy,Q as orderedToken,O as pick,N as pluck,Y as randomHex,x as randomNumber,yt as randomString,X as readFile,S as removeEmpty,D as renameKeys,A as resolverArgs,ot as shuffle,ct as slash,it as slugify,Z as strAfter,tt as strBefore,pt as stringifyQueryParams,k as sumOfAnArray,ft as template,z as throttle,P as timeTaken,l as toString,B as unescapeHTML,q as union,M as unique}; | ||
var d=(t,e)=>{if(!t)throw new Error(e)},u=t=>Object.prototype.toString.call(t),h=()=>{};import p from"crypto";import g from"fs";var f=/\./g,m=t=>[Object,Array].includes((t||{}).constructor)&&!Object.entries(t||{}).length,k=t=>Object.entries(t).reduce((e,[n,r])=>r===null?e:{...e,[n]:r},{}),O=(t,e)=>{let n={};return e.forEach(r=>{n[r]=t[r]}),n},S=(...t)=>JSON.stringify(t),A=(t,e=0)=>t.reduce((n,r)=>n+r,e),R=t=>[...new Set(t)],E=(t,e)=>{let n={...t};return e.forEach(r=>delete n[r]),n},M=(t,e,n)=>{[...t].sort((r,o)=>e.reduce((s,i,l)=>{if(s===0){let[c,a]=n&&n[l]==="desc"?[o[i],r[i]]:[r[i],o[i]];s=c>a?1:c<a?-1:0}return s},0))},I=(...t)=>e=>t.reduce((n,r)=>r(n),e),N=(t,e)=>t.map(n=>n[e]),D=(t,e)=>{Object.keys(e).reduce((n,r)=>({...n,[t[r]||r]:e[r]}),{})},j=(t,e)=>t.map(n=>n[e]),K=(t,e=2)=>{let n=new RegExp(`^-?\\d+(?:.\\d{0,${e||-1}})?`);return parseFloat(t.toString().match(n)[0])},F=t=>!!JSON.parse(t)===JSON.parse(t)?JSON.parse(t.toLowerCase()):isNaN(Number(t))?t:parseFloat(t),C=t=>t.flat(1/0),x=(t,e)=>t.filter(n=>!e.includes(n)),L=(t,e)=>t.filter(n=>e.includes(n)),v=t=>t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"",P=t=>{let e;return function(){let n=this,r=arguments,o=function(){e=null,t.immediate||t.func.apply(n,r)},s=t.immediate&&!e;clearTimeout(e),e=setTimeout(o,t.wait),s&&t.func.apply(n,r)}},B=t=>{console.time("timeTaken");let e=t();return console.timeEnd("timeTaken"),e},z=t=>t.replace(/&|<|>|'|"/g,e=>({"&":"&","<":"<",">":">","'":"'",""":'"'})[e]||e),$=(t,e)=>{let n=null,r=null,o=void 0,s=()=>{t.apply(o,r),n=null};return function(){n||(r=arguments,n=setTimeout(s,e))}},J=t=>{t<0&&(t=-t);let e={day:Math.floor(t/864e5),hour:Math.floor(t/36e5)%24,minute:Math.floor(t/6e4)%60,second:Math.floor(t/1e3)%60,millisecond:Math.floor(t)%1e3};return Object.entries(e).filter(n=>n[1]!==0).map(([n,r])=>`${r} ${n}${r!==1?"s":""}`).join(", ")},U=t=>t.replace(/\b[a-z]/g,e=>e.toUpperCase()),q=t=>t?t.charAt(0).toLowerCase()+t.slice(1):"",V=(t,e,n=!0)=>n?Array.from([...t,...e]):Array.from(new Set([...t,...e])),W=t=>new Date(t)instanceof Date,_=(t,e=1)=>t.slice(0,-e),G=t=>{let e=Buffer.from(t.config.key,"hex"),n=Buffer.from(t.config.iv,"hex"),r=p.createCipheriv("aes-256-cbc",e,n),o=r.update(t.text,"utf8","base64");return o+=r.final("base64"),o},H=t=>Object.keys(t).map(e=>t[e]).filter(e=>typeof e=="string"),X=t=>{let e=Buffer.from(t.config.key,"hex"),n=Buffer.from(t.config.iv,"hex"),r=p.createDecipheriv("aes-256-cbc",e,n);return r.update(t.text,"base64","utf8")+r.final("utf8")},Y=t=>new Promise((e,n)=>{g.readFile(t,{encoding:"utf-8"},(r,o)=>{r?n(r):e(o)})}),y=(t=1,e=9)=>{let n=Math.ceil(Math.min(t,e)),r=Math.floor(Math.max(t,e));return Math.floor(n+Math.random()*(r-n+1))},Q=t=>[...Array(t)].map(()=>Math.floor(Math.random()*16).toString(16)).join(""),Z=(t,e="X")=>{for(;t.includes(e);)t=t.replace(e,String(y()));return t},tt=(t,e)=>t.split(e)[1],et=(t,e)=>t.split(e)[0],nt=t=>!m(t),rt=t=>{let e=new t.constructor;return Object.assign(e,t),e},ot=(t,e)=>t.reduce((n,r)=>(n[r[e]]||(n[r[e]]=[]),n[r[e]].push(r),n),{}),st=t=>{let e=t.length;for(;e>0;){let n=Math.floor(Math.random()*e--),r=t[e];t[e]=t[n],t[n]=r}return t},it=t=>{let[e,n]=t.split("@"),[r]=e.split("+");r=r.replace(f,"");let o=`${r.toLowerCase()}@${n.toLowerCase()}`;return Number(o),o},ct=(t,e)=>{e={lowercase:!0,separator:"-",trim:!0,...e};let n=t.toString().normalize("NFD").replace(/[\u0300-\u036F]/g,"");return e.lowercase&&n.toLowerCase(),e.trim&&n.trim(),n.replace(/[^a-z0-9 -]/g,"").replace(/\s+/g,e.separator)},at=t=>(Object.keys(t).forEach(e=>t[e]===void 0?delete t[e]:{}),t),ut=t=>t.replace(/\\/g,"/"),pt=(t,e)=>e.startsWith(t)?e:t+e,lt=t=>{let e={};for(let n in t)t.hasOwnProperty(n)&&(e[t[n]]=n);return e},gt=(t={})=>new URLSearchParams(t).toString(),ft=(t=6)=>Math.random().toString(20).substr(2,t),mt=(t,e)=>{let n=/{{(.*?)}}/g;return t.replace(n,(r,o,s)=>{for(r=0,s=e,o=o.trim().split(".");s&&r<o.length;)s=s[o[r++]];return s??""})};function xt(t){let e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",n="0123456789",r="!@#$%^&*_-+=",o=e;t.numbers&&(o+=n),t.symbols&&(o+=r);let s="";for(let i=0;i<t.length;i++)s+=o.charAt(Math.floor(Math.random()*o.length));return s}var yt=(...t)=>e=>t.reduceRight((n,r)=>n.then(r),Promise.resolve(e)),dt=(t,e)=>x(t,e),ht=(t,e)=>t.toISOString()===e.toISOString(),bt=(t,e)=>{for(;t.length>0&&!e(t[0]);)t=t.slice(1);return t},wt=(t,e=1)=>t.slice(e);var Ot=t=>typeof t<"u",St=t=>typeof t=="boolean",At=t=>typeof t=="function",Rt=t=>typeof t=="number",Et=t=>typeof t=="string",Mt=t=>u(t)==="[object Object]";export{d as assert,F as autoParseValues,v as capitalize,U as capitalizeEveryWord,at as clearUndefined,rt as clone,L as common,yt as composeAsync,P as debounce,X as decrypt,x as difference,wt as drop,_ as dropRight,bt as dropWhile,G as encrypt,pt as ensurePrefix,H as enumToString,K as fixedDecimal,C as flattenDeep,J as formatDuration,ft as generateRandomString,ot as groupBy,dt as intersection,lt as invertObj,St as isBoolean,W as isDate,Ot as isDef,m as isEmpty,At as isFunction,nt as isNotEmpty,Rt as isNumber,Mt as isObject,ht as isSameDate,Et as isString,q as lowerFirst,h as noop,it as normalizeEmail,j as objectArrayToArray,E as omit,M as orderBy,Z as orderedToken,O as pick,I as pipe,N as pluck,Q as randomHex,y as randomNumber,xt as randomString,Y as readFile,k as removeEmpty,D as renameKeys,S as resolverArgs,st as shuffle,ut as slash,ct as slugify,tt as strAfter,et as strBefore,gt as stringifyQueryParams,A as sumOfAnArray,mt as template,$ as throttle,B as timeTaken,u as toString,z as unescapeHTML,V as union,R as unique}; |
{ | ||
"name": "helper-fns", | ||
"type": "module", | ||
"version": "2.5.20", | ||
"version": "2.5.22", | ||
"packageManager": "pnpm@7.2.1", | ||
@@ -6,0 +6,0 @@ "description": "Some common utilities functions for everyday backend usage with zero dependencies", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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.
Found 1 instance in 1 package
27692
143
0