@zthun/helpful-fn 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import{v4 as n}from"uuid";var t,i;function r(n,t,i,r){if(void 0===i&&(i=0),void 0===r&&(r=Infinity),n=Math.max(0,n),t=Math.max(0,t),Number.isNaN(n)||Number.isNaN(t))return NaN;if(0===t)return i;var u=Infinity===n?1:Math.ceil(t/n);return Math.min(r,Math.max(i,u))}!function(n){n.Top="top",n.Middle="middle",n.Bottom="bottom"}(t||(t={})),function(n){n.Left="left",n.Center="center",n.Right="right"}(i||(i={}));var u=n;function e(n,t){var i=[].slice.call(arguments,2);if(null!=t)return t;for(var r=0;r<i.length;++r){var u=i[r];if(null!=u)return u}return n}function l(n){return[].slice.call(arguments,1).map(function(n){return n instanceof Array?n[1]?n[0]:null:n}).filter(function(n){return null!=n}).join(n)}var o,a=l.bind(null," "),f=a,c=l.bind(null,","),d=l.bind(null,";"),m=l.bind(null,"|");function v(n,t,i){n(null!=i&&i.length?i[0]:t)}function h(n,t){return void 0===n&&(n=0),void 0===t&&(t=void 0),new Promise(function(i){return setTimeout(function(){return i(t)},n)})}!function(n){n.Horizontal="horizontal",n.Vertical="vertical"}(o||(o={}));export{i as ZHorizontalAnchor,o as ZOrientation,t as ZVerticalAnchor,c as commaJoinDefined,r as countBuckets,u as createGuid,f as cssJoinDefined,e as firstDefined,l as joinDefined,m as pipeJoinDefined,d as semiColonJoinDefined,v as setFirst,h as sleep,a as spaceJoinDefined};
1
+ import{v4 as n}from"uuid";var r,t;function i(n,r,t,i){if(void 0===t&&(t=0),void 0===i&&(i=Infinity),n=Math.max(0,n),r=Math.max(0,r),Number.isNaN(n)||Number.isNaN(r))return NaN;if(0===r)return t;var e=Infinity===n?1:Math.ceil(r/n);return Math.min(i,Math.max(t,e))}function e(n,r){if(void 0===r&&(r=["message","error","exception"]),n instanceof Error)return n;if(null==n)return new Error;for(var t=0;t<r.length;++t){var i=r[t];if(Object.prototype.hasOwnProperty.call(n,i))return e(n[i])}return new Error(String(n))}!function(n){n.Top="top",n.Middle="middle",n.Bottom="bottom"}(r||(r={})),function(n){n.Left="left",n.Center="center",n.Right="right"}(t||(t={}));var o=n;function u(n,r){var t=[].slice.call(arguments,2);if(null!=r)return r;for(var i=0;i<t.length;++i){var e=t[i];if(null!=e)return e}return n}function l(n){return[].slice.call(arguments,1).map(function(n){return n instanceof Array?n[1]?n[0]:null:n}).filter(function(n){return null!=n}).join(n)}var a,f=l.bind(null," "),c=f,v=l.bind(null,","),d=l.bind(null,";"),m=l.bind(null,"|");function h(n,r,t){n(null!=t&&t.length?t[0]:r)}function s(n,r){return void 0===n&&(n=0),void 0===r&&(r=void 0),new Promise(function(t){return setTimeout(function(){return t(r)},n)})}!function(n){n.Horizontal="horizontal",n.Vertical="vertical"}(a||(a={}));export{t as ZHorizontalAnchor,a as ZOrientation,r as ZVerticalAnchor,v as commaJoinDefined,i as countBuckets,e as createError,o as createGuid,c as cssJoinDefined,u as firstDefined,l as joinDefined,m as pipeJoinDefined,d as semiColonJoinDefined,h as setFirst,s as sleep,f as spaceJoinDefined};
2
2
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../../src/anchor/anchor.ts","../../src/count-buckets/count-buckets.ts","../../src/create-guid/create-guid.ts","../../src/first-defined/first-defined.ts","../../src/join-defined/join-defined.ts","../../src/orientation/orientation.ts","../../src/set-first/set-first.ts","../../src/sleep/sleep.ts"],"sourcesContent":["/**\n * Represents a vertical anchor.\n */\nexport enum ZVerticalAnchor {\n /**\n * Top boundary.\n */\n Top = 'top',\n /**\n * Centerpoint between the top and bottom.\n */\n Middle = 'middle',\n /**\n * Bottom boundary.\n */\n Bottom = 'bottom'\n}\n\nexport enum ZHorizontalAnchor {\n /**\n * Left boundary.\n */\n Left = 'left',\n /**\n * Centerpoint between the left and right boundary.\n */\n Center = 'center',\n /**\n * Right boundary.\n */\n Right = 'right'\n}\n\n/**\n * Represents an anchor point.\n *\n * An anchor point is a point that stays constant while things are\n * resizing.\n */\nexport type ZAnchor = [ZVerticalAnchor, ZHorizontalAnchor];\n\n/**\n * Represents a special type of anchor that excludes the center points.\n */\nexport type ZSideAnchor =\n | ZVerticalAnchor.Top\n | ZVerticalAnchor.Bottom\n | ZHorizontalAnchor.Left\n | ZHorizontalAnchor.Right;\n","/**\n * Calculates the total number of buckets you need to\n * store a number of items where each bucket can hold a\n * maximum weight of items.\n *\n * You can use this function to calculate groupings of\n * items based on total counts and sizes. A good example\n * usage would be to calculate the total number of pages\n * on a paginated list of items given a page size and item\n * count.\n *\n * @param weight -\n * The maximum weight a bucket can store.\n * @param items -\n * The total number of items you need to store where each item\n * counts as 1 towards the weight.\n * @param min -\n * The bounded minimum value. If the total number of buckets\n * evaluates to less than this value, then this value is returned.\n * @param max -\n * The bounded maximum value. If the total number of buckets\n * evaluates to more than this value, then this value is returned.\n *\n * @returns\n * The number of buckets you need to store the total number\n * of items given that a single bucket can hold a max weight of items.\n * If either weight or items is NaN, then NaN will be returned regardless\n * of the opposite value. Passing a negative number is the same as\n * passing 0.\n */\nexport function countBuckets(weight: number, items: number, min = 0, max = Infinity) {\n weight = Math.max(0, weight);\n items = Math.max(0, items);\n\n if (Number.isNaN(weight) || Number.isNaN(items)) {\n return NaN;\n }\n\n if (items === 0) {\n return min;\n }\n\n const boxes = weight === Infinity ? 1 : Math.ceil(items / weight);\n return Math.min(max, Math.max(min, boxes));\n}\n","import { v4 } from 'uuid';\n\n/**\n * Creates a globally unique identifier.\n *\n * @returns\n * A new generated globally unique identifier.\n */\nexport const createGuid: () => string = v4;\n","/**\n * Returns the first value in args such that args is not null or undefined.\n *\n * @param fallback -\n * The fallback value in the case that all values in args are null/undefined.\n * @param first -\n * The first value to check.\n * @param remaining -\n * The remaining values beyond the first to check.\n *\n * @returns\n * The first value if it is not null or undefined. If first is undefined or null, then the first item\n * in remaining such that remaining[i] is not null or undefined is returned. If first and all values of\n * remaining are null or undefined, then fallback is returned.\n */\nexport function firstDefined<T = any>(\n fallback: T,\n first: T | null | undefined,\n ...remaining: (T | null | undefined)[]\n): T {\n if (first != null) {\n return first;\n }\n\n for (let i = 0; i < remaining.length; ++i) {\n const val = remaining[i];\n\n if (val != null) {\n return val;\n }\n }\n\n return fallback;\n}\n","export type JoinListInputParameter<T> = T | [T, boolean] | null | undefined;\n\n/**\n * Similar to a string join, but filters out null and undefined items.\n *\n * @param delimiter -\n * The delimiter that separates the items.\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by delimiter.\n */\nexport function joinDefined<T>(delimiter: string, ...items: JoinListInputParameter<T>[]) {\n return items\n .map((item) => (item instanceof Array ? (item[1] ? item[0] : null) : item))\n .filter((item) => item != null)\n .join(delimiter);\n}\n\n/**\n * Alias to joinList with a string delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by space delimiter.\n */\nexport const spaceJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ' ');\n\n/**\n * Alias of spaceJoinList.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a space delimiter.\n */\nexport const cssJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = spaceJoinDefined;\n\n/**\n * Alias of joinList with a comma delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a comma delimiter.\n */\nexport const commaJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ',');\n\n/**\n * Alias of joinList with a semi-colon delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a semi-colon delimiter.\n */\nexport const semiColonJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ';');\n\n/**\n * Alias of joinList with a pipe delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a pipe delimiter.\n */\nexport const pipeJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, '|');\n","/**\n * Represents a direction orientation.\n */\nexport enum ZOrientation {\n /**\n * Row orientation.\n *\n * This type of orientation is a row\n * style orientation or flex-row orientation.\n */\n Horizontal = 'horizontal',\n\n /**\n * Vertical orientation.\n *\n * This type of orientation is a column\n * style orientation or block orientation.\n */\n Vertical = 'vertical'\n}\n","/**\n * Represents a setter function for when you want to set a single value, but you have an array instead.\n *\n * This is useful when you want to support lists of items, but you need\n * backwards compatibility for setting a single item.\n *\n * @param setValue -\n * The setter function that takes a single value.\n * @param fallback -\n * The fallback value in the case that there are no values.\n * @param value -\n * The value list to retrieve the first item from.\n */\nexport function setFirst<T>(setValue: (val: T) => any, fallback: T, value: T[] | null | undefined) {\n const _value = value?.length ? value[0] : fallback;\n setValue(_value);\n}\n","/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep(ms?: number): Promise<void>;\n\n/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n * @param val -\n * The value to resolve with.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep<T>(ms: number, val: T): Promise<T>;\n\n/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep<T>(ms = 0, val: T | undefined = undefined): Promise<T | undefined> {\n return new Promise<T | undefined>((resolve) => setTimeout(() => resolve(val), ms));\n}\n"],"names":["ZVerticalAnchor","ZHorizontalAnchor","countBuckets","weight","items","min","max","Infinity","Math","Number","isNaN","NaN","boxes","ceil","createGuid","v4","firstDefined","fallback","first","remaining","slice","call","arguments","i","length","val","joinDefined","delimiter","map","item","Array","filter","join","ZOrientation","spaceJoinDefined","bind","cssJoinDefined","commaJoinDefined","semiColonJoinDefined","pipeJoinDefined","setFirst","setValue","value","sleep","ms","undefined","Promise","resolve","setTimeout"],"mappings":"0BAGY,IAAAA,EAeAC,ECYI,SAAAC,EAAaC,EAAgBC,EAAeC,EAASC,GAInE,QAJ6D,IAAHD,IAAAA,EAAM,QAAM,IAAHC,IAAAA,EAAMC,UACzEJ,EAASK,KAAKF,IAAI,EAAGH,GACrBC,EAAQI,KAAKF,IAAI,EAAGF,GAEhBK,OAAOC,MAAMP,IAAWM,OAAOC,MAAMN,GACvC,OAAOO,IAGT,GAAc,IAAVP,EACF,OAAOC,EAGT,IAAMO,EAAmBL,WAAXJ,EAAsB,EAAIK,KAAKK,KAAKT,EAAQD,GAC1D,OAAOK,KAAKH,IAAIC,EAAKE,KAAKF,IAAID,EAAKO,GACrC,EDzCA,SAAYZ,GAIVA,EAAA,IAAA,MAIAA,EAAA,OAAA,SAIAA,EAAA,OAAA,QACD,CAbD,CAAYA,IAAAA,EAaX,KAED,SAAYC,GAIVA,EAAA,KAAA,OAIAA,EAAA,OAAA,SAIAA,EAAA,MAAA,OACD,CAbD,CAAYA,IAAAA,EAaX,CAAA,IEvBY,IAAAa,EAA2BC,ECOxB,SAAAC,EACdC,EACAC,GACG,IAAAC,EAAmC,GAAAC,MAAAC,KAAAC,UAEtC,GAAA,GAAa,MAATJ,EACF,OAAOA,EAGT,IAAK,IAAIK,EAAI,EAAGA,EAAIJ,EAAUK,SAAUD,EAAG,CACzC,IAAME,EAAMN,EAAUI,GAEtB,GAAW,MAAPE,EACF,OAAOA,CAEV,CAED,OAAOR,CACT,UCpBgBS,EAAeC,GAC7B,MAAO,GAAAP,MAAAC,KAAAC,UACJM,GAAAA,IAAI,SAACC,GAAI,OAAMA,aAAgBC,MAASD,EAAK,GAAKA,EAAK,GAAK,KAAQA,CAAI,GACxEE,OAAO,SAACF,GAAI,OAAa,MAARA,CAAY,GAC7BG,KAAKL,EACV,CAWa,IC1BDM,ED0BCC,EAAyER,EAAYS,KAAK,KAAM,KAWhGC,EAAuEF,EAWvEG,EAAyEX,EAAYS,KAAK,KAAM,KAWhGG,EAA6EZ,EAAYS,KAAK,KAAM,KAWpGI,EAAwEb,EAAYS,KAAK,KAAM,KE5D5F,SAAAK,EAAYC,EAA2BxB,EAAayB,GAElED,EADoB,MAALC,GAAAA,EAAOlB,OAASkB,EAAM,GAAKzB,EAE5C,UCiBgB0B,EAASC,EAAQnB,GAC/B,YADyB,IAAFmB,IAAAA,EAAK,YAAGnB,IAAAA,OAAqBoB,OACzCC,QAAuB,SAACC,UAAYC,WAAW,WAAM,OAAAD,EAAQtB,EAAI,EAAEmB,EAAG,EACnF,EFhCA,SAAYX,GAOVA,EAAA,WAAA,aAQAA,EAAA,SAAA,UACD,CAhBD,CAAYA,IAAAA,EAgBX,CAAA"}
1
+ {"version":3,"file":"index.esm.js","sources":["../../src/anchor/anchor.ts","../../src/count-buckets/count-buckets.ts","../../src/create-error/create-error.ts","../../src/create-guid/create-guid.ts","../../src/first-defined/first-defined.ts","../../src/join-defined/join-defined.ts","../../src/orientation/orientation.ts","../../src/set-first/set-first.ts","../../src/sleep/sleep.ts"],"sourcesContent":["/**\n * Represents a vertical anchor.\n */\nexport enum ZVerticalAnchor {\n /**\n * Top boundary.\n */\n Top = 'top',\n /**\n * Centerpoint between the top and bottom.\n */\n Middle = 'middle',\n /**\n * Bottom boundary.\n */\n Bottom = 'bottom'\n}\n\nexport enum ZHorizontalAnchor {\n /**\n * Left boundary.\n */\n Left = 'left',\n /**\n * Centerpoint between the left and right boundary.\n */\n Center = 'center',\n /**\n * Right boundary.\n */\n Right = 'right'\n}\n\n/**\n * Represents an anchor point.\n *\n * An anchor point is a point that stays constant while things are\n * resizing.\n */\nexport type ZAnchor = [ZVerticalAnchor, ZHorizontalAnchor];\n\n/**\n * Represents a special type of anchor that excludes the center points.\n */\nexport type ZSideAnchor =\n | ZVerticalAnchor.Top\n | ZVerticalAnchor.Bottom\n | ZHorizontalAnchor.Left\n | ZHorizontalAnchor.Right;\n","/**\n * Calculates the total number of buckets you need to\n * store a number of items where each bucket can hold a\n * maximum weight of items.\n *\n * You can use this function to calculate groupings of\n * items based on total counts and sizes. A good example\n * usage would be to calculate the total number of pages\n * on a paginated list of items given a page size and item\n * count.\n *\n * @param weight -\n * The maximum weight a bucket can store.\n * @param items -\n * The total number of items you need to store where each item\n * counts as 1 towards the weight.\n * @param min -\n * The bounded minimum value. If the total number of buckets\n * evaluates to less than this value, then this value is returned.\n * @param max -\n * The bounded maximum value. If the total number of buckets\n * evaluates to more than this value, then this value is returned.\n *\n * @returns\n * The number of buckets you need to store the total number\n * of items given that a single bucket can hold a max weight of items.\n * If either weight or items is NaN, then NaN will be returned regardless\n * of the opposite value. Passing a negative number is the same as\n * passing 0.\n */\nexport function countBuckets(weight: number, items: number, min = 0, max = Infinity) {\n weight = Math.max(0, weight);\n items = Math.max(0, items);\n\n if (Number.isNaN(weight) || Number.isNaN(items)) {\n return NaN;\n }\n\n if (items === 0) {\n return min;\n }\n\n const boxes = weight === Infinity ? 1 : Math.ceil(items / weight);\n return Math.min(max, Math.max(min, boxes));\n}\n","/**\n * A helper method to construct a JavaScript error object given a list of acceptable schema keys.\n *\n * @param problem -\n * A generic representation of the problem that occurred. This can be an Error object,\n * another object representing some kind of error, or some message representing the error.\n * If this is null or undefined, then a generic error is returned.\n * @param schema -\n * The list of acceptable object keys to look into problem. These will be recursively\n * evaluated to strip out the real error message. Note that this is in order of\n * priority. If schema[0] and schema[1] are both keys on problem, then schema[0] takes\n * a higher precedence than schema[1].\n *\n * @returns\n * An error object that is the best evaluation of what the problem actually is.\n */\nexport function createError(problem: any, schema = ['message', 'error', 'exception']): Error {\n if (problem instanceof Error) {\n return problem;\n }\n\n if (problem == null) {\n return new Error();\n }\n\n for (let i = 0; i < schema.length; ++i) {\n const key = schema[i];\n\n if (Object.prototype.hasOwnProperty.call(problem, key)) {\n return createError(problem[key]);\n }\n }\n\n return new Error(String(problem));\n}\n","import { v4 } from 'uuid';\n\n/**\n * Creates a globally unique identifier.\n *\n * @returns\n * A new generated globally unique identifier.\n */\nexport const createGuid: () => string = v4;\n","/**\n * Returns the first value in args such that args is not null or undefined.\n *\n * @param fallback -\n * The fallback value in the case that all values in args are null/undefined.\n * @param first -\n * The first value to check.\n * @param remaining -\n * The remaining values beyond the first to check.\n *\n * @returns\n * The first value if it is not null or undefined. If first is undefined or null, then the first item\n * in remaining such that remaining[i] is not null or undefined is returned. If first and all values of\n * remaining are null or undefined, then fallback is returned.\n */\nexport function firstDefined<T = any>(\n fallback: T,\n first: T | null | undefined,\n ...remaining: (T | null | undefined)[]\n): T {\n if (first != null) {\n return first;\n }\n\n for (let i = 0; i < remaining.length; ++i) {\n const val = remaining[i];\n\n if (val != null) {\n return val;\n }\n }\n\n return fallback;\n}\n","export type JoinListInputParameter<T> = T | [T, boolean] | null | undefined;\n\n/**\n * Similar to a string join, but filters out null and undefined items.\n *\n * @param delimiter -\n * The delimiter that separates the items.\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by delimiter.\n */\nexport function joinDefined<T>(delimiter: string, ...items: JoinListInputParameter<T>[]) {\n return items\n .map((item) => (item instanceof Array ? (item[1] ? item[0] : null) : item))\n .filter((item) => item != null)\n .join(delimiter);\n}\n\n/**\n * Alias to joinList with a string delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by space delimiter.\n */\nexport const spaceJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ' ');\n\n/**\n * Alias of spaceJoinList.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a space delimiter.\n */\nexport const cssJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = spaceJoinDefined;\n\n/**\n * Alias of joinList with a comma delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a comma delimiter.\n */\nexport const commaJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ',');\n\n/**\n * Alias of joinList with a semi-colon delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a semi-colon delimiter.\n */\nexport const semiColonJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ';');\n\n/**\n * Alias of joinList with a pipe delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a pipe delimiter.\n */\nexport const pipeJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, '|');\n","/**\n * Represents a direction orientation.\n */\nexport enum ZOrientation {\n /**\n * Row orientation.\n *\n * This type of orientation is a row\n * style orientation or flex-row orientation.\n */\n Horizontal = 'horizontal',\n\n /**\n * Vertical orientation.\n *\n * This type of orientation is a column\n * style orientation or block orientation.\n */\n Vertical = 'vertical'\n}\n","/**\n * Represents a setter function for when you want to set a single value, but you have an array instead.\n *\n * This is useful when you want to support lists of items, but you need\n * backwards compatibility for setting a single item.\n *\n * @param setValue -\n * The setter function that takes a single value.\n * @param fallback -\n * The fallback value in the case that there are no values.\n * @param value -\n * The value list to retrieve the first item from.\n */\nexport function setFirst<T>(setValue: (val: T) => any, fallback: T, value: T[] | null | undefined) {\n const _value = value?.length ? value[0] : fallback;\n setValue(_value);\n}\n","/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep(ms?: number): Promise<void>;\n\n/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n * @param val -\n * The value to resolve with.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep<T>(ms: number, val: T): Promise<T>;\n\n/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep<T>(ms = 0, val: T | undefined = undefined): Promise<T | undefined> {\n return new Promise<T | undefined>((resolve) => setTimeout(() => resolve(val), ms));\n}\n"],"names":["ZVerticalAnchor","ZHorizontalAnchor","countBuckets","weight","items","min","max","Infinity","Math","Number","isNaN","NaN","boxes","ceil","createError","problem","schema","Error","i","length","key","Object","prototype","hasOwnProperty","call","String","createGuid","v4","firstDefined","fallback","first","remaining","slice","arguments","val","joinDefined","delimiter","map","item","Array","filter","join","ZOrientation","spaceJoinDefined","bind","cssJoinDefined","commaJoinDefined","semiColonJoinDefined","pipeJoinDefined","setFirst","setValue","value","sleep","ms","undefined","Promise","resolve","setTimeout"],"mappings":"0BAGY,IAAAA,EAeAC,ECYI,SAAAC,EAAaC,EAAgBC,EAAeC,EAASC,GAInE,QAJ6D,IAAHD,IAAAA,EAAM,QAAM,IAAHC,IAAAA,EAAMC,UACzEJ,EAASK,KAAKF,IAAI,EAAGH,GACrBC,EAAQI,KAAKF,IAAI,EAAGF,GAEhBK,OAAOC,MAAMP,IAAWM,OAAOC,MAAMN,GACvC,OAAOO,IAGT,GAAc,IAAVP,EACF,OAAOC,EAGT,IAAMO,EAAmBL,WAAXJ,EAAsB,EAAIK,KAAKK,KAAKT,EAAQD,GAC1D,OAAOK,KAAKH,IAAIC,EAAKE,KAAKF,IAAID,EAAKO,GACrC,CC5BgB,SAAAE,EAAYC,EAAcC,GACxC,QAD8C,IAANA,IAAAA,EAAS,CAAC,UAAW,QAAS,cAClED,aAAmBE,MACrB,OAAOF,EAGT,GAAe,MAAXA,EACF,OAAW,IAAAE,MAGb,IAAK,IAAIC,EAAI,EAAGA,EAAIF,EAAOG,SAAUD,EAAG,CACtC,IAAME,EAAMJ,EAAOE,GAEnB,GAAIG,OAAOC,UAAUC,eAAeC,KAAKT,EAASK,GAChD,OAAON,EAAYC,EAAQK,GAE9B,CAED,OAAO,IAAIH,MAAMQ,OAAOV,GAC1B,EF/BA,SAAYf,GAIVA,EAAA,IAAA,MAIAA,EAAA,OAAA,SAIAA,EAAA,OAAA,QACD,CAbD,CAAYA,IAAAA,EAaX,KAED,SAAYC,GAIVA,EAAA,KAAA,OAIAA,EAAA,OAAA,SAIAA,EAAA,MAAA,OACD,CAbD,CAAYA,IAAAA,EAaX,CAAA,IGvBY,IAAAyB,EAA2BC,ECOxB,SAAAC,EACdC,EACAC,GACG,IAAAC,EAAmC,GAAAC,MAAAR,KAAAS,UAEtC,GAAA,GAAa,MAATH,EACF,OAAOA,EAGT,IAAK,IAAIZ,EAAI,EAAGA,EAAIa,EAAUZ,SAAUD,EAAG,CACzC,IAAMgB,EAAMH,EAAUb,GAEtB,GAAW,MAAPgB,EACF,OAAOA,CAEV,CAED,OAAOL,CACT,UCpBgBM,EAAeC,GAC7B,MAAO,GAAAJ,MAAAR,KAAAS,UACJI,GAAAA,IAAI,SAACC,GAAI,OAAMA,aAAgBC,MAASD,EAAK,GAAKA,EAAK,GAAK,KAAQA,CAAI,GACxEE,OAAO,SAACF,GAAI,OAAa,MAARA,CAAY,GAC7BG,KAAKL,EACV,CAWa,IC1BDM,ED0BCC,EAAyER,EAAYS,KAAK,KAAM,KAWhGC,EAAuEF,EAWvEG,EAAyEX,EAAYS,KAAK,KAAM,KAWhGG,EAA6EZ,EAAYS,KAAK,KAAM,KAWpGI,EAAwEb,EAAYS,KAAK,KAAM,KE5D5F,SAAAK,EAAYC,EAA2BrB,EAAasB,GAElED,EADoB,MAALC,GAAAA,EAAOhC,OAASgC,EAAM,GAAKtB,EAE5C,UCiBgBuB,EAASC,EAAQnB,GAC/B,YADyB,IAAFmB,IAAAA,EAAK,YAAGnB,IAAAA,OAAqBoB,OACzCC,QAAuB,SAACC,UAAYC,WAAW,WAAM,OAAAD,EAAQtB,EAAI,EAAEmB,EAAG,EACnF,EFhCA,SAAYX,GAOVA,EAAA,WAAA,aAQAA,EAAA,SAAA,UACD,CAhBD,CAAYA,IAAAA,EAgBX,CAAA"}
package/dist/lib/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var n,t,e=require("uuid");exports.ZVerticalAnchor=void 0,(n=exports.ZVerticalAnchor||(exports.ZVerticalAnchor={})).Top="top",n.Middle="middle",n.Bottom="bottom",exports.ZHorizontalAnchor=void 0,(t=exports.ZHorizontalAnchor||(exports.ZHorizontalAnchor={})).Left="left",t.Center="center",t.Right="right";var r=e.v4;function i(n){return[].slice.call(arguments,1).map(function(n){return n instanceof Array?n[1]?n[0]:null:n}).filter(function(n){return null!=n}).join(n)}var o,l=i.bind(null," "),a=l,u=i.bind(null,","),s=i.bind(null,";"),c=i.bind(null,"|");exports.ZOrientation=void 0,(o=exports.ZOrientation||(exports.ZOrientation={})).Horizontal="horizontal",o.Vertical="vertical",exports.commaJoinDefined=u,exports.countBuckets=function(n,t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=Infinity),n=Math.max(0,n),t=Math.max(0,t),Number.isNaN(n)||Number.isNaN(t))return NaN;if(0===t)return e;var i=Infinity===n?1:Math.ceil(t/n);return Math.min(r,Math.max(e,i))},exports.createGuid=r,exports.cssJoinDefined=a,exports.firstDefined=function(n,t){var e=[].slice.call(arguments,2);if(null!=t)return t;for(var r=0;r<e.length;++r){var i=e[r];if(null!=i)return i}return n},exports.joinDefined=i,exports.pipeJoinDefined=c,exports.semiColonJoinDefined=s,exports.setFirst=function(n,t,e){n(null!=e&&e.length?e[0]:t)},exports.sleep=function(n,t){return void 0===n&&(n=0),void 0===t&&(t=void 0),new Promise(function(e){return setTimeout(function(){return e(t)},n)})},exports.spaceJoinDefined=l;
1
+ var r,e,n=require("uuid");exports.ZVerticalAnchor=void 0,(r=exports.ZVerticalAnchor||(exports.ZVerticalAnchor={})).Top="top",r.Middle="middle",r.Bottom="bottom",exports.ZHorizontalAnchor=void 0,(e=exports.ZHorizontalAnchor||(exports.ZHorizontalAnchor={})).Left="left",e.Center="center",e.Right="right";var t=n.v4;function o(r){return[].slice.call(arguments,1).map(function(r){return r instanceof Array?r[1]?r[0]:null:r}).filter(function(r){return null!=r}).join(r)}var i,l=o.bind(null," "),a=l,u=o.bind(null,","),s=o.bind(null,";"),c=o.bind(null,"|");exports.ZOrientation=void 0,(i=exports.ZOrientation||(exports.ZOrientation={})).Horizontal="horizontal",i.Vertical="vertical",exports.commaJoinDefined=u,exports.countBuckets=function(r,e,n,t){if(void 0===n&&(n=0),void 0===t&&(t=Infinity),r=Math.max(0,r),e=Math.max(0,e),Number.isNaN(r)||Number.isNaN(e))return NaN;if(0===e)return n;var o=Infinity===r?1:Math.ceil(e/r);return Math.min(t,Math.max(n,o))},exports.createError=function r(e,n){if(void 0===n&&(n=["message","error","exception"]),e instanceof Error)return e;if(null==e)return new Error;for(var t=0;t<n.length;++t){var o=n[t];if(Object.prototype.hasOwnProperty.call(e,o))return r(e[o])}return new Error(String(e))},exports.createGuid=t,exports.cssJoinDefined=a,exports.firstDefined=function(r,e){var n=[].slice.call(arguments,2);if(null!=e)return e;for(var t=0;t<n.length;++t){var o=n[t];if(null!=o)return o}return r},exports.joinDefined=o,exports.pipeJoinDefined=c,exports.semiColonJoinDefined=s,exports.setFirst=function(r,e,n){r(null!=n&&n.length?n[0]:e)},exports.sleep=function(r,e){return void 0===r&&(r=0),void 0===e&&(e=void 0),new Promise(function(n){return setTimeout(function(){return n(e)},r)})},exports.spaceJoinDefined=l;
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/anchor/anchor.ts","../../src/create-guid/create-guid.ts","../../src/join-defined/join-defined.ts","../../src/orientation/orientation.ts","../../src/count-buckets/count-buckets.ts","../../src/first-defined/first-defined.ts","../../src/set-first/set-first.ts","../../src/sleep/sleep.ts"],"sourcesContent":["/**\n * Represents a vertical anchor.\n */\nexport enum ZVerticalAnchor {\n /**\n * Top boundary.\n */\n Top = 'top',\n /**\n * Centerpoint between the top and bottom.\n */\n Middle = 'middle',\n /**\n * Bottom boundary.\n */\n Bottom = 'bottom'\n}\n\nexport enum ZHorizontalAnchor {\n /**\n * Left boundary.\n */\n Left = 'left',\n /**\n * Centerpoint between the left and right boundary.\n */\n Center = 'center',\n /**\n * Right boundary.\n */\n Right = 'right'\n}\n\n/**\n * Represents an anchor point.\n *\n * An anchor point is a point that stays constant while things are\n * resizing.\n */\nexport type ZAnchor = [ZVerticalAnchor, ZHorizontalAnchor];\n\n/**\n * Represents a special type of anchor that excludes the center points.\n */\nexport type ZSideAnchor =\n | ZVerticalAnchor.Top\n | ZVerticalAnchor.Bottom\n | ZHorizontalAnchor.Left\n | ZHorizontalAnchor.Right;\n","import { v4 } from 'uuid';\n\n/**\n * Creates a globally unique identifier.\n *\n * @returns\n * A new generated globally unique identifier.\n */\nexport const createGuid: () => string = v4;\n","export type JoinListInputParameter<T> = T | [T, boolean] | null | undefined;\n\n/**\n * Similar to a string join, but filters out null and undefined items.\n *\n * @param delimiter -\n * The delimiter that separates the items.\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by delimiter.\n */\nexport function joinDefined<T>(delimiter: string, ...items: JoinListInputParameter<T>[]) {\n return items\n .map((item) => (item instanceof Array ? (item[1] ? item[0] : null) : item))\n .filter((item) => item != null)\n .join(delimiter);\n}\n\n/**\n * Alias to joinList with a string delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by space delimiter.\n */\nexport const spaceJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ' ');\n\n/**\n * Alias of spaceJoinList.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a space delimiter.\n */\nexport const cssJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = spaceJoinDefined;\n\n/**\n * Alias of joinList with a comma delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a comma delimiter.\n */\nexport const commaJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ',');\n\n/**\n * Alias of joinList with a semi-colon delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a semi-colon delimiter.\n */\nexport const semiColonJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ';');\n\n/**\n * Alias of joinList with a pipe delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a pipe delimiter.\n */\nexport const pipeJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, '|');\n","/**\n * Represents a direction orientation.\n */\nexport enum ZOrientation {\n /**\n * Row orientation.\n *\n * This type of orientation is a row\n * style orientation or flex-row orientation.\n */\n Horizontal = 'horizontal',\n\n /**\n * Vertical orientation.\n *\n * This type of orientation is a column\n * style orientation or block orientation.\n */\n Vertical = 'vertical'\n}\n","/**\n * Calculates the total number of buckets you need to\n * store a number of items where each bucket can hold a\n * maximum weight of items.\n *\n * You can use this function to calculate groupings of\n * items based on total counts and sizes. A good example\n * usage would be to calculate the total number of pages\n * on a paginated list of items given a page size and item\n * count.\n *\n * @param weight -\n * The maximum weight a bucket can store.\n * @param items -\n * The total number of items you need to store where each item\n * counts as 1 towards the weight.\n * @param min -\n * The bounded minimum value. If the total number of buckets\n * evaluates to less than this value, then this value is returned.\n * @param max -\n * The bounded maximum value. If the total number of buckets\n * evaluates to more than this value, then this value is returned.\n *\n * @returns\n * The number of buckets you need to store the total number\n * of items given that a single bucket can hold a max weight of items.\n * If either weight or items is NaN, then NaN will be returned regardless\n * of the opposite value. Passing a negative number is the same as\n * passing 0.\n */\nexport function countBuckets(weight: number, items: number, min = 0, max = Infinity) {\n weight = Math.max(0, weight);\n items = Math.max(0, items);\n\n if (Number.isNaN(weight) || Number.isNaN(items)) {\n return NaN;\n }\n\n if (items === 0) {\n return min;\n }\n\n const boxes = weight === Infinity ? 1 : Math.ceil(items / weight);\n return Math.min(max, Math.max(min, boxes));\n}\n","/**\n * Returns the first value in args such that args is not null or undefined.\n *\n * @param fallback -\n * The fallback value in the case that all values in args are null/undefined.\n * @param first -\n * The first value to check.\n * @param remaining -\n * The remaining values beyond the first to check.\n *\n * @returns\n * The first value if it is not null or undefined. If first is undefined or null, then the first item\n * in remaining such that remaining[i] is not null or undefined is returned. If first and all values of\n * remaining are null or undefined, then fallback is returned.\n */\nexport function firstDefined<T = any>(\n fallback: T,\n first: T | null | undefined,\n ...remaining: (T | null | undefined)[]\n): T {\n if (first != null) {\n return first;\n }\n\n for (let i = 0; i < remaining.length; ++i) {\n const val = remaining[i];\n\n if (val != null) {\n return val;\n }\n }\n\n return fallback;\n}\n","/**\n * Represents a setter function for when you want to set a single value, but you have an array instead.\n *\n * This is useful when you want to support lists of items, but you need\n * backwards compatibility for setting a single item.\n *\n * @param setValue -\n * The setter function that takes a single value.\n * @param fallback -\n * The fallback value in the case that there are no values.\n * @param value -\n * The value list to retrieve the first item from.\n */\nexport function setFirst<T>(setValue: (val: T) => any, fallback: T, value: T[] | null | undefined) {\n const _value = value?.length ? value[0] : fallback;\n setValue(_value);\n}\n","/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep(ms?: number): Promise<void>;\n\n/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n * @param val -\n * The value to resolve with.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep<T>(ms: number, val: T): Promise<T>;\n\n/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep<T>(ms = 0, val: T | undefined = undefined): Promise<T | undefined> {\n return new Promise<T | undefined>((resolve) => setTimeout(() => resolve(val), ms));\n}\n"],"names":["ZVerticalAnchor","ZHorizontalAnchor","createGuid","v4","joinDefined","delimiter","slice","call","arguments","map","item","Array","filter","join","ZOrientation","spaceJoinDefined","bind","cssJoinDefined","commaJoinDefined","semiColonJoinDefined","pipeJoinDefined","weight","items","min","max","Infinity","Math","Number","isNaN","NaN","boxes","ceil","fallback","first","remaining","i","length","val","setValue","value","ms","undefined","Promise","resolve","setTimeout"],"mappings":"IAGYA,EAeAC,oBAfAD,QAAAA,qBAAAA,GAAAA,EAAAA,QAAeA,kBAAfA,QAAeA,gBAa1B,KATC,IAAA,MAIAA,EAAA,OAAA,SAIAA,EAAA,OAAA,SAGUC,QAAAA,uBAAAA,GAAAA,EAAAA,4BAAAA,QAAAA,kBAaX,CAAA,IATC,KAAA,OAIAA,EAAA,OAAA,SAIAA,EAAA,MAAA,QCtBW,IAAAC,EAA2BC,EAAAA,YCKxBC,EAAeC,GAC7B,MAAO,GAAAC,MAAAC,KAAAC,UACJC,GAAAA,IAAI,SAACC,GAAI,OAAMA,aAAgBC,MAASD,EAAK,GAAKA,EAAK,GAAK,KAAQA,CAAI,GACxEE,OAAO,SAACF,GAAI,OAAa,MAARA,CAAY,GAC7BG,KAAKR,EACV,CAWa,IC1BDS,ED0BCC,EAAyEX,EAAYY,KAAK,KAAM,KAWhGC,EAAuEF,EAWvEG,EAAyEd,EAAYY,KAAK,KAAM,KAWhGG,EAA6Ef,EAAYY,KAAK,KAAM,KAWpGI,EAAwEhB,EAAYY,KAAK,KAAM,KCtEhGF,QAAZA,kBAAA,GAAYA,EAAAA,QAAYA,eAAZA,QAAYA,aAgBvB,CAAA,IATC,WAAA,aAQAA,EAAA,SAAA,2DCYc,SAAaO,EAAgBC,EAAeC,EAASC,GAInE,QAJ6D,IAAHD,IAAAA,EAAM,QAAM,IAAHC,IAAAA,EAAMC,UACzEJ,EAASK,KAAKF,IAAI,EAAGH,GACrBC,EAAQI,KAAKF,IAAI,EAAGF,GAEhBK,OAAOC,MAAMP,IAAWM,OAAOC,MAAMN,GACvC,OAAOO,IAGT,GAAc,IAAVP,EACF,OAAOC,EAGT,IAAMO,EAAmBL,WAAXJ,EAAsB,EAAIK,KAAKK,KAAKT,EAAQD,GAC1D,OAAOK,KAAKH,IAAIC,EAAKE,KAAKF,IAAID,EAAKO,GACrC,qEC7BgB,SACdE,EACAC,GACG,IAAAC,EAAmC,GAAA5B,MAAAC,KAAAC,UAEtC,GAAA,GAAa,MAATyB,EACF,OAAOA,EAGT,IAAK,IAAIE,EAAI,EAAGA,EAAID,EAAUE,SAAUD,EAAG,CACzC,IAAME,EAAMH,EAAUC,GAEtB,GAAW,MAAPE,EACF,OAAOA,CAEV,CAED,OAAOL,CACT,kGCpBgB,SAAYM,EAA2BN,EAAaO,GAElED,EADoB,MAALC,GAAAA,EAAOH,OAASG,EAAM,GAAKP,EAE5C,yBCiByBQ,EAAQH,GAC/B,YADyB,IAAFG,IAAAA,EAAK,YAAGH,IAAAA,OAAqBI,OACzCC,QAAuB,SAACC,UAAYC,WAAW,WAAM,OAAAD,EAAQN,EAAI,EAAEG,EAAG,EACnF"}
1
+ {"version":3,"file":"index.js","sources":["../../src/anchor/anchor.ts","../../src/create-guid/create-guid.ts","../../src/join-defined/join-defined.ts","../../src/orientation/orientation.ts","../../src/count-buckets/count-buckets.ts","../../src/create-error/create-error.ts","../../src/first-defined/first-defined.ts","../../src/set-first/set-first.ts","../../src/sleep/sleep.ts"],"sourcesContent":["/**\n * Represents a vertical anchor.\n */\nexport enum ZVerticalAnchor {\n /**\n * Top boundary.\n */\n Top = 'top',\n /**\n * Centerpoint between the top and bottom.\n */\n Middle = 'middle',\n /**\n * Bottom boundary.\n */\n Bottom = 'bottom'\n}\n\nexport enum ZHorizontalAnchor {\n /**\n * Left boundary.\n */\n Left = 'left',\n /**\n * Centerpoint between the left and right boundary.\n */\n Center = 'center',\n /**\n * Right boundary.\n */\n Right = 'right'\n}\n\n/**\n * Represents an anchor point.\n *\n * An anchor point is a point that stays constant while things are\n * resizing.\n */\nexport type ZAnchor = [ZVerticalAnchor, ZHorizontalAnchor];\n\n/**\n * Represents a special type of anchor that excludes the center points.\n */\nexport type ZSideAnchor =\n | ZVerticalAnchor.Top\n | ZVerticalAnchor.Bottom\n | ZHorizontalAnchor.Left\n | ZHorizontalAnchor.Right;\n","import { v4 } from 'uuid';\n\n/**\n * Creates a globally unique identifier.\n *\n * @returns\n * A new generated globally unique identifier.\n */\nexport const createGuid: () => string = v4;\n","export type JoinListInputParameter<T> = T | [T, boolean] | null | undefined;\n\n/**\n * Similar to a string join, but filters out null and undefined items.\n *\n * @param delimiter -\n * The delimiter that separates the items.\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by delimiter.\n */\nexport function joinDefined<T>(delimiter: string, ...items: JoinListInputParameter<T>[]) {\n return items\n .map((item) => (item instanceof Array ? (item[1] ? item[0] : null) : item))\n .filter((item) => item != null)\n .join(delimiter);\n}\n\n/**\n * Alias to joinList with a string delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by space delimiter.\n */\nexport const spaceJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ' ');\n\n/**\n * Alias of spaceJoinList.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a space delimiter.\n */\nexport const cssJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = spaceJoinDefined;\n\n/**\n * Alias of joinList with a comma delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a comma delimiter.\n */\nexport const commaJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ',');\n\n/**\n * Alias of joinList with a semi-colon delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a semi-colon delimiter.\n */\nexport const semiColonJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ';');\n\n/**\n * Alias of joinList with a pipe delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a pipe delimiter.\n */\nexport const pipeJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, '|');\n","/**\n * Represents a direction orientation.\n */\nexport enum ZOrientation {\n /**\n * Row orientation.\n *\n * This type of orientation is a row\n * style orientation or flex-row orientation.\n */\n Horizontal = 'horizontal',\n\n /**\n * Vertical orientation.\n *\n * This type of orientation is a column\n * style orientation or block orientation.\n */\n Vertical = 'vertical'\n}\n","/**\n * Calculates the total number of buckets you need to\n * store a number of items where each bucket can hold a\n * maximum weight of items.\n *\n * You can use this function to calculate groupings of\n * items based on total counts and sizes. A good example\n * usage would be to calculate the total number of pages\n * on a paginated list of items given a page size and item\n * count.\n *\n * @param weight -\n * The maximum weight a bucket can store.\n * @param items -\n * The total number of items you need to store where each item\n * counts as 1 towards the weight.\n * @param min -\n * The bounded minimum value. If the total number of buckets\n * evaluates to less than this value, then this value is returned.\n * @param max -\n * The bounded maximum value. If the total number of buckets\n * evaluates to more than this value, then this value is returned.\n *\n * @returns\n * The number of buckets you need to store the total number\n * of items given that a single bucket can hold a max weight of items.\n * If either weight or items is NaN, then NaN will be returned regardless\n * of the opposite value. Passing a negative number is the same as\n * passing 0.\n */\nexport function countBuckets(weight: number, items: number, min = 0, max = Infinity) {\n weight = Math.max(0, weight);\n items = Math.max(0, items);\n\n if (Number.isNaN(weight) || Number.isNaN(items)) {\n return NaN;\n }\n\n if (items === 0) {\n return min;\n }\n\n const boxes = weight === Infinity ? 1 : Math.ceil(items / weight);\n return Math.min(max, Math.max(min, boxes));\n}\n","/**\n * A helper method to construct a JavaScript error object given a list of acceptable schema keys.\n *\n * @param problem -\n * A generic representation of the problem that occurred. This can be an Error object,\n * another object representing some kind of error, or some message representing the error.\n * If this is null or undefined, then a generic error is returned.\n * @param schema -\n * The list of acceptable object keys to look into problem. These will be recursively\n * evaluated to strip out the real error message. Note that this is in order of\n * priority. If schema[0] and schema[1] are both keys on problem, then schema[0] takes\n * a higher precedence than schema[1].\n *\n * @returns\n * An error object that is the best evaluation of what the problem actually is.\n */\nexport function createError(problem: any, schema = ['message', 'error', 'exception']): Error {\n if (problem instanceof Error) {\n return problem;\n }\n\n if (problem == null) {\n return new Error();\n }\n\n for (let i = 0; i < schema.length; ++i) {\n const key = schema[i];\n\n if (Object.prototype.hasOwnProperty.call(problem, key)) {\n return createError(problem[key]);\n }\n }\n\n return new Error(String(problem));\n}\n","/**\n * Returns the first value in args such that args is not null or undefined.\n *\n * @param fallback -\n * The fallback value in the case that all values in args are null/undefined.\n * @param first -\n * The first value to check.\n * @param remaining -\n * The remaining values beyond the first to check.\n *\n * @returns\n * The first value if it is not null or undefined. If first is undefined or null, then the first item\n * in remaining such that remaining[i] is not null or undefined is returned. If first and all values of\n * remaining are null or undefined, then fallback is returned.\n */\nexport function firstDefined<T = any>(\n fallback: T,\n first: T | null | undefined,\n ...remaining: (T | null | undefined)[]\n): T {\n if (first != null) {\n return first;\n }\n\n for (let i = 0; i < remaining.length; ++i) {\n const val = remaining[i];\n\n if (val != null) {\n return val;\n }\n }\n\n return fallback;\n}\n","/**\n * Represents a setter function for when you want to set a single value, but you have an array instead.\n *\n * This is useful when you want to support lists of items, but you need\n * backwards compatibility for setting a single item.\n *\n * @param setValue -\n * The setter function that takes a single value.\n * @param fallback -\n * The fallback value in the case that there are no values.\n * @param value -\n * The value list to retrieve the first item from.\n */\nexport function setFirst<T>(setValue: (val: T) => any, fallback: T, value: T[] | null | undefined) {\n const _value = value?.length ? value[0] : fallback;\n setValue(_value);\n}\n","/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep(ms?: number): Promise<void>;\n\n/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n * @param val -\n * The value to resolve with.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep<T>(ms: number, val: T): Promise<T>;\n\n/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep<T>(ms = 0, val: T | undefined = undefined): Promise<T | undefined> {\n return new Promise<T | undefined>((resolve) => setTimeout(() => resolve(val), ms));\n}\n"],"names":["ZVerticalAnchor","ZHorizontalAnchor","createGuid","v4","joinDefined","delimiter","slice","call","arguments","map","item","Array","filter","join","ZOrientation","spaceJoinDefined","bind","cssJoinDefined","commaJoinDefined","semiColonJoinDefined","pipeJoinDefined","weight","items","min","max","Infinity","Math","Number","isNaN","NaN","boxes","ceil","createError","problem","schema","Error","i","length","key","Object","prototype","hasOwnProperty","String","fallback","first","remaining","val","setValue","value","ms","undefined","Promise","resolve","setTimeout"],"mappings":"IAGYA,EAeAC,oBAfAD,QAAAA,qBAAAA,GAAAA,EAAAA,QAAeA,kBAAfA,QAAeA,gBAa1B,KATC,IAAA,MAIAA,EAAA,OAAA,SAIAA,EAAA,OAAA,SAGUC,QAAAA,uBAAAA,GAAAA,EAAAA,4BAAAA,QAAAA,kBAaX,CAAA,IATC,KAAA,OAIAA,EAAA,OAAA,SAIAA,EAAA,MAAA,QCtBW,IAAAC,EAA2BC,EAAAA,YCKxBC,EAAeC,GAC7B,MAAO,GAAAC,MAAAC,KAAAC,UACJC,GAAAA,IAAI,SAACC,GAAI,OAAMA,aAAgBC,MAASD,EAAK,GAAKA,EAAK,GAAK,KAAQA,CAAI,GACxEE,OAAO,SAACF,GAAI,OAAa,MAARA,CAAY,GAC7BG,KAAKR,EACV,CAWa,IC1BDS,ED0BCC,EAAyEX,EAAYY,KAAK,KAAM,KAWhGC,EAAuEF,EAWvEG,EAAyEd,EAAYY,KAAK,KAAM,KAWhGG,EAA6Ef,EAAYY,KAAK,KAAM,KAWpGI,EAAwEhB,EAAYY,KAAK,KAAM,KCtEhGF,QAAZA,kBAAA,GAAYA,EAAAA,QAAYA,eAAZA,QAAYA,aAgBvB,CAAA,IATC,WAAA,aAQAA,EAAA,SAAA,2DCYc,SAAaO,EAAgBC,EAAeC,EAASC,GAInE,QAJ6D,IAAHD,IAAAA,EAAM,QAAM,IAAHC,IAAAA,EAAMC,UACzEJ,EAASK,KAAKF,IAAI,EAAGH,GACrBC,EAAQI,KAAKF,IAAI,EAAGF,GAEhBK,OAAOC,MAAMP,IAAWM,OAAOC,MAAMN,GACvC,OAAOO,IAGT,GAAc,IAAVP,EACF,OAAOC,EAGT,IAAMO,EAAmBL,WAAXJ,EAAsB,EAAIK,KAAKK,KAAKT,EAAQD,GAC1D,OAAOK,KAAKH,IAAIC,EAAKE,KAAKF,IAAID,EAAKO,GACrC,sBC5BgB,SAAAE,EAAYC,EAAcC,GACxC,QAD8C,IAANA,IAAAA,EAAS,CAAC,UAAW,QAAS,cAClED,aAAmBE,MACrB,OAAOF,EAGT,GAAe,MAAXA,EACF,OAAW,IAAAE,MAGb,IAAK,IAAIC,EAAI,EAAGA,EAAIF,EAAOG,SAAUD,EAAG,CACtC,IAAME,EAAMJ,EAAOE,GAEnB,GAAIG,OAAOC,UAAUC,eAAelC,KAAK0B,EAASK,GAChD,OAAON,EAAYC,EAAQK,GAE9B,CAED,OAAO,IAAIH,MAAMO,OAAOT,GAC1B,qECnBgB,SACdU,EACAC,GACG,IAAAC,EAAmC,GAAAvC,MAAAC,KAAAC,UAEtC,GAAA,GAAa,MAAToC,EACF,OAAOA,EAGT,IAAK,IAAIR,EAAI,EAAGA,EAAIS,EAAUR,SAAUD,EAAG,CACzC,IAAMU,EAAMD,EAAUT,GAEtB,GAAW,MAAPU,EACF,OAAOA,CAEV,CAED,OAAOH,CACT,kGCpBgB,SAAYI,EAA2BJ,EAAaK,GAElED,EADoB,MAALC,GAAAA,EAAOX,OAASW,EAAM,GAAKL,EAE5C,yBCiByBM,EAAQH,GAC/B,YADyB,IAAFG,IAAAA,EAAK,YAAGH,IAAAA,OAAqBI,OACzCC,QAAuB,SAACC,UAAYC,WAAW,WAAM,OAAAD,EAAQN,EAAI,EAAEG,EAAG,EACnF"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * A helper method to construct a JavaScript error object given a list of acceptable schema keys.
3
+ *
4
+ * @param problem -
5
+ * A generic representation of the problem that occurred. This can be an Error object,
6
+ * another object representing some kind of error, or some message representing the error.
7
+ * If this is null or undefined, then a generic error is returned.
8
+ * @param schema -
9
+ * The list of acceptable object keys to look into problem. These will be recursively
10
+ * evaluated to strip out the real error message. Note that this is in order of
11
+ * priority. If schema[0] and schema[1] are both keys on problem, then schema[0] takes
12
+ * a higher precedence than schema[1].
13
+ *
14
+ * @returns
15
+ * An error object that is the best evaluation of what the problem actually is.
16
+ */
17
+ export declare function createError(problem: any, schema?: string[]): Error;
@@ -1,5 +1,6 @@
1
1
  export * from './anchor/anchor';
2
2
  export * from './count-buckets/count-buckets';
3
+ export * from './create-error/create-error';
3
4
  export * from './create-guid/create-guid';
4
5
  export * from './first-defined/first-defined';
5
6
  export * from './join-defined/join-defined';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zthun/helpful-fn",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Helpful, isolated pure functions that are not found in other libraries such as lodash.",
5
5
  "author": "Anthony Bonta",
6
6
  "license": "MIT",
@@ -30,5 +30,5 @@
30
30
  "dist"
31
31
  ],
32
32
  "sideEffects": false,
33
- "gitHead": "86fa3dbe37e74477f5b75315298a3980824292b7"
33
+ "gitHead": "cf7997a20c329ac00b57967ec42120df4b4081b4"
34
34
  }