@zthun/helpful-fn 4.0.2 → 4.0.3
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.
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -376,7 +376,7 @@ const _ZTrilean = class _ZTrilean {
|
|
|
376
376
|
* and indeterminate if x is null.
|
|
377
377
|
*/
|
|
378
378
|
static stringify(x) {
|
|
379
|
-
return _ZTrilean.isIndeterminate(x) ?
|
|
379
|
+
return _ZTrilean.isIndeterminate(x) ? "indeterminate" : String(x);
|
|
380
380
|
}
|
|
381
381
|
/**
|
|
382
382
|
* Converts a string to a trilean value.
|
|
@@ -453,7 +453,7 @@ const _ZTrilean = class _ZTrilean {
|
|
|
453
453
|
return !!val;
|
|
454
454
|
}
|
|
455
455
|
};
|
|
456
|
-
_ZTrilean.Indeterminate = Symbol("indeterminate");
|
|
456
|
+
_ZTrilean.Indeterminate = Symbol("helpful-fn-indeterminate");
|
|
457
457
|
let ZTrilean = _ZTrilean;
|
|
458
458
|
class ZDeserializeJson {
|
|
459
459
|
constructor(_schema) {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/anchor/anchor.mts","../src/assert/assert.mts","../src/count-buckets/count-buckets.mts","../src/create-error/create-error.mts","../src/create-guid/create-guid.mts","../src/first-where/first-where.mts","../src/geometry/quadrilateral.mts","../src/geometry/rectangle.mts","../src/global/global.mts","../src/join-defined/join-defined.mts","../src/obligation/obligation.mts","../src/orientation/orientation.mts","../src/peel/peel.mts","../src/schema/trilean.mts","../src/serialize/deserialize-json.mts","../src/serialize/deserialize-try.mts","../src/serialize/serialize-json.mts","../src/set-first/set-first.mts","../src/sleep/sleep.mts","../src/tag/tag.mts","../src/try-fallback/try-fallback.mts"],"sourcesContent":["/**\n * Represents a targeted point along a y axis.\n */\nexport enum ZVerticalAnchor {\n /**\n * Top boundary.\n *\n * In vertical device space, this would equate to y = 0.\n */\n Top = 'top',\n /**\n * Centerpoint between the top and bottom.\n */\n Middle = 'middle',\n /**\n * Bottom boundary.\n *\n * In vertical device space, this would equate to y = Infinity.\n */\n Bottom = 'bottom'\n}\n\n/**\n * Represents a targeted point along an x axis.\n */\nexport enum ZHorizontalAnchor {\n /**\n * Left boundary.\n *\n * In horizontal device space, this would equate to x = 0.\n */\n Left = 'left',\n /**\n * Centerpoint between the left and right boundary.\n */\n Center = 'center',\n /**\n * Right boundary.\n *\n * In horizontal device space, this would equate to x = Infinity.\n */\n Right = 'right'\n}\n\n/**\n * Represents an anchor point in 2d space.\n *\n * An anchor array is defined by [vertical, horizontal]\n * and is read as such.\n *\n * @example\n *\n * ```ts\n * const topCenter = [ZVerticalAnchor.Top, ZHorizontalAnchor.Center];\n * const bottomRight = [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Right];\n * ```\n *\n * @see {@link ZVerticalAnchor} For more information.\n * @see {@link ZHorizontalAnchor} For more information.\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 * Represents an object that can be used to build a list of assertions.\n *\n * @example\n *\n * ```ts\n * import { ZAssert, createError } from '@zthun/helpful-fn';\n *\n * const user = readUser();\n *\n * ZAssert\n * .claim(user.name != null, 'User name is required')\n * .claim(user.email != null, 'User email is required')\n * .assert((m) => createError(m));\n * ```\n */\nexport class ZAssert {\n /**\n * Initializes a new instance of a ZAssert with one claim.\n *\n * @param claim -\n * The claim to make.\n * @param msg -\n * The message to throw if the claim is false.\n *\n * @returns\n * A new ZAssert object with an initial claim.\n */\n public static claim(claim: boolean, msg: any): ZAssert {\n return new ZAssert().claim(claim, msg);\n }\n\n private _messages: any[] = [];\n\n /**\n * Initializes a new instance of this object.\n */\n private constructor() {}\n\n /**\n * Adds a claim.\n *\n * @param claim -\n * The claim predicate.\n * @param msg -\n * The message to add if the claim fails.\n *\n * @returns This object.\n */\n public claim(claim: boolean, msg: any): this {\n if (!claim) {\n this._messages.push(msg);\n }\n return this;\n }\n\n /**\n * Runs the assertion.\n *\n * @param fail -\n * The factory that is responsible for returning the specified error to throw.\n */\n public assert<E extends Error>(fail: (message: any | any[]) => E): void {\n if (this._messages.length === 1) {\n throw fail(this._messages[0]);\n }\n\n if (this._messages.length) {\n throw fail(this._messages);\n }\n }\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. If this value receives\n * Infinity, then it will result in 1 or min buckets being returned,\n * whichever is larger. If this receives NaN, then this method will\n * result in NaN. Finally, if this receives a negative value, then\n * the result will be max.\n * @param items -\n * The total number of items you need to store where each item\n * counts as 1 towards the weight. If the total number of items\n * is Infinity, then this method will result in max buckets.\n * If this receives NaN, then this method will result in NaN. Finally,\n * if you pass 0, or a negative number of items, then result will be min.\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 * The default is 0.\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 * The default is Infinity.\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 *\n * @example\n *\n * ```ts\n * // The following will return 5 for numberOfPages since you need 5 buckets\n * // to store 101 number of items where each bucket can hold a max of 25\n * // items. The 5th page would be a page of 1 item, since 1 is the remainder.\n * const numberOfPages = countBuckets(25, 101);\n *\n * // In this case, the numberOfPages would be 1 here since our minimum buckets\n * // is 1. By default, this would be 0.\n * const numberOfPages = countBuckets(10, 0, 1);\n *\n * // In this case, we have more items that can be held in the number of buckets\n * // available, so only 4 is returned instead of the 5.\n * const numberOfPages = countBuckets(25, 101, undefined, 4);\n * ```\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]. By default, the schema will look for properties\n * named, message, error, exception, and data, in that order.\n *\n * @returns\n * An error object that is the best evaluation of what the problem actually is.\n *\n * @example\n *\n * ```ts\n * // All of these result an Error with the message, 'Something went wrong'\n * const errorWithStringProblem = createError('Something went wrong');\n * const errorWithObjectProblemInSchema = createError({ error: 'Something went wrong'});\n * const errorWithCustomSchema = createError({ issue: 'Something went wrong'}, ['issue']);\n * const errorRecursive = createError({ error: { message: 'Something went wrong' }});\n *\n * // This would result in '[Object object]' as there is no way to figure out how to deconstruct this problem.\n * const errorCannotBeFound = createError({ wut: 'Something went wrong' });\n * ```\n */\nexport function createError(problem: any, schema = ['message', 'error', 'exception', 'data']): 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 * The identifier holds to v4 of the UUID specification. A summary\n * of the specification can be found at\n * {@link https://commons.apache.org/sandbox/commons-id/uuid.html | Apache Commons UUID Documentation}.\n *\n * The official documentation of the UUID specification is under\n * {@link https://www.rfc-editor.org/info/rfc4122 | RFC 4122}\n *\n * @returns\n * A new generated globally unique identifier based on random bytes.\n *\n * @example\n *\n * ```ts\n * // Will get a value similar to 53e33fb6-d05a-4fa9-8dc0-b78e4feaa702\n * const guidA = createGuid();\n * // Will most likely not ever be equal to guidA\n * const guidB = createGuid();\n * ```\n */\nexport const createGuid: () => string = v4;\n","/**\n * Returns the first value in an argument list that matches a predicate.\n *\n * @param predicate -\n * The match method against each value argument.\n * @param fallback -\n * The fallback value in the case that all arguments fail\n * the predicate.\n * @param first -\n * The first value to check.\n * @param remaining -\n * The remaining values beyond the first to check.\n * @param T -\n * The type of data that will be enumerated.\n *\n * @returns\n * The first value for where {@link predicate} returns true for the given argument value.\n * If first and all values of remaining fail the predicate then fallback is returned.\n */\nexport function firstWhere<T = any>(\n predicate: (v: T | null | undefined) => boolean,\n fallback: T,\n first: T,\n ...remaining: T[]\n): T {\n if (predicate(first)) {\n return first;\n }\n\n for (let i = 0; i < remaining.length; ++i) {\n const val = remaining[i];\n\n if (predicate(val)) {\n return val;\n }\n }\n\n return fallback;\n}\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 * @param T -\n * The type of data that will be enumerated.\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 *\n * @example\n *\n * ```ts\n * // 'Defined'\n * const shouldBeDefined = firstDefined('Fallback', null, undefined, 'Defined');\n * // 'Fallback'\n * const shouldBeFallback = firstDefined('Fallback', null, undefined);\n * const shouldAlsoBeFallback = firstDefined('Fallback', undefined);\n * // 'First'\n * const shouldBeFirst = firstDefined('Fallback', 'First', null, 'Third');\n * ```\n */\nexport function firstDefined<T = any>(\n fallback: T,\n first: T | null | undefined,\n ...remaining: (T | null | undefined)[]\n): T {\n return firstWhere<T | null | undefined>((v) => v != null, fallback, first, ...remaining) as T;\n}\n\n/**\n * Returns the first value in args such that args is truthy\n *\n * @param fallback -\n * The fallback value in the case that all values in args are falsy.\n * @param first -\n * The first value to check.\n * @param remaining -\n * The remaining values beyond the first to check.\n * @param T -\n * The type of data that will be enumerated.\n *\n * @returns\n * The first value if it is truthy. If first is falsy, then the first item\n * in remaining such that remaining[i] is truthy is returned. If first and\n * all values of remaining are falsy, then fallback is returned.\n *\n * @example\n *\n * ```ts\n * // 'Defined'\n * const shouldBeDefined = firstTruthy('Fallback', null, undefined, 'Defined');\n * // 'Fallback'\n * const shouldBeFallback = firstTruthy('Fallback', '', undefined);\n * const shouldAlsoBeFallback = firstDefined('Fallback', 0, false);\n * // 'First'\n * const shouldBeFirst = firstDefined('Fallback', 'First', null, false, 0, NaN);\n * ```\n */\nexport function firstTruthy<T = any>(\n fallback: T,\n first: T | null | undefined,\n ...remaining: (T | null | undefined)[]\n): T {\n return firstWhere<T | null | undefined>((v) => !!v, fallback, first, ...remaining) as T;\n}\n","/**\n * Represents a object of 4 side values.\n *\n * @param T -\n * Value type. Typically number.\n */\nexport interface IZQuadrilateral<T = number> {\n /**\n * Bottom value.\n */\n bottom: T;\n /**\n * Left value.\n */\n left: T;\n /**\n * Right value.\n */\n right: T;\n /**\n * Top value.\n */\n top: T;\n}\n\n/**\n * Represents a builder for a quadrilateral object.\n */\nexport class ZQuadrilateralBuilder<T = number> {\n private _quad: IZQuadrilateral<T>;\n\n /**\n * Initializes a new instance of this object.\n *\n * @param start -\n * The starting value.\n */\n public constructor(start: T) {\n this._quad = {\n bottom: start,\n left: start,\n right: start,\n top: start\n };\n }\n\n /**\n * Sets the bottom value.\n *\n * @param bottom -\n * The bottom value.\n *\n * @returns\n * This object.\n */\n public bottom(bottom: T): this {\n this._quad.bottom = bottom;\n return this;\n }\n\n /**\n * Sets the left value.\n *\n * @param left -\n * The left value.\n *\n * @returns\n * This object.\n */\n public left(left: T): this {\n this._quad.left = left;\n return this;\n }\n\n /**\n * Sets the right value.\n *\n * @param right -\n * The right value.\n *\n * @returns\n * This object.\n */\n public right(right: T): this {\n this._quad.right = right;\n return this;\n }\n\n /**\n * Sets the top value.\n *\n * @param top -\n * The top value.\n *\n * @returns\n * This object.\n */\n public top(top: T): this {\n this._quad.top = top;\n return this;\n }\n\n /**\n * Sets the left and right value.\n *\n * @param x -\n * The left and right value.\n *\n * @returns\n * This object.\n */\n public x(x: T): this {\n return this.left(x).right(x);\n }\n\n /**\n * Sets the top and bottom value.\n *\n * @param y -\n * The top and bottom value.\n *\n * @returns\n * This object.\n */\n public y(y: T): this {\n return this.bottom(y).top(y);\n }\n\n /**\n * Copies another quadrilateral object into the current instance.\n *\n * @param other -\n * The quadrilateral object to copy.\n *\n * @returns\n * This object.\n */\n public copy(other: IZQuadrilateral<T>): this {\n this._quad = structuredClone(other);\n return this;\n }\n\n /**\n * Returns the built quadrilateral object.\n *\n * @returns\n * The built quadrilateral.\n */\n public build(): IZQuadrilateral<T> {\n return structuredClone(this._quad);\n }\n}\n","import { ZAnchor, ZHorizontalAnchor, ZVerticalAnchor } from '../anchor/anchor.mjs';\nimport { IZPoint2d } from './point.mjs';\nimport { IZQuadrilateral } from './quadrilateral.mjs';\n\n/**\n * Represents a helper object that can run calculations on a numeric quadrilateral.\n */\nexport class ZRectangle {\n /**\n * Initializes a new instance of this object.\n *\n * @param sides -\n * The numeric sides of a quadrilateral.\n */\n public constructor(public readonly sides: IZQuadrilateral) {}\n\n /**\n * Calculates the width of the rectangle.\n *\n * @returns\n * The numeric width of the rectangle.\n */\n public width(): number {\n const { left, right } = this.sides;\n return right - left;\n }\n\n /**\n * Calculates the height of the rectangle.\n *\n * @returns\n * The numeric height of the rectangle.\n */\n public height(): number {\n const { top, bottom } = this.sides;\n return bottom - top;\n }\n\n /**\n * Calculates the area of the rectangle.\n *\n * @returns\n * The numeric area of the rectangle.\n */\n public area(): number {\n return this.width() * this.height();\n }\n\n /**\n * Calculates the (x, y) point given an anchor target.\n *\n * @param anchor -\n * The anchor target to calculate the point for.\n *\n * @returns\n * The numeric width of the rectangle.\n */\n public point(anchor: ZAnchor): IZPoint2d {\n const { bottom, left, right, top } = this.sides;\n const [vertical, horizontal] = anchor;\n\n const v: Record<ZVerticalAnchor, number> = {\n [ZVerticalAnchor.Top]: top,\n [ZVerticalAnchor.Middle]: (bottom + top) / 2,\n [ZVerticalAnchor.Bottom]: bottom\n };\n\n const h: Record<ZHorizontalAnchor, number> = {\n [ZHorizontalAnchor.Left]: left,\n [ZHorizontalAnchor.Center]: (right + left) / 2,\n [ZHorizontalAnchor.Right]: right\n };\n\n return { x: h[horizontal], y: v[vertical] };\n }\n\n /**\n * Calculates the top left point of the rectangle.\n *\n * @returns\n * The top left point of the rectangle.\n */\n public topLeft = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Left]);\n /**\n * Calculates the top center point of the rectangle.\n *\n * @returns\n * The top center point of the rectangle.\n */\n public topCenter = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Center]);\n /**\n * Calculates the top right point of the rectangle.\n *\n * @returns\n * The top right point of the rectangle.\n */\n public topRight = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Right]);\n /**\n * Calculates the middle left point of the rectangle.\n *\n * @returns\n * The middle left point of the rectangle.\n */\n public middleLeft = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Left]);\n /**\n * Calculates the middle center point of the rectangle.\n *\n * @returns\n * The middle center point of the rectangle.\n */\n public middleCenter = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Center]);\n /**\n * Calculates the middle right point of the rectangle.\n *\n * @returns\n * The middle right point of the rectangle.\n */\n public middleRight = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Right]);\n /**\n * Calculates the bottom left point of the rectangle.\n *\n * @returns\n * The bottom left point of the rectangle.\n */\n public bottomLeft = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Left]);\n /**\n * Calculates the bottom center point of the rectangle.\n *\n * @returns\n * The bottom center point of the rectangle.\n */\n public bottomCenter = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Center]);\n /**\n * Calculates the bottom right point of the rectangle.\n *\n * @returns\n * The bottom right point of the rectangle.\n */\n public bottomRight = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Right]);\n}\n","/* istanbul ignore next -- @preserve */\nexport const $global = typeof window === 'undefined' ? global : window;\n","/**\n * A set of parameters that can be used for a string join.\n *\n * Join lists can be a regular object, null, undefined, or a tuple where the\n * first item is the object to join, and the second item is a boolean that specifies\n * whether to include it if the value is truthy.\n *\n * @param T -\n * The type of data to join.\n */\nexport type JoinListInputParameter<T> = T | [T, boolean] | null | undefined;\n\n/**\n * Similar to {@link Array.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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by delimiter.\n *\n * @example\n *\n * ```ts\n * // 'a b d'\n * const joinBySpace = joinDefined(' ', 'a', 'b', ['c', false], null, undefined, ['d', true]);\n * // (Empty String)\n * const joinEmpty = joinDefined('?');\n * ```\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 space delimiter.\n *\n * @param items -\n * The items to join.\n * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by space delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a space delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a comma delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a semi-colon delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a pipe delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\n */\nexport const pipeJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, '|');\n","/**\n * A specific set of possible values that need to be checked for requirements.\n *\n * @param T -\n * The type of value that is being checked.\n */\nexport type ZObligatedValue<T> = T | null | undefined | Promise<T | null | undefined>;\n\n/**\n * Requires a value to be non null.\n *\n * @param val -\n * The value to require. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, an error is thrown.\n *\n * @throws\n * An error if the value is null or undefined.\n */\nexport async function required<T>(val: ZObligatedValue<T>): Promise<T> {\n if (val == null) {\n throw new Error('A required value was not provided');\n }\n\n const _val = await val;\n\n if (_val == null) {\n throw new Error('A required value was not provided');\n }\n\n return _val;\n}\n\n/**\n * Allows a value to be null or undefined and has a fallback.\n *\n * @param val -\n * The value to check. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param fallback -\n * The fallback value in the case that val is\n * null or undefined.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, the fallback is returned.\n * If val is a promise and rejects, then fallback is\n * also returned.\n */\nexport function optional<T>(val: ZObligatedValue<T>, fallback: T): Promise<T>;\n\n/**\n * Allows a value to be null or undefined and has a fallback.\n *\n * @param val -\n * The value to check. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, null is returned.\n * If val is a promise and rejects, then null is\n * also returned.\n */\nexport function optional<T>(val: ZObligatedValue<T>): Promise<T | null>;\n\n/**\n * Allows a value to be null or undefined and has a fallback.\n *\n * @param val -\n * The value to check. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param fallback -\n * The fallback value in the case that val is\n * null or undefined.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, the fallback is returned.\n * If val is a promise and rejects, then fallback is\n * also returned.\n */\nexport async function optional<T>(val: ZObligatedValue<T>, fallback: T | null = null): Promise<T | null> {\n if (val == null) {\n return fallback;\n }\n\n try {\n const _val = await val;\n return _val == null ? fallback : _val;\n } catch {\n return fallback;\n }\n}\n","/**\n * Represents a direction orientation.\n */\nexport enum ZOrientation {\n /**\n * Horizontal 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 * Peels a candidate string from the start of a string and splits it into two segments.\n *\n * @param str -\n * The string to peel from.\n * @param candidates -\n * The candidate list of values to peel from str.\n *\n * @returns\n * A tuple where the first item is the peeled string and\n * the second item is the remainder of the string. If the string\n * does not start with any given candidates, then the first\n * item will be null and the second item will be str.\n */\nexport function peel<T extends string = string>(str: string, candidates: T[]): [T | null, string] {\n for (const check of candidates) {\n if (str.startsWith(check)) {\n return [str.substring(0, check.length) as T, str.substring(check.length)];\n }\n }\n\n return [null, str];\n}\n\n/**\n * Peels the values between an opening string set and a closing string set.\n *\n * The actual value will handle issues with internal opening and closing brackets\n *\n * @example\n *\n * ```ts\n * const [peeled, rest] = peelBetween('[a, b, [c1, c2],[d]] other', '[' ']');\n *\n * // Outputs 'a, b, [c1, c2], [d]'\n * console.log(peeled);\n *\n * // Outputs ' other' - white space is included'\n * console.log(rest);\n * ```\n *\n * @param str -\n * The string to peel between.\n * @param open -\n * The opening string. This will test\n * at the start of str.\n * @param close -\n * The closing string. This can be anywhere\n * in the str. If this is equal to open, then\n * the open string is removed from the start of the\n * string and the rest of the string would be returned.\n *\n * @returns\n * A tuple where the first argument is string that was found between\n * the opening and closing bracket. Returns null if no string could\n * be found between an open and close pair. The second argument will\n * be the remaining text of the string, including whitespace.\n */\nexport function peelBetween(str: string, open: string, close: string): [string | null, string] {\n if (!str.startsWith(open)) {\n return [null, str];\n }\n\n let stack = 1;\n\n const _str = str.substring(open.length);\n\n for (let i = 0; i < _str.length; ++i) {\n if (_str.startsWith(open, i)) {\n stack += 1;\n i += open.length - 1;\n continue;\n }\n\n if (_str.startsWith(close, i)) {\n stack -= 1;\n\n if (stack === 0) {\n return [_str.substring(0, i), _str.substring(i + close.length)];\n }\n\n i += close.length - 1;\n }\n }\n\n return [null, str];\n}\n","/**\n * Represents a tri logic state.\n *\n * See {@link ZTrilean.Indeterminate} for what the symbol value should be.\n *\n * @deprecated Use the one found in [\\@zthun/trilean](https://www.npmjs.com/package/\\@zthun/trilean) instead.\n */\nexport type trilean = boolean | symbol;\n\n/**\n * A utility class for trilean values.\n *\n * @deprecated Use the one found in [\\@zthun/trilean](https://www.npmjs.com/package/\\@zthun/trilean) instead.\n */\nexport abstract class ZTrilean {\n /**\n * A unique value for the third, indeterminate, state.\n */\n public static readonly Indeterminate = Symbol('indeterminate');\n\n /**\n * Converts a trilean value to a string.\n *\n * @param x -\n * The value to convert.\n *\n * @returns\n * A string of true if x is true, false if x is false,\n * and indeterminate if x is null.\n */\n public static stringify(x: trilean): string {\n return ZTrilean.isIndeterminate(x) ? x.description! : String(x);\n }\n\n /**\n * Converts a string to a trilean value.\n *\n * @param str -\n * The text to parse.\n * @param fallback -\n * The fallback in the case that str is not a parsable value.\n *\n * @returns\n * The parsed trilean value or fallback if str is not a valid\n * trilean value.\n */\n public static parse(str: string | null | undefined, fallback: trilean = false): trilean {\n if (str?.toUpperCase().localeCompare('TRUE') === 0) {\n return true;\n }\n\n if (str?.toUpperCase().localeCompare('FALSE') === 0) {\n return false;\n }\n\n if (str?.toUpperCase().localeCompare('INDETERMINATE') === 0) {\n return ZTrilean.Indeterminate;\n }\n\n return fallback;\n }\n\n /**\n * Gets a value that determines if val is a trilean supported value.\n *\n * @param val -\n * The value to test.\n *\n * @returns\n * True if val is a trilean value. False otherwise.\n */\n public static is(val: any): val is trilean {\n return typeof val === 'boolean' || ZTrilean.isIndeterminate(val);\n }\n\n /**\n * Gets whether val is the indeterminate value.\n */\n public static isIndeterminate(val: trilean): val is symbol {\n return val === ZTrilean.Indeterminate;\n }\n\n /**\n * Converts from a value to a trilean value.\n *\n * This is similar to parse, but it also supports non\n * string inputs which will be converted to a boolean.\n *\n * @param val -\n * The value to convert.\n * @param fallback -\n * The fallback value in the case that val cannot be converted. This will\n * only be used in the case that val is a string, null, or undefined.\n *\n * @returns\n * The trilean value of val. If val is null or undefined, then\n * fallback is returned. If val is a string, then the return value of\n * {@link parse} will be used. If val is a boolean, then it will be\n * directly returned. If val is equal to {@link Indeterminate}, then\n * {@link Indeterminate} will be returned. Otherwise, the truthy\n * nature of value will be returned.\n */\n public static convert(val: any, fallback: trilean = false): trilean {\n if (val == null) {\n return fallback;\n }\n\n if (ZTrilean.is(val)) {\n return val;\n }\n\n if (typeof val === 'string') {\n return ZTrilean.parse(val, fallback);\n }\n\n return !!val;\n }\n}\n","import { IZDeserialize } from './deserialize.mjs';\n\n/**\n * A deserializer that deserializes a JSON string.\n */\nexport class ZDeserializeJson<T> implements IZDeserialize<T> {\n public constructor(private _schema?: (k: any) => k is T) {}\n\n public deserialize(candidate: string): T {\n const parsed = JSON.parse(candidate);\n\n if (this._schema && !this._schema(parsed)) {\n throw new Error('The parsed JSON does not conform to the given schema requirement');\n }\n\n return parsed;\n }\n}\n","import { IZDeserialize } from './deserialize.mjs';\n\n/**\n * A deserializer that attempts to deserialize multiple times through a series of supported languages.\n *\n * @param T -\n * The type of data to deserialize.\n * @param S -\n * The input type\n */\nexport class ZDeserializeTry<T, S = string> implements IZDeserialize<T, S> {\n /**\n * Initializes a new instance of this object.\n *\n * @param _children -\n * The list of deserializer objects to try on a specific candidate.\n * The first deserializer to succeed will return the target object.\n * If no deserializer is able to deserialize the candidate, then an\n * error is throw with a mapping of serialization errors between each\n * deserializer.\n */\n public constructor(private _children: IZDeserialize<T, S>[]) {}\n\n public deserialize(candidate: S): T {\n const errors: string[] = [];\n\n for (const child of this._children) {\n try {\n return child.deserialize(candidate);\n } catch (e) {\n errors.push(e.message);\n }\n }\n\n const msg = `Unable to deserialize candidate, ${candidate}.`;\n errors.splice(0, 0, msg);\n throw new Error(errors.join('\\n\\n'));\n }\n}\n","import { IZSerialize } from './serialize.mjs';\n\n/**\n * Represents a serializer that serializes anything to a JSON string.\n */\nexport class ZSerializeJson implements IZSerialize<any> {\n public serialize(candidate: any): string | undefined {\n return JSON.stringify(candidate, undefined, 2);\n }\n}\n","/**\n * Represents a setter function for when you want to set a single value,\n * 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. This is primarily meant\n * to be use with bind to construct a new method setter that takes an array\n * and forwards it to a setter method which will accept a single value of the\n * first item in the target value.\n *\n * @param setValue -\n * The setter function that takes a single value. This will receive\n * the first item of the value list.\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 * @param T -\n * The type of data that the array holds.\n *\n * @example\n *\n * ```ts\n * // An example of a react component that needs a value of an array, but you only care about a single selection.\n * const [value, setValue] = useState<TypesOfPie>();\n * const _values = useMemo(() => value ? [value] : [], [value]);\n * const _setValues = setFirst.bind(null, setValue, undefined);\n *\n * return <ComponentWithMultiSelectSupport values={_values} onValuesChange={_setValues} />\n * ```\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 * @param T -\n * The type of value that will be resolved.\n *\n * @returns\n * A promise that resolves with val 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 * @param T -\n * The type of value that will be resolved.\n *\n * @returns\n * A promise that resolves with val 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","/**\n * This is just a method that allows you to tag an interpolation\n * string as a syntax language.\n *\n * This is useful with IDE extensions that can detect the language\n * and do the syntax highlighting for you.\n *\n * @param strings -\n * The string breaks for interpolation.\n * @param expressions -\n * The equivalent expressions that break apart\n * the single string literal.\n *\n * @returns\n * The compiled string literal. This is no different\n * than letting native JavaScript do it for you.\n *\n * @example\n *\n * ```ts\n * const html = tag;\n * const css = tag;\n *\n * const $html = html`\n * <div>Some IDE extensions will highlight this as html</div>\n * `\n *\n * const $css = css`\n * button {\n * display: grid;\n * }\n * `\n * ```\n */\nexport function tag(strings: TemplateStringsArray, ...expressions: unknown[]): string {\n let [result] = strings;\n\n for (let i = 1, l = strings.length; i < l; i++) {\n result += expressions[i - 1];\n result += strings[i];\n }\n\n return result;\n}\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=Tobermory.es6-string-html | IDE extensions will detect the string}\n * interpolation as html when using this tag.\n */\nexport const html = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=bashmish.es6-string-css | IDE extensions will detect the string}\n * interpolation as css when using this tag.\n */\nexport const css = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=zjcompt.es6-string-javascript | IDE extensions will detect the string}\n * interpolation as javascript when using this tag.\n */\nexport const javascript = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=jeoht.es6-string-markdown | IDE extensions will detect the string}\n * interpolation as markdown when using this tag.\n */\nexport const md = tag;\n\n/**\n * See {@link md}\n */\nexport const markdown = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=HoodieCollin.es6-string-typescript | IDE extensions will detect the string}\n * interpolation as typescript when using this tag.\n */\nexport const ts = tag;\n\n/**\n * See {@link ts}\n */\nexport const typescript = tag;\n","/**\n * Invokes the candidate function and returns undefined if an error is thrown from it.\n *\n * @param candidate -\n * The candidate function to run.\n *\n * @returns\n * The result from candidate. Returns undefined if candidate throws an Error.\n */\nexport function tryFallback<T>(candidate: () => T): T | undefined;\n\n/**\n * Invokes the candidate function and returns fallback if an error is thrown from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The fallback value to return if candidate throws an error.\n *\n * @returns\n * The result from candidate. Returns fallback if candidate throws an Error.\n */\nexport function tryFallback<T>(candidate: () => T, fallback: T): T;\n\n/**\n * Invokes the candidate function and returns fallback if an error is thrown from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The fallback value to return if candidate throws an error.\n *\n * @returns\n * The result from candidate. Returns fallback if candidate throws an Error.\n * If no fallback value is provided, then undefined is returned.\n */\nexport function tryFallback<T>(candidate: () => T, fallback?: T): T | undefined {\n try {\n return candidate();\n } catch {\n return fallback;\n }\n}\n\n/**\n * Invokes the candidate function and returns undefined if an rejected promise is returned from it.\n *\n * @param candidate -\n * The candidate function to run.\n *\n * @returns\n * A promise that resolves with the result from candidate. Returns undefined\n * if candidate returns a rejected promise.\n */\nexport function tryFallbackAsync<T>(candidate: () => Promise<T>): Promise<T | undefined>;\n\n/**\n * Invokes the candidate function and returns undefined if an rejected promise is returned from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The fallback value that will be returned if candidate returns a rejected promise.\n *\n * @returns\n * A promise that resolves with the result from candidate. Returns fallback\n * if candidate returns a rejected promise.\n */\nexport function tryFallbackAsync<T>(candidate: () => Promise<T>, fallback: T): Promise<T>;\n\n/**\n * Invokes the candidate function and returns undefined if an rejected promise is returned from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The optional fallback value to return if the candidate throws an Error.\n *\n * @returns\n * A promise that resolves with the result from candidate or fallback\n * if candidate returns a rejected promise. Resolves with undefined\n * if no fallback is provided.\n */\nexport async function tryFallbackAsync<T>(candidate: () => Promise<T>, fallback?: T): Promise<T | undefined> {\n try {\n return await candidate();\n } catch {\n return fallback;\n }\n}\n"],"names":["ZVerticalAnchor","ZHorizontalAnchor","v4","ZOrientation"],"mappings":";;;AAGY,IAAA,oCAAAA,qBAAL;AAMLA,mBAAA,KAAM,IAAA;AAINA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AAA,EACT;AACF;AAyCsB,eAAA,iBAAoB,WAA6B,UAAsC;AACvG,MAAA;AACF,WAAO,MAAM,UAAU;AAAA,EAAA,QACjB;AACC,WAAA;AAAA,EACT;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/anchor/anchor.mts","../src/assert/assert.mts","../src/count-buckets/count-buckets.mts","../src/create-error/create-error.mts","../src/create-guid/create-guid.mts","../src/first-where/first-where.mts","../src/geometry/quadrilateral.mts","../src/geometry/rectangle.mts","../src/global/global.mts","../src/join-defined/join-defined.mts","../src/obligation/obligation.mts","../src/orientation/orientation.mts","../src/peel/peel.mts","../src/schema/trilean.mts","../src/serialize/deserialize-json.mts","../src/serialize/deserialize-try.mts","../src/serialize/serialize-json.mts","../src/set-first/set-first.mts","../src/sleep/sleep.mts","../src/tag/tag.mts","../src/try-fallback/try-fallback.mts"],"sourcesContent":["/**\n * Represents a targeted point along a y axis.\n */\nexport enum ZVerticalAnchor {\n /**\n * Top boundary.\n *\n * In vertical device space, this would equate to y = 0.\n */\n Top = 'top',\n /**\n * Centerpoint between the top and bottom.\n */\n Middle = 'middle',\n /**\n * Bottom boundary.\n *\n * In vertical device space, this would equate to y = Infinity.\n */\n Bottom = 'bottom'\n}\n\n/**\n * Represents a targeted point along an x axis.\n */\nexport enum ZHorizontalAnchor {\n /**\n * Left boundary.\n *\n * In horizontal device space, this would equate to x = 0.\n */\n Left = 'left',\n /**\n * Centerpoint between the left and right boundary.\n */\n Center = 'center',\n /**\n * Right boundary.\n *\n * In horizontal device space, this would equate to x = Infinity.\n */\n Right = 'right'\n}\n\n/**\n * Represents an anchor point in 2d space.\n *\n * An anchor array is defined by [vertical, horizontal]\n * and is read as such.\n *\n * @example\n *\n * ```ts\n * const topCenter = [ZVerticalAnchor.Top, ZHorizontalAnchor.Center];\n * const bottomRight = [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Right];\n * ```\n *\n * @see {@link ZVerticalAnchor} For more information.\n * @see {@link ZHorizontalAnchor} For more information.\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 * Represents an object that can be used to build a list of assertions.\n *\n * @example\n *\n * ```ts\n * import { ZAssert, createError } from '@zthun/helpful-fn';\n *\n * const user = readUser();\n *\n * ZAssert\n * .claim(user.name != null, 'User name is required')\n * .claim(user.email != null, 'User email is required')\n * .assert((m) => createError(m));\n * ```\n */\nexport class ZAssert {\n /**\n * Initializes a new instance of a ZAssert with one claim.\n *\n * @param claim -\n * The claim to make.\n * @param msg -\n * The message to throw if the claim is false.\n *\n * @returns\n * A new ZAssert object with an initial claim.\n */\n public static claim(claim: boolean, msg: any): ZAssert {\n return new ZAssert().claim(claim, msg);\n }\n\n private _messages: any[] = [];\n\n /**\n * Initializes a new instance of this object.\n */\n private constructor() {}\n\n /**\n * Adds a claim.\n *\n * @param claim -\n * The claim predicate.\n * @param msg -\n * The message to add if the claim fails.\n *\n * @returns This object.\n */\n public claim(claim: boolean, msg: any): this {\n if (!claim) {\n this._messages.push(msg);\n }\n return this;\n }\n\n /**\n * Runs the assertion.\n *\n * @param fail -\n * The factory that is responsible for returning the specified error to throw.\n */\n public assert<E extends Error>(fail: (message: any | any[]) => E): void {\n if (this._messages.length === 1) {\n throw fail(this._messages[0]);\n }\n\n if (this._messages.length) {\n throw fail(this._messages);\n }\n }\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. If this value receives\n * Infinity, then it will result in 1 or min buckets being returned,\n * whichever is larger. If this receives NaN, then this method will\n * result in NaN. Finally, if this receives a negative value, then\n * the result will be max.\n * @param items -\n * The total number of items you need to store where each item\n * counts as 1 towards the weight. If the total number of items\n * is Infinity, then this method will result in max buckets.\n * If this receives NaN, then this method will result in NaN. Finally,\n * if you pass 0, or a negative number of items, then result will be min.\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 * The default is 0.\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 * The default is Infinity.\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 *\n * @example\n *\n * ```ts\n * // The following will return 5 for numberOfPages since you need 5 buckets\n * // to store 101 number of items where each bucket can hold a max of 25\n * // items. The 5th page would be a page of 1 item, since 1 is the remainder.\n * const numberOfPages = countBuckets(25, 101);\n *\n * // In this case, the numberOfPages would be 1 here since our minimum buckets\n * // is 1. By default, this would be 0.\n * const numberOfPages = countBuckets(10, 0, 1);\n *\n * // In this case, we have more items that can be held in the number of buckets\n * // available, so only 4 is returned instead of the 5.\n * const numberOfPages = countBuckets(25, 101, undefined, 4);\n * ```\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]. By default, the schema will look for properties\n * named, message, error, exception, and data, in that order.\n *\n * @returns\n * An error object that is the best evaluation of what the problem actually is.\n *\n * @example\n *\n * ```ts\n * // All of these result an Error with the message, 'Something went wrong'\n * const errorWithStringProblem = createError('Something went wrong');\n * const errorWithObjectProblemInSchema = createError({ error: 'Something went wrong'});\n * const errorWithCustomSchema = createError({ issue: 'Something went wrong'}, ['issue']);\n * const errorRecursive = createError({ error: { message: 'Something went wrong' }});\n *\n * // This would result in '[Object object]' as there is no way to figure out how to deconstruct this problem.\n * const errorCannotBeFound = createError({ wut: 'Something went wrong' });\n * ```\n */\nexport function createError(problem: any, schema = ['message', 'error', 'exception', 'data']): 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 * The identifier holds to v4 of the UUID specification. A summary\n * of the specification can be found at\n * {@link https://commons.apache.org/sandbox/commons-id/uuid.html | Apache Commons UUID Documentation}.\n *\n * The official documentation of the UUID specification is under\n * {@link https://www.rfc-editor.org/info/rfc4122 | RFC 4122}\n *\n * @returns\n * A new generated globally unique identifier based on random bytes.\n *\n * @example\n *\n * ```ts\n * // Will get a value similar to 53e33fb6-d05a-4fa9-8dc0-b78e4feaa702\n * const guidA = createGuid();\n * // Will most likely not ever be equal to guidA\n * const guidB = createGuid();\n * ```\n */\nexport const createGuid: () => string = v4;\n","/**\n * Returns the first value in an argument list that matches a predicate.\n *\n * @param predicate -\n * The match method against each value argument.\n * @param fallback -\n * The fallback value in the case that all arguments fail\n * the predicate.\n * @param first -\n * The first value to check.\n * @param remaining -\n * The remaining values beyond the first to check.\n * @param T -\n * The type of data that will be enumerated.\n *\n * @returns\n * The first value for where {@link predicate} returns true for the given argument value.\n * If first and all values of remaining fail the predicate then fallback is returned.\n */\nexport function firstWhere<T = any>(\n predicate: (v: T | null | undefined) => boolean,\n fallback: T,\n first: T,\n ...remaining: T[]\n): T {\n if (predicate(first)) {\n return first;\n }\n\n for (let i = 0; i < remaining.length; ++i) {\n const val = remaining[i];\n\n if (predicate(val)) {\n return val;\n }\n }\n\n return fallback;\n}\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 * @param T -\n * The type of data that will be enumerated.\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 *\n * @example\n *\n * ```ts\n * // 'Defined'\n * const shouldBeDefined = firstDefined('Fallback', null, undefined, 'Defined');\n * // 'Fallback'\n * const shouldBeFallback = firstDefined('Fallback', null, undefined);\n * const shouldAlsoBeFallback = firstDefined('Fallback', undefined);\n * // 'First'\n * const shouldBeFirst = firstDefined('Fallback', 'First', null, 'Third');\n * ```\n */\nexport function firstDefined<T = any>(\n fallback: T,\n first: T | null | undefined,\n ...remaining: (T | null | undefined)[]\n): T {\n return firstWhere<T | null | undefined>((v) => v != null, fallback, first, ...remaining) as T;\n}\n\n/**\n * Returns the first value in args such that args is truthy\n *\n * @param fallback -\n * The fallback value in the case that all values in args are falsy.\n * @param first -\n * The first value to check.\n * @param remaining -\n * The remaining values beyond the first to check.\n * @param T -\n * The type of data that will be enumerated.\n *\n * @returns\n * The first value if it is truthy. If first is falsy, then the first item\n * in remaining such that remaining[i] is truthy is returned. If first and\n * all values of remaining are falsy, then fallback is returned.\n *\n * @example\n *\n * ```ts\n * // 'Defined'\n * const shouldBeDefined = firstTruthy('Fallback', null, undefined, 'Defined');\n * // 'Fallback'\n * const shouldBeFallback = firstTruthy('Fallback', '', undefined);\n * const shouldAlsoBeFallback = firstDefined('Fallback', 0, false);\n * // 'First'\n * const shouldBeFirst = firstDefined('Fallback', 'First', null, false, 0, NaN);\n * ```\n */\nexport function firstTruthy<T = any>(\n fallback: T,\n first: T | null | undefined,\n ...remaining: (T | null | undefined)[]\n): T {\n return firstWhere<T | null | undefined>((v) => !!v, fallback, first, ...remaining) as T;\n}\n","/**\n * Represents a object of 4 side values.\n *\n * @param T -\n * Value type. Typically number.\n */\nexport interface IZQuadrilateral<T = number> {\n /**\n * Bottom value.\n */\n bottom: T;\n /**\n * Left value.\n */\n left: T;\n /**\n * Right value.\n */\n right: T;\n /**\n * Top value.\n */\n top: T;\n}\n\n/**\n * Represents a builder for a quadrilateral object.\n */\nexport class ZQuadrilateralBuilder<T = number> {\n private _quad: IZQuadrilateral<T>;\n\n /**\n * Initializes a new instance of this object.\n *\n * @param start -\n * The starting value.\n */\n public constructor(start: T) {\n this._quad = {\n bottom: start,\n left: start,\n right: start,\n top: start\n };\n }\n\n /**\n * Sets the bottom value.\n *\n * @param bottom -\n * The bottom value.\n *\n * @returns\n * This object.\n */\n public bottom(bottom: T): this {\n this._quad.bottom = bottom;\n return this;\n }\n\n /**\n * Sets the left value.\n *\n * @param left -\n * The left value.\n *\n * @returns\n * This object.\n */\n public left(left: T): this {\n this._quad.left = left;\n return this;\n }\n\n /**\n * Sets the right value.\n *\n * @param right -\n * The right value.\n *\n * @returns\n * This object.\n */\n public right(right: T): this {\n this._quad.right = right;\n return this;\n }\n\n /**\n * Sets the top value.\n *\n * @param top -\n * The top value.\n *\n * @returns\n * This object.\n */\n public top(top: T): this {\n this._quad.top = top;\n return this;\n }\n\n /**\n * Sets the left and right value.\n *\n * @param x -\n * The left and right value.\n *\n * @returns\n * This object.\n */\n public x(x: T): this {\n return this.left(x).right(x);\n }\n\n /**\n * Sets the top and bottom value.\n *\n * @param y -\n * The top and bottom value.\n *\n * @returns\n * This object.\n */\n public y(y: T): this {\n return this.bottom(y).top(y);\n }\n\n /**\n * Copies another quadrilateral object into the current instance.\n *\n * @param other -\n * The quadrilateral object to copy.\n *\n * @returns\n * This object.\n */\n public copy(other: IZQuadrilateral<T>): this {\n this._quad = structuredClone(other);\n return this;\n }\n\n /**\n * Returns the built quadrilateral object.\n *\n * @returns\n * The built quadrilateral.\n */\n public build(): IZQuadrilateral<T> {\n return structuredClone(this._quad);\n }\n}\n","import { ZAnchor, ZHorizontalAnchor, ZVerticalAnchor } from '../anchor/anchor.mjs';\nimport { IZPoint2d } from './point.mjs';\nimport { IZQuadrilateral } from './quadrilateral.mjs';\n\n/**\n * Represents a helper object that can run calculations on a numeric quadrilateral.\n */\nexport class ZRectangle {\n /**\n * Initializes a new instance of this object.\n *\n * @param sides -\n * The numeric sides of a quadrilateral.\n */\n public constructor(public readonly sides: IZQuadrilateral) {}\n\n /**\n * Calculates the width of the rectangle.\n *\n * @returns\n * The numeric width of the rectangle.\n */\n public width(): number {\n const { left, right } = this.sides;\n return right - left;\n }\n\n /**\n * Calculates the height of the rectangle.\n *\n * @returns\n * The numeric height of the rectangle.\n */\n public height(): number {\n const { top, bottom } = this.sides;\n return bottom - top;\n }\n\n /**\n * Calculates the area of the rectangle.\n *\n * @returns\n * The numeric area of the rectangle.\n */\n public area(): number {\n return this.width() * this.height();\n }\n\n /**\n * Calculates the (x, y) point given an anchor target.\n *\n * @param anchor -\n * The anchor target to calculate the point for.\n *\n * @returns\n * The numeric width of the rectangle.\n */\n public point(anchor: ZAnchor): IZPoint2d {\n const { bottom, left, right, top } = this.sides;\n const [vertical, horizontal] = anchor;\n\n const v: Record<ZVerticalAnchor, number> = {\n [ZVerticalAnchor.Top]: top,\n [ZVerticalAnchor.Middle]: (bottom + top) / 2,\n [ZVerticalAnchor.Bottom]: bottom\n };\n\n const h: Record<ZHorizontalAnchor, number> = {\n [ZHorizontalAnchor.Left]: left,\n [ZHorizontalAnchor.Center]: (right + left) / 2,\n [ZHorizontalAnchor.Right]: right\n };\n\n return { x: h[horizontal], y: v[vertical] };\n }\n\n /**\n * Calculates the top left point of the rectangle.\n *\n * @returns\n * The top left point of the rectangle.\n */\n public topLeft = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Left]);\n /**\n * Calculates the top center point of the rectangle.\n *\n * @returns\n * The top center point of the rectangle.\n */\n public topCenter = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Center]);\n /**\n * Calculates the top right point of the rectangle.\n *\n * @returns\n * The top right point of the rectangle.\n */\n public topRight = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Right]);\n /**\n * Calculates the middle left point of the rectangle.\n *\n * @returns\n * The middle left point of the rectangle.\n */\n public middleLeft = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Left]);\n /**\n * Calculates the middle center point of the rectangle.\n *\n * @returns\n * The middle center point of the rectangle.\n */\n public middleCenter = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Center]);\n /**\n * Calculates the middle right point of the rectangle.\n *\n * @returns\n * The middle right point of the rectangle.\n */\n public middleRight = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Right]);\n /**\n * Calculates the bottom left point of the rectangle.\n *\n * @returns\n * The bottom left point of the rectangle.\n */\n public bottomLeft = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Left]);\n /**\n * Calculates the bottom center point of the rectangle.\n *\n * @returns\n * The bottom center point of the rectangle.\n */\n public bottomCenter = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Center]);\n /**\n * Calculates the bottom right point of the rectangle.\n *\n * @returns\n * The bottom right point of the rectangle.\n */\n public bottomRight = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Right]);\n}\n","/* istanbul ignore next -- @preserve */\nexport const $global = typeof window === 'undefined' ? global : window;\n","/**\n * A set of parameters that can be used for a string join.\n *\n * Join lists can be a regular object, null, undefined, or a tuple where the\n * first item is the object to join, and the second item is a boolean that specifies\n * whether to include it if the value is truthy.\n *\n * @param T -\n * The type of data to join.\n */\nexport type JoinListInputParameter<T> = T | [T, boolean] | null | undefined;\n\n/**\n * Similar to {@link Array.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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by delimiter.\n *\n * @example\n *\n * ```ts\n * // 'a b d'\n * const joinBySpace = joinDefined(' ', 'a', 'b', ['c', false], null, undefined, ['d', true]);\n * // (Empty String)\n * const joinEmpty = joinDefined('?');\n * ```\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 space delimiter.\n *\n * @param items -\n * The items to join.\n * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by space delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a space delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a comma delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a semi-colon delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a pipe delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\n */\nexport const pipeJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, '|');\n","/**\n * A specific set of possible values that need to be checked for requirements.\n *\n * @param T -\n * The type of value that is being checked.\n */\nexport type ZObligatedValue<T> = T | null | undefined | Promise<T | null | undefined>;\n\n/**\n * Requires a value to be non null.\n *\n * @param val -\n * The value to require. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, an error is thrown.\n *\n * @throws\n * An error if the value is null or undefined.\n */\nexport async function required<T>(val: ZObligatedValue<T>): Promise<T> {\n if (val == null) {\n throw new Error('A required value was not provided');\n }\n\n const _val = await val;\n\n if (_val == null) {\n throw new Error('A required value was not provided');\n }\n\n return _val;\n}\n\n/**\n * Allows a value to be null or undefined and has a fallback.\n *\n * @param val -\n * The value to check. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param fallback -\n * The fallback value in the case that val is\n * null or undefined.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, the fallback is returned.\n * If val is a promise and rejects, then fallback is\n * also returned.\n */\nexport function optional<T>(val: ZObligatedValue<T>, fallback: T): Promise<T>;\n\n/**\n * Allows a value to be null or undefined and has a fallback.\n *\n * @param val -\n * The value to check. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, null is returned.\n * If val is a promise and rejects, then null is\n * also returned.\n */\nexport function optional<T>(val: ZObligatedValue<T>): Promise<T | null>;\n\n/**\n * Allows a value to be null or undefined and has a fallback.\n *\n * @param val -\n * The value to check. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param fallback -\n * The fallback value in the case that val is\n * null or undefined.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, the fallback is returned.\n * If val is a promise and rejects, then fallback is\n * also returned.\n */\nexport async function optional<T>(val: ZObligatedValue<T>, fallback: T | null = null): Promise<T | null> {\n if (val == null) {\n return fallback;\n }\n\n try {\n const _val = await val;\n return _val == null ? fallback : _val;\n } catch {\n return fallback;\n }\n}\n","/**\n * Represents a direction orientation.\n */\nexport enum ZOrientation {\n /**\n * Horizontal 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 * Peels a candidate string from the start of a string and splits it into two segments.\n *\n * @param str -\n * The string to peel from.\n * @param candidates -\n * The candidate list of values to peel from str.\n *\n * @returns\n * A tuple where the first item is the peeled string and\n * the second item is the remainder of the string. If the string\n * does not start with any given candidates, then the first\n * item will be null and the second item will be str.\n */\nexport function peel<T extends string = string>(str: string, candidates: T[]): [T | null, string] {\n for (const check of candidates) {\n if (str.startsWith(check)) {\n return [str.substring(0, check.length) as T, str.substring(check.length)];\n }\n }\n\n return [null, str];\n}\n\n/**\n * Peels the values between an opening string set and a closing string set.\n *\n * The actual value will handle issues with internal opening and closing brackets\n *\n * @example\n *\n * ```ts\n * const [peeled, rest] = peelBetween('[a, b, [c1, c2],[d]] other', '[' ']');\n *\n * // Outputs 'a, b, [c1, c2], [d]'\n * console.log(peeled);\n *\n * // Outputs ' other' - white space is included'\n * console.log(rest);\n * ```\n *\n * @param str -\n * The string to peel between.\n * @param open -\n * The opening string. This will test\n * at the start of str.\n * @param close -\n * The closing string. This can be anywhere\n * in the str. If this is equal to open, then\n * the open string is removed from the start of the\n * string and the rest of the string would be returned.\n *\n * @returns\n * A tuple where the first argument is string that was found between\n * the opening and closing bracket. Returns null if no string could\n * be found between an open and close pair. The second argument will\n * be the remaining text of the string, including whitespace.\n */\nexport function peelBetween(str: string, open: string, close: string): [string | null, string] {\n if (!str.startsWith(open)) {\n return [null, str];\n }\n\n let stack = 1;\n\n const _str = str.substring(open.length);\n\n for (let i = 0; i < _str.length; ++i) {\n if (_str.startsWith(open, i)) {\n stack += 1;\n i += open.length - 1;\n continue;\n }\n\n if (_str.startsWith(close, i)) {\n stack -= 1;\n\n if (stack === 0) {\n return [_str.substring(0, i), _str.substring(i + close.length)];\n }\n\n i += close.length - 1;\n }\n }\n\n return [null, str];\n}\n","/**\n * Represents a tri logic state.\n *\n * See {@link ZTrilean.Indeterminate} for what the symbol value should be.\n *\n * @deprecated Use the one found in [\\@zthun/trilean](https://www.npmjs.com/package/\\@zthun/trilean) instead.\n */\nexport type trilean = boolean | symbol;\n\n/**\n * A utility class for trilean values.\n *\n * @deprecated Use the one found in [\\@zthun/trilean](https://www.npmjs.com/package/\\@zthun/trilean) instead.\n */\nexport abstract class ZTrilean {\n /**\n * A unique value for the third, indeterminate, state.\n */\n public static readonly Indeterminate = Symbol('helpful-fn-indeterminate');\n\n /**\n * Converts a trilean value to a string.\n *\n * @param x -\n * The value to convert.\n *\n * @returns\n * A string of true if x is true, false if x is false,\n * and indeterminate if x is null.\n */\n public static stringify(x: trilean): string {\n return ZTrilean.isIndeterminate(x) ? 'indeterminate' : String(x);\n }\n\n /**\n * Converts a string to a trilean value.\n *\n * @param str -\n * The text to parse.\n * @param fallback -\n * The fallback in the case that str is not a parsable value.\n *\n * @returns\n * The parsed trilean value or fallback if str is not a valid\n * trilean value.\n */\n public static parse(str: string | null | undefined, fallback: trilean = false): trilean {\n if (str?.toUpperCase().localeCompare('TRUE') === 0) {\n return true;\n }\n\n if (str?.toUpperCase().localeCompare('FALSE') === 0) {\n return false;\n }\n\n if (str?.toUpperCase().localeCompare('INDETERMINATE') === 0) {\n return ZTrilean.Indeterminate;\n }\n\n return fallback;\n }\n\n /**\n * Gets a value that determines if val is a trilean supported value.\n *\n * @param val -\n * The value to test.\n *\n * @returns\n * True if val is a trilean value. False otherwise.\n */\n public static is(val: any): val is trilean {\n return typeof val === 'boolean' || ZTrilean.isIndeterminate(val);\n }\n\n /**\n * Gets whether val is the indeterminate value.\n */\n public static isIndeterminate(val: trilean): val is symbol {\n return val === ZTrilean.Indeterminate;\n }\n\n /**\n * Converts from a value to a trilean value.\n *\n * This is similar to parse, but it also supports non\n * string inputs which will be converted to a boolean.\n *\n * @param val -\n * The value to convert.\n * @param fallback -\n * The fallback value in the case that val cannot be converted. This will\n * only be used in the case that val is a string, null, or undefined.\n *\n * @returns\n * The trilean value of val. If val is null or undefined, then\n * fallback is returned. If val is a string, then the return value of\n * {@link parse} will be used. If val is a boolean, then it will be\n * directly returned. If val is equal to {@link Indeterminate}, then\n * {@link Indeterminate} will be returned. Otherwise, the truthy\n * nature of value will be returned.\n */\n public static convert(val: any, fallback: trilean = false): trilean {\n if (val == null) {\n return fallback;\n }\n\n if (ZTrilean.is(val)) {\n return val;\n }\n\n if (typeof val === 'string') {\n return ZTrilean.parse(val, fallback);\n }\n\n return !!val;\n }\n}\n","import { IZDeserialize } from './deserialize.mjs';\n\n/**\n * A deserializer that deserializes a JSON string.\n */\nexport class ZDeserializeJson<T> implements IZDeserialize<T> {\n public constructor(private _schema?: (k: any) => k is T) {}\n\n public deserialize(candidate: string): T {\n const parsed = JSON.parse(candidate);\n\n if (this._schema && !this._schema(parsed)) {\n throw new Error('The parsed JSON does not conform to the given schema requirement');\n }\n\n return parsed;\n }\n}\n","import { IZDeserialize } from './deserialize.mjs';\n\n/**\n * A deserializer that attempts to deserialize multiple times through a series of supported languages.\n *\n * @param T -\n * The type of data to deserialize.\n * @param S -\n * The input type\n */\nexport class ZDeserializeTry<T, S = string> implements IZDeserialize<T, S> {\n /**\n * Initializes a new instance of this object.\n *\n * @param _children -\n * The list of deserializer objects to try on a specific candidate.\n * The first deserializer to succeed will return the target object.\n * If no deserializer is able to deserialize the candidate, then an\n * error is throw with a mapping of serialization errors between each\n * deserializer.\n */\n public constructor(private _children: IZDeserialize<T, S>[]) {}\n\n public deserialize(candidate: S): T {\n const errors: string[] = [];\n\n for (const child of this._children) {\n try {\n return child.deserialize(candidate);\n } catch (e) {\n errors.push(e.message);\n }\n }\n\n const msg = `Unable to deserialize candidate, ${candidate}.`;\n errors.splice(0, 0, msg);\n throw new Error(errors.join('\\n\\n'));\n }\n}\n","import { IZSerialize } from './serialize.mjs';\n\n/**\n * Represents a serializer that serializes anything to a JSON string.\n */\nexport class ZSerializeJson implements IZSerialize<any> {\n public serialize(candidate: any): string | undefined {\n return JSON.stringify(candidate, undefined, 2);\n }\n}\n","/**\n * Represents a setter function for when you want to set a single value,\n * 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. This is primarily meant\n * to be use with bind to construct a new method setter that takes an array\n * and forwards it to a setter method which will accept a single value of the\n * first item in the target value.\n *\n * @param setValue -\n * The setter function that takes a single value. This will receive\n * the first item of the value list.\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 * @param T -\n * The type of data that the array holds.\n *\n * @example\n *\n * ```ts\n * // An example of a react component that needs a value of an array, but you only care about a single selection.\n * const [value, setValue] = useState<TypesOfPie>();\n * const _values = useMemo(() => value ? [value] : [], [value]);\n * const _setValues = setFirst.bind(null, setValue, undefined);\n *\n * return <ComponentWithMultiSelectSupport values={_values} onValuesChange={_setValues} />\n * ```\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 * @param T -\n * The type of value that will be resolved.\n *\n * @returns\n * A promise that resolves with val 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 * @param T -\n * The type of value that will be resolved.\n *\n * @returns\n * A promise that resolves with val 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","/**\n * This is just a method that allows you to tag an interpolation\n * string as a syntax language.\n *\n * This is useful with IDE extensions that can detect the language\n * and do the syntax highlighting for you.\n *\n * @param strings -\n * The string breaks for interpolation.\n * @param expressions -\n * The equivalent expressions that break apart\n * the single string literal.\n *\n * @returns\n * The compiled string literal. This is no different\n * than letting native JavaScript do it for you.\n *\n * @example\n *\n * ```ts\n * const html = tag;\n * const css = tag;\n *\n * const $html = html`\n * <div>Some IDE extensions will highlight this as html</div>\n * `\n *\n * const $css = css`\n * button {\n * display: grid;\n * }\n * `\n * ```\n */\nexport function tag(strings: TemplateStringsArray, ...expressions: unknown[]): string {\n let [result] = strings;\n\n for (let i = 1, l = strings.length; i < l; i++) {\n result += expressions[i - 1];\n result += strings[i];\n }\n\n return result;\n}\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=Tobermory.es6-string-html | IDE extensions will detect the string}\n * interpolation as html when using this tag.\n */\nexport const html = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=bashmish.es6-string-css | IDE extensions will detect the string}\n * interpolation as css when using this tag.\n */\nexport const css = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=zjcompt.es6-string-javascript | IDE extensions will detect the string}\n * interpolation as javascript when using this tag.\n */\nexport const javascript = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=jeoht.es6-string-markdown | IDE extensions will detect the string}\n * interpolation as markdown when using this tag.\n */\nexport const md = tag;\n\n/**\n * See {@link md}\n */\nexport const markdown = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=HoodieCollin.es6-string-typescript | IDE extensions will detect the string}\n * interpolation as typescript when using this tag.\n */\nexport const ts = tag;\n\n/**\n * See {@link ts}\n */\nexport const typescript = tag;\n","/**\n * Invokes the candidate function and returns undefined if an error is thrown from it.\n *\n * @param candidate -\n * The candidate function to run.\n *\n * @returns\n * The result from candidate. Returns undefined if candidate throws an Error.\n */\nexport function tryFallback<T>(candidate: () => T): T | undefined;\n\n/**\n * Invokes the candidate function and returns fallback if an error is thrown from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The fallback value to return if candidate throws an error.\n *\n * @returns\n * The result from candidate. Returns fallback if candidate throws an Error.\n */\nexport function tryFallback<T>(candidate: () => T, fallback: T): T;\n\n/**\n * Invokes the candidate function and returns fallback if an error is thrown from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The fallback value to return if candidate throws an error.\n *\n * @returns\n * The result from candidate. Returns fallback if candidate throws an Error.\n * If no fallback value is provided, then undefined is returned.\n */\nexport function tryFallback<T>(candidate: () => T, fallback?: T): T | undefined {\n try {\n return candidate();\n } catch {\n return fallback;\n }\n}\n\n/**\n * Invokes the candidate function and returns undefined if an rejected promise is returned from it.\n *\n * @param candidate -\n * The candidate function to run.\n *\n * @returns\n * A promise that resolves with the result from candidate. Returns undefined\n * if candidate returns a rejected promise.\n */\nexport function tryFallbackAsync<T>(candidate: () => Promise<T>): Promise<T | undefined>;\n\n/**\n * Invokes the candidate function and returns undefined if an rejected promise is returned from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The fallback value that will be returned if candidate returns a rejected promise.\n *\n * @returns\n * A promise that resolves with the result from candidate. Returns fallback\n * if candidate returns a rejected promise.\n */\nexport function tryFallbackAsync<T>(candidate: () => Promise<T>, fallback: T): Promise<T>;\n\n/**\n * Invokes the candidate function and returns undefined if an rejected promise is returned from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The optional fallback value to return if the candidate throws an Error.\n *\n * @returns\n * A promise that resolves with the result from candidate or fallback\n * if candidate returns a rejected promise. Resolves with undefined\n * if no fallback is provided.\n */\nexport async function tryFallbackAsync<T>(candidate: () => Promise<T>, fallback?: T): Promise<T | undefined> {\n try {\n return await candidate();\n } catch {\n return fallback;\n }\n}\n"],"names":["ZVerticalAnchor","ZHorizontalAnchor","v4","ZOrientation"],"mappings":";;;AAGY,IAAA,oCAAAA,qBAAL;AAMLA,mBAAA,KAAM,IAAA;AAINA,mBAAA,QAAS,IAAA;AAMTA,mBAAA,QAAS,IAAA;AAhBCA,SAAAA;AAAA,GAAA,mBAAA,CAAA,CAAA;AAsBA,IAAA,sCAAAC,uBAAL;AAMLA,qBAAA,MAAO,IAAA;AAIPA,qBAAA,QAAS,IAAA;AAMTA,qBAAA,OAAQ,IAAA;AAhBEA,SAAAA;AAAA,GAAA,qBAAA,CAAA,CAAA;ACTL,MAAM,QAAQ;AAAA;AAAA;AAAA;AAAA,EAqBX,cAAc;AALtB,SAAQ,YAAmB;EAKJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EATvB,OAAc,MAAM,OAAgB,KAAmB;AACrD,WAAO,IAAI,QAAU,EAAA,MAAM,OAAO,GAAG;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBO,MAAM,OAAgB,KAAgB;AAC3C,QAAI,CAAC,OAAO;AACL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MAAM,CAAC,IAAI;AAC1C,WAAS,MAAM;AACjB;ACGO,SAAS,MAAS,KAAK,GAAG,MAAqB,QAAmC;AAChF,SAAA,IAAI,QAAuB,CAAC,YAAY,WAAW,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC;AACnF;ACLgB,SAAA,IAAI,YAAkC,aAAgC;AAChF,MAAA,CAAC,MAAM,IAAI;AAEf,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,IAAI,GAAG,KAAK;AACpC,cAAA,YAAY,IAAI,CAAC;AAC3B,cAAU,QAAQ,CAAC;AAAA,EACrB;AAEO,SAAA;AACT;AAQO,MAAM,OAAO;AAQb,MAAM,MAAM;AAQZ,MAAM,aAAa;AAQnB,MAAM,KAAK;AAKX,MAAM,WAAW;AAQjB,MAAM,KAAK;AAKX,MAAM,aAAa;ACzDV,SAAA,YAAe,WAAoB,UAA6B;AAC1E,MAAA;AACF,WAAO,UAAU;AAAA,EAAA,QACX;AACC,WAAA;AAAA,EACT;AACF;AAyCsB,eAAA,iBAAoB,WAA6B,UAAsC;AACvG,MAAA;AACF,WAAO,MAAM,UAAU;AAAA,EAAA,QACjB;AACC,WAAA;AAAA,EACT;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -374,7 +374,7 @@ const _ZTrilean = class _ZTrilean {
|
|
|
374
374
|
* and indeterminate if x is null.
|
|
375
375
|
*/
|
|
376
376
|
static stringify(x) {
|
|
377
|
-
return _ZTrilean.isIndeterminate(x) ?
|
|
377
|
+
return _ZTrilean.isIndeterminate(x) ? "indeterminate" : String(x);
|
|
378
378
|
}
|
|
379
379
|
/**
|
|
380
380
|
* Converts a string to a trilean value.
|
|
@@ -451,7 +451,7 @@ const _ZTrilean = class _ZTrilean {
|
|
|
451
451
|
return !!val;
|
|
452
452
|
}
|
|
453
453
|
};
|
|
454
|
-
_ZTrilean.Indeterminate = Symbol("indeterminate");
|
|
454
|
+
_ZTrilean.Indeterminate = Symbol("helpful-fn-indeterminate");
|
|
455
455
|
let ZTrilean = _ZTrilean;
|
|
456
456
|
class ZDeserializeJson {
|
|
457
457
|
constructor(_schema) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/anchor/anchor.mts","../src/assert/assert.mts","../src/count-buckets/count-buckets.mts","../src/create-error/create-error.mts","../src/create-guid/create-guid.mts","../src/first-where/first-where.mts","../src/geometry/quadrilateral.mts","../src/geometry/rectangle.mts","../src/global/global.mts","../src/join-defined/join-defined.mts","../src/obligation/obligation.mts","../src/orientation/orientation.mts","../src/peel/peel.mts","../src/schema/trilean.mts","../src/serialize/deserialize-json.mts","../src/serialize/deserialize-try.mts","../src/serialize/serialize-json.mts","../src/set-first/set-first.mts","../src/sleep/sleep.mts","../src/tag/tag.mts","../src/try-fallback/try-fallback.mts"],"sourcesContent":["/**\n * Represents a targeted point along a y axis.\n */\nexport enum ZVerticalAnchor {\n /**\n * Top boundary.\n *\n * In vertical device space, this would equate to y = 0.\n */\n Top = 'top',\n /**\n * Centerpoint between the top and bottom.\n */\n Middle = 'middle',\n /**\n * Bottom boundary.\n *\n * In vertical device space, this would equate to y = Infinity.\n */\n Bottom = 'bottom'\n}\n\n/**\n * Represents a targeted point along an x axis.\n */\nexport enum ZHorizontalAnchor {\n /**\n * Left boundary.\n *\n * In horizontal device space, this would equate to x = 0.\n */\n Left = 'left',\n /**\n * Centerpoint between the left and right boundary.\n */\n Center = 'center',\n /**\n * Right boundary.\n *\n * In horizontal device space, this would equate to x = Infinity.\n */\n Right = 'right'\n}\n\n/**\n * Represents an anchor point in 2d space.\n *\n * An anchor array is defined by [vertical, horizontal]\n * and is read as such.\n *\n * @example\n *\n * ```ts\n * const topCenter = [ZVerticalAnchor.Top, ZHorizontalAnchor.Center];\n * const bottomRight = [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Right];\n * ```\n *\n * @see {@link ZVerticalAnchor} For more information.\n * @see {@link ZHorizontalAnchor} For more information.\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 * Represents an object that can be used to build a list of assertions.\n *\n * @example\n *\n * ```ts\n * import { ZAssert, createError } from '@zthun/helpful-fn';\n *\n * const user = readUser();\n *\n * ZAssert\n * .claim(user.name != null, 'User name is required')\n * .claim(user.email != null, 'User email is required')\n * .assert((m) => createError(m));\n * ```\n */\nexport class ZAssert {\n /**\n * Initializes a new instance of a ZAssert with one claim.\n *\n * @param claim -\n * The claim to make.\n * @param msg -\n * The message to throw if the claim is false.\n *\n * @returns\n * A new ZAssert object with an initial claim.\n */\n public static claim(claim: boolean, msg: any): ZAssert {\n return new ZAssert().claim(claim, msg);\n }\n\n private _messages: any[] = [];\n\n /**\n * Initializes a new instance of this object.\n */\n private constructor() {}\n\n /**\n * Adds a claim.\n *\n * @param claim -\n * The claim predicate.\n * @param msg -\n * The message to add if the claim fails.\n *\n * @returns This object.\n */\n public claim(claim: boolean, msg: any): this {\n if (!claim) {\n this._messages.push(msg);\n }\n return this;\n }\n\n /**\n * Runs the assertion.\n *\n * @param fail -\n * The factory that is responsible for returning the specified error to throw.\n */\n public assert<E extends Error>(fail: (message: any | any[]) => E): void {\n if (this._messages.length === 1) {\n throw fail(this._messages[0]);\n }\n\n if (this._messages.length) {\n throw fail(this._messages);\n }\n }\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. If this value receives\n * Infinity, then it will result in 1 or min buckets being returned,\n * whichever is larger. If this receives NaN, then this method will\n * result in NaN. Finally, if this receives a negative value, then\n * the result will be max.\n * @param items -\n * The total number of items you need to store where each item\n * counts as 1 towards the weight. If the total number of items\n * is Infinity, then this method will result in max buckets.\n * If this receives NaN, then this method will result in NaN. Finally,\n * if you pass 0, or a negative number of items, then result will be min.\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 * The default is 0.\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 * The default is Infinity.\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 *\n * @example\n *\n * ```ts\n * // The following will return 5 for numberOfPages since you need 5 buckets\n * // to store 101 number of items where each bucket can hold a max of 25\n * // items. The 5th page would be a page of 1 item, since 1 is the remainder.\n * const numberOfPages = countBuckets(25, 101);\n *\n * // In this case, the numberOfPages would be 1 here since our minimum buckets\n * // is 1. By default, this would be 0.\n * const numberOfPages = countBuckets(10, 0, 1);\n *\n * // In this case, we have more items that can be held in the number of buckets\n * // available, so only 4 is returned instead of the 5.\n * const numberOfPages = countBuckets(25, 101, undefined, 4);\n * ```\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]. By default, the schema will look for properties\n * named, message, error, exception, and data, in that order.\n *\n * @returns\n * An error object that is the best evaluation of what the problem actually is.\n *\n * @example\n *\n * ```ts\n * // All of these result an Error with the message, 'Something went wrong'\n * const errorWithStringProblem = createError('Something went wrong');\n * const errorWithObjectProblemInSchema = createError({ error: 'Something went wrong'});\n * const errorWithCustomSchema = createError({ issue: 'Something went wrong'}, ['issue']);\n * const errorRecursive = createError({ error: { message: 'Something went wrong' }});\n *\n * // This would result in '[Object object]' as there is no way to figure out how to deconstruct this problem.\n * const errorCannotBeFound = createError({ wut: 'Something went wrong' });\n * ```\n */\nexport function createError(problem: any, schema = ['message', 'error', 'exception', 'data']): 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 * The identifier holds to v4 of the UUID specification. A summary\n * of the specification can be found at\n * {@link https://commons.apache.org/sandbox/commons-id/uuid.html | Apache Commons UUID Documentation}.\n *\n * The official documentation of the UUID specification is under\n * {@link https://www.rfc-editor.org/info/rfc4122 | RFC 4122}\n *\n * @returns\n * A new generated globally unique identifier based on random bytes.\n *\n * @example\n *\n * ```ts\n * // Will get a value similar to 53e33fb6-d05a-4fa9-8dc0-b78e4feaa702\n * const guidA = createGuid();\n * // Will most likely not ever be equal to guidA\n * const guidB = createGuid();\n * ```\n */\nexport const createGuid: () => string = v4;\n","/**\n * Returns the first value in an argument list that matches a predicate.\n *\n * @param predicate -\n * The match method against each value argument.\n * @param fallback -\n * The fallback value in the case that all arguments fail\n * the predicate.\n * @param first -\n * The first value to check.\n * @param remaining -\n * The remaining values beyond the first to check.\n * @param T -\n * The type of data that will be enumerated.\n *\n * @returns\n * The first value for where {@link predicate} returns true for the given argument value.\n * If first and all values of remaining fail the predicate then fallback is returned.\n */\nexport function firstWhere<T = any>(\n predicate: (v: T | null | undefined) => boolean,\n fallback: T,\n first: T,\n ...remaining: T[]\n): T {\n if (predicate(first)) {\n return first;\n }\n\n for (let i = 0; i < remaining.length; ++i) {\n const val = remaining[i];\n\n if (predicate(val)) {\n return val;\n }\n }\n\n return fallback;\n}\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 * @param T -\n * The type of data that will be enumerated.\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 *\n * @example\n *\n * ```ts\n * // 'Defined'\n * const shouldBeDefined = firstDefined('Fallback', null, undefined, 'Defined');\n * // 'Fallback'\n * const shouldBeFallback = firstDefined('Fallback', null, undefined);\n * const shouldAlsoBeFallback = firstDefined('Fallback', undefined);\n * // 'First'\n * const shouldBeFirst = firstDefined('Fallback', 'First', null, 'Third');\n * ```\n */\nexport function firstDefined<T = any>(\n fallback: T,\n first: T | null | undefined,\n ...remaining: (T | null | undefined)[]\n): T {\n return firstWhere<T | null | undefined>((v) => v != null, fallback, first, ...remaining) as T;\n}\n\n/**\n * Returns the first value in args such that args is truthy\n *\n * @param fallback -\n * The fallback value in the case that all values in args are falsy.\n * @param first -\n * The first value to check.\n * @param remaining -\n * The remaining values beyond the first to check.\n * @param T -\n * The type of data that will be enumerated.\n *\n * @returns\n * The first value if it is truthy. If first is falsy, then the first item\n * in remaining such that remaining[i] is truthy is returned. If first and\n * all values of remaining are falsy, then fallback is returned.\n *\n * @example\n *\n * ```ts\n * // 'Defined'\n * const shouldBeDefined = firstTruthy('Fallback', null, undefined, 'Defined');\n * // 'Fallback'\n * const shouldBeFallback = firstTruthy('Fallback', '', undefined);\n * const shouldAlsoBeFallback = firstDefined('Fallback', 0, false);\n * // 'First'\n * const shouldBeFirst = firstDefined('Fallback', 'First', null, false, 0, NaN);\n * ```\n */\nexport function firstTruthy<T = any>(\n fallback: T,\n first: T | null | undefined,\n ...remaining: (T | null | undefined)[]\n): T {\n return firstWhere<T | null | undefined>((v) => !!v, fallback, first, ...remaining) as T;\n}\n","/**\n * Represents a object of 4 side values.\n *\n * @param T -\n * Value type. Typically number.\n */\nexport interface IZQuadrilateral<T = number> {\n /**\n * Bottom value.\n */\n bottom: T;\n /**\n * Left value.\n */\n left: T;\n /**\n * Right value.\n */\n right: T;\n /**\n * Top value.\n */\n top: T;\n}\n\n/**\n * Represents a builder for a quadrilateral object.\n */\nexport class ZQuadrilateralBuilder<T = number> {\n private _quad: IZQuadrilateral<T>;\n\n /**\n * Initializes a new instance of this object.\n *\n * @param start -\n * The starting value.\n */\n public constructor(start: T) {\n this._quad = {\n bottom: start,\n left: start,\n right: start,\n top: start\n };\n }\n\n /**\n * Sets the bottom value.\n *\n * @param bottom -\n * The bottom value.\n *\n * @returns\n * This object.\n */\n public bottom(bottom: T): this {\n this._quad.bottom = bottom;\n return this;\n }\n\n /**\n * Sets the left value.\n *\n * @param left -\n * The left value.\n *\n * @returns\n * This object.\n */\n public left(left: T): this {\n this._quad.left = left;\n return this;\n }\n\n /**\n * Sets the right value.\n *\n * @param right -\n * The right value.\n *\n * @returns\n * This object.\n */\n public right(right: T): this {\n this._quad.right = right;\n return this;\n }\n\n /**\n * Sets the top value.\n *\n * @param top -\n * The top value.\n *\n * @returns\n * This object.\n */\n public top(top: T): this {\n this._quad.top = top;\n return this;\n }\n\n /**\n * Sets the left and right value.\n *\n * @param x -\n * The left and right value.\n *\n * @returns\n * This object.\n */\n public x(x: T): this {\n return this.left(x).right(x);\n }\n\n /**\n * Sets the top and bottom value.\n *\n * @param y -\n * The top and bottom value.\n *\n * @returns\n * This object.\n */\n public y(y: T): this {\n return this.bottom(y).top(y);\n }\n\n /**\n * Copies another quadrilateral object into the current instance.\n *\n * @param other -\n * The quadrilateral object to copy.\n *\n * @returns\n * This object.\n */\n public copy(other: IZQuadrilateral<T>): this {\n this._quad = structuredClone(other);\n return this;\n }\n\n /**\n * Returns the built quadrilateral object.\n *\n * @returns\n * The built quadrilateral.\n */\n public build(): IZQuadrilateral<T> {\n return structuredClone(this._quad);\n }\n}\n","import { ZAnchor, ZHorizontalAnchor, ZVerticalAnchor } from '../anchor/anchor.mjs';\nimport { IZPoint2d } from './point.mjs';\nimport { IZQuadrilateral } from './quadrilateral.mjs';\n\n/**\n * Represents a helper object that can run calculations on a numeric quadrilateral.\n */\nexport class ZRectangle {\n /**\n * Initializes a new instance of this object.\n *\n * @param sides -\n * The numeric sides of a quadrilateral.\n */\n public constructor(public readonly sides: IZQuadrilateral) {}\n\n /**\n * Calculates the width of the rectangle.\n *\n * @returns\n * The numeric width of the rectangle.\n */\n public width(): number {\n const { left, right } = this.sides;\n return right - left;\n }\n\n /**\n * Calculates the height of the rectangle.\n *\n * @returns\n * The numeric height of the rectangle.\n */\n public height(): number {\n const { top, bottom } = this.sides;\n return bottom - top;\n }\n\n /**\n * Calculates the area of the rectangle.\n *\n * @returns\n * The numeric area of the rectangle.\n */\n public area(): number {\n return this.width() * this.height();\n }\n\n /**\n * Calculates the (x, y) point given an anchor target.\n *\n * @param anchor -\n * The anchor target to calculate the point for.\n *\n * @returns\n * The numeric width of the rectangle.\n */\n public point(anchor: ZAnchor): IZPoint2d {\n const { bottom, left, right, top } = this.sides;\n const [vertical, horizontal] = anchor;\n\n const v: Record<ZVerticalAnchor, number> = {\n [ZVerticalAnchor.Top]: top,\n [ZVerticalAnchor.Middle]: (bottom + top) / 2,\n [ZVerticalAnchor.Bottom]: bottom\n };\n\n const h: Record<ZHorizontalAnchor, number> = {\n [ZHorizontalAnchor.Left]: left,\n [ZHorizontalAnchor.Center]: (right + left) / 2,\n [ZHorizontalAnchor.Right]: right\n };\n\n return { x: h[horizontal], y: v[vertical] };\n }\n\n /**\n * Calculates the top left point of the rectangle.\n *\n * @returns\n * The top left point of the rectangle.\n */\n public topLeft = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Left]);\n /**\n * Calculates the top center point of the rectangle.\n *\n * @returns\n * The top center point of the rectangle.\n */\n public topCenter = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Center]);\n /**\n * Calculates the top right point of the rectangle.\n *\n * @returns\n * The top right point of the rectangle.\n */\n public topRight = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Right]);\n /**\n * Calculates the middle left point of the rectangle.\n *\n * @returns\n * The middle left point of the rectangle.\n */\n public middleLeft = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Left]);\n /**\n * Calculates the middle center point of the rectangle.\n *\n * @returns\n * The middle center point of the rectangle.\n */\n public middleCenter = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Center]);\n /**\n * Calculates the middle right point of the rectangle.\n *\n * @returns\n * The middle right point of the rectangle.\n */\n public middleRight = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Right]);\n /**\n * Calculates the bottom left point of the rectangle.\n *\n * @returns\n * The bottom left point of the rectangle.\n */\n public bottomLeft = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Left]);\n /**\n * Calculates the bottom center point of the rectangle.\n *\n * @returns\n * The bottom center point of the rectangle.\n */\n public bottomCenter = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Center]);\n /**\n * Calculates the bottom right point of the rectangle.\n *\n * @returns\n * The bottom right point of the rectangle.\n */\n public bottomRight = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Right]);\n}\n","/* istanbul ignore next -- @preserve */\nexport const $global = typeof window === 'undefined' ? global : window;\n","/**\n * A set of parameters that can be used for a string join.\n *\n * Join lists can be a regular object, null, undefined, or a tuple where the\n * first item is the object to join, and the second item is a boolean that specifies\n * whether to include it if the value is truthy.\n *\n * @param T -\n * The type of data to join.\n */\nexport type JoinListInputParameter<T> = T | [T, boolean] | null | undefined;\n\n/**\n * Similar to {@link Array.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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by delimiter.\n *\n * @example\n *\n * ```ts\n * // 'a b d'\n * const joinBySpace = joinDefined(' ', 'a', 'b', ['c', false], null, undefined, ['d', true]);\n * // (Empty String)\n * const joinEmpty = joinDefined('?');\n * ```\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 space delimiter.\n *\n * @param items -\n * The items to join.\n * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by space delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a space delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a comma delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a semi-colon delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a pipe delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\n */\nexport const pipeJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, '|');\n","/**\n * A specific set of possible values that need to be checked for requirements.\n *\n * @param T -\n * The type of value that is being checked.\n */\nexport type ZObligatedValue<T> = T | null | undefined | Promise<T | null | undefined>;\n\n/**\n * Requires a value to be non null.\n *\n * @param val -\n * The value to require. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, an error is thrown.\n *\n * @throws\n * An error if the value is null or undefined.\n */\nexport async function required<T>(val: ZObligatedValue<T>): Promise<T> {\n if (val == null) {\n throw new Error('A required value was not provided');\n }\n\n const _val = await val;\n\n if (_val == null) {\n throw new Error('A required value was not provided');\n }\n\n return _val;\n}\n\n/**\n * Allows a value to be null or undefined and has a fallback.\n *\n * @param val -\n * The value to check. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param fallback -\n * The fallback value in the case that val is\n * null or undefined.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, the fallback is returned.\n * If val is a promise and rejects, then fallback is\n * also returned.\n */\nexport function optional<T>(val: ZObligatedValue<T>, fallback: T): Promise<T>;\n\n/**\n * Allows a value to be null or undefined and has a fallback.\n *\n * @param val -\n * The value to check. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, null is returned.\n * If val is a promise and rejects, then null is\n * also returned.\n */\nexport function optional<T>(val: ZObligatedValue<T>): Promise<T | null>;\n\n/**\n * Allows a value to be null or undefined and has a fallback.\n *\n * @param val -\n * The value to check. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param fallback -\n * The fallback value in the case that val is\n * null or undefined.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, the fallback is returned.\n * If val is a promise and rejects, then fallback is\n * also returned.\n */\nexport async function optional<T>(val: ZObligatedValue<T>, fallback: T | null = null): Promise<T | null> {\n if (val == null) {\n return fallback;\n }\n\n try {\n const _val = await val;\n return _val == null ? fallback : _val;\n } catch {\n return fallback;\n }\n}\n","/**\n * Represents a direction orientation.\n */\nexport enum ZOrientation {\n /**\n * Horizontal 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 * Peels a candidate string from the start of a string and splits it into two segments.\n *\n * @param str -\n * The string to peel from.\n * @param candidates -\n * The candidate list of values to peel from str.\n *\n * @returns\n * A tuple where the first item is the peeled string and\n * the second item is the remainder of the string. If the string\n * does not start with any given candidates, then the first\n * item will be null and the second item will be str.\n */\nexport function peel<T extends string = string>(str: string, candidates: T[]): [T | null, string] {\n for (const check of candidates) {\n if (str.startsWith(check)) {\n return [str.substring(0, check.length) as T, str.substring(check.length)];\n }\n }\n\n return [null, str];\n}\n\n/**\n * Peels the values between an opening string set and a closing string set.\n *\n * The actual value will handle issues with internal opening and closing brackets\n *\n * @example\n *\n * ```ts\n * const [peeled, rest] = peelBetween('[a, b, [c1, c2],[d]] other', '[' ']');\n *\n * // Outputs 'a, b, [c1, c2], [d]'\n * console.log(peeled);\n *\n * // Outputs ' other' - white space is included'\n * console.log(rest);\n * ```\n *\n * @param str -\n * The string to peel between.\n * @param open -\n * The opening string. This will test\n * at the start of str.\n * @param close -\n * The closing string. This can be anywhere\n * in the str. If this is equal to open, then\n * the open string is removed from the start of the\n * string and the rest of the string would be returned.\n *\n * @returns\n * A tuple where the first argument is string that was found between\n * the opening and closing bracket. Returns null if no string could\n * be found between an open and close pair. The second argument will\n * be the remaining text of the string, including whitespace.\n */\nexport function peelBetween(str: string, open: string, close: string): [string | null, string] {\n if (!str.startsWith(open)) {\n return [null, str];\n }\n\n let stack = 1;\n\n const _str = str.substring(open.length);\n\n for (let i = 0; i < _str.length; ++i) {\n if (_str.startsWith(open, i)) {\n stack += 1;\n i += open.length - 1;\n continue;\n }\n\n if (_str.startsWith(close, i)) {\n stack -= 1;\n\n if (stack === 0) {\n return [_str.substring(0, i), _str.substring(i + close.length)];\n }\n\n i += close.length - 1;\n }\n }\n\n return [null, str];\n}\n","/**\n * Represents a tri logic state.\n *\n * See {@link ZTrilean.Indeterminate} for what the symbol value should be.\n *\n * @deprecated Use the one found in [\\@zthun/trilean](https://www.npmjs.com/package/\\@zthun/trilean) instead.\n */\nexport type trilean = boolean | symbol;\n\n/**\n * A utility class for trilean values.\n *\n * @deprecated Use the one found in [\\@zthun/trilean](https://www.npmjs.com/package/\\@zthun/trilean) instead.\n */\nexport abstract class ZTrilean {\n /**\n * A unique value for the third, indeterminate, state.\n */\n public static readonly Indeterminate = Symbol('indeterminate');\n\n /**\n * Converts a trilean value to a string.\n *\n * @param x -\n * The value to convert.\n *\n * @returns\n * A string of true if x is true, false if x is false,\n * and indeterminate if x is null.\n */\n public static stringify(x: trilean): string {\n return ZTrilean.isIndeterminate(x) ? x.description! : String(x);\n }\n\n /**\n * Converts a string to a trilean value.\n *\n * @param str -\n * The text to parse.\n * @param fallback -\n * The fallback in the case that str is not a parsable value.\n *\n * @returns\n * The parsed trilean value or fallback if str is not a valid\n * trilean value.\n */\n public static parse(str: string | null | undefined, fallback: trilean = false): trilean {\n if (str?.toUpperCase().localeCompare('TRUE') === 0) {\n return true;\n }\n\n if (str?.toUpperCase().localeCompare('FALSE') === 0) {\n return false;\n }\n\n if (str?.toUpperCase().localeCompare('INDETERMINATE') === 0) {\n return ZTrilean.Indeterminate;\n }\n\n return fallback;\n }\n\n /**\n * Gets a value that determines if val is a trilean supported value.\n *\n * @param val -\n * The value to test.\n *\n * @returns\n * True if val is a trilean value. False otherwise.\n */\n public static is(val: any): val is trilean {\n return typeof val === 'boolean' || ZTrilean.isIndeterminate(val);\n }\n\n /**\n * Gets whether val is the indeterminate value.\n */\n public static isIndeterminate(val: trilean): val is symbol {\n return val === ZTrilean.Indeterminate;\n }\n\n /**\n * Converts from a value to a trilean value.\n *\n * This is similar to parse, but it also supports non\n * string inputs which will be converted to a boolean.\n *\n * @param val -\n * The value to convert.\n * @param fallback -\n * The fallback value in the case that val cannot be converted. This will\n * only be used in the case that val is a string, null, or undefined.\n *\n * @returns\n * The trilean value of val. If val is null or undefined, then\n * fallback is returned. If val is a string, then the return value of\n * {@link parse} will be used. If val is a boolean, then it will be\n * directly returned. If val is equal to {@link Indeterminate}, then\n * {@link Indeterminate} will be returned. Otherwise, the truthy\n * nature of value will be returned.\n */\n public static convert(val: any, fallback: trilean = false): trilean {\n if (val == null) {\n return fallback;\n }\n\n if (ZTrilean.is(val)) {\n return val;\n }\n\n if (typeof val === 'string') {\n return ZTrilean.parse(val, fallback);\n }\n\n return !!val;\n }\n}\n","import { IZDeserialize } from './deserialize.mjs';\n\n/**\n * A deserializer that deserializes a JSON string.\n */\nexport class ZDeserializeJson<T> implements IZDeserialize<T> {\n public constructor(private _schema?: (k: any) => k is T) {}\n\n public deserialize(candidate: string): T {\n const parsed = JSON.parse(candidate);\n\n if (this._schema && !this._schema(parsed)) {\n throw new Error('The parsed JSON does not conform to the given schema requirement');\n }\n\n return parsed;\n }\n}\n","import { IZDeserialize } from './deserialize.mjs';\n\n/**\n * A deserializer that attempts to deserialize multiple times through a series of supported languages.\n *\n * @param T -\n * The type of data to deserialize.\n * @param S -\n * The input type\n */\nexport class ZDeserializeTry<T, S = string> implements IZDeserialize<T, S> {\n /**\n * Initializes a new instance of this object.\n *\n * @param _children -\n * The list of deserializer objects to try on a specific candidate.\n * The first deserializer to succeed will return the target object.\n * If no deserializer is able to deserialize the candidate, then an\n * error is throw with a mapping of serialization errors between each\n * deserializer.\n */\n public constructor(private _children: IZDeserialize<T, S>[]) {}\n\n public deserialize(candidate: S): T {\n const errors: string[] = [];\n\n for (const child of this._children) {\n try {\n return child.deserialize(candidate);\n } catch (e) {\n errors.push(e.message);\n }\n }\n\n const msg = `Unable to deserialize candidate, ${candidate}.`;\n errors.splice(0, 0, msg);\n throw new Error(errors.join('\\n\\n'));\n }\n}\n","import { IZSerialize } from './serialize.mjs';\n\n/**\n * Represents a serializer that serializes anything to a JSON string.\n */\nexport class ZSerializeJson implements IZSerialize<any> {\n public serialize(candidate: any): string | undefined {\n return JSON.stringify(candidate, undefined, 2);\n }\n}\n","/**\n * Represents a setter function for when you want to set a single value,\n * 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. This is primarily meant\n * to be use with bind to construct a new method setter that takes an array\n * and forwards it to a setter method which will accept a single value of the\n * first item in the target value.\n *\n * @param setValue -\n * The setter function that takes a single value. This will receive\n * the first item of the value list.\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 * @param T -\n * The type of data that the array holds.\n *\n * @example\n *\n * ```ts\n * // An example of a react component that needs a value of an array, but you only care about a single selection.\n * const [value, setValue] = useState<TypesOfPie>();\n * const _values = useMemo(() => value ? [value] : [], [value]);\n * const _setValues = setFirst.bind(null, setValue, undefined);\n *\n * return <ComponentWithMultiSelectSupport values={_values} onValuesChange={_setValues} />\n * ```\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 * @param T -\n * The type of value that will be resolved.\n *\n * @returns\n * A promise that resolves with val 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 * @param T -\n * The type of value that will be resolved.\n *\n * @returns\n * A promise that resolves with val 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","/**\n * This is just a method that allows you to tag an interpolation\n * string as a syntax language.\n *\n * This is useful with IDE extensions that can detect the language\n * and do the syntax highlighting for you.\n *\n * @param strings -\n * The string breaks for interpolation.\n * @param expressions -\n * The equivalent expressions that break apart\n * the single string literal.\n *\n * @returns\n * The compiled string literal. This is no different\n * than letting native JavaScript do it for you.\n *\n * @example\n *\n * ```ts\n * const html = tag;\n * const css = tag;\n *\n * const $html = html`\n * <div>Some IDE extensions will highlight this as html</div>\n * `\n *\n * const $css = css`\n * button {\n * display: grid;\n * }\n * `\n * ```\n */\nexport function tag(strings: TemplateStringsArray, ...expressions: unknown[]): string {\n let [result] = strings;\n\n for (let i = 1, l = strings.length; i < l; i++) {\n result += expressions[i - 1];\n result += strings[i];\n }\n\n return result;\n}\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=Tobermory.es6-string-html | IDE extensions will detect the string}\n * interpolation as html when using this tag.\n */\nexport const html = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=bashmish.es6-string-css | IDE extensions will detect the string}\n * interpolation as css when using this tag.\n */\nexport const css = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=zjcompt.es6-string-javascript | IDE extensions will detect the string}\n * interpolation as javascript when using this tag.\n */\nexport const javascript = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=jeoht.es6-string-markdown | IDE extensions will detect the string}\n * interpolation as markdown when using this tag.\n */\nexport const md = tag;\n\n/**\n * See {@link md}\n */\nexport const markdown = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=HoodieCollin.es6-string-typescript | IDE extensions will detect the string}\n * interpolation as typescript when using this tag.\n */\nexport const ts = tag;\n\n/**\n * See {@link ts}\n */\nexport const typescript = tag;\n","/**\n * Invokes the candidate function and returns undefined if an error is thrown from it.\n *\n * @param candidate -\n * The candidate function to run.\n *\n * @returns\n * The result from candidate. Returns undefined if candidate throws an Error.\n */\nexport function tryFallback<T>(candidate: () => T): T | undefined;\n\n/**\n * Invokes the candidate function and returns fallback if an error is thrown from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The fallback value to return if candidate throws an error.\n *\n * @returns\n * The result from candidate. Returns fallback if candidate throws an Error.\n */\nexport function tryFallback<T>(candidate: () => T, fallback: T): T;\n\n/**\n * Invokes the candidate function and returns fallback if an error is thrown from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The fallback value to return if candidate throws an error.\n *\n * @returns\n * The result from candidate. Returns fallback if candidate throws an Error.\n * If no fallback value is provided, then undefined is returned.\n */\nexport function tryFallback<T>(candidate: () => T, fallback?: T): T | undefined {\n try {\n return candidate();\n } catch {\n return fallback;\n }\n}\n\n/**\n * Invokes the candidate function and returns undefined if an rejected promise is returned from it.\n *\n * @param candidate -\n * The candidate function to run.\n *\n * @returns\n * A promise that resolves with the result from candidate. Returns undefined\n * if candidate returns a rejected promise.\n */\nexport function tryFallbackAsync<T>(candidate: () => Promise<T>): Promise<T | undefined>;\n\n/**\n * Invokes the candidate function and returns undefined if an rejected promise is returned from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The fallback value that will be returned if candidate returns a rejected promise.\n *\n * @returns\n * A promise that resolves with the result from candidate. Returns fallback\n * if candidate returns a rejected promise.\n */\nexport function tryFallbackAsync<T>(candidate: () => Promise<T>, fallback: T): Promise<T>;\n\n/**\n * Invokes the candidate function and returns undefined if an rejected promise is returned from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The optional fallback value to return if the candidate throws an Error.\n *\n * @returns\n * A promise that resolves with the result from candidate or fallback\n * if candidate returns a rejected promise. Resolves with undefined\n * if no fallback is provided.\n */\nexport async function tryFallbackAsync<T>(candidate: () => Promise<T>, fallback?: T): Promise<T | undefined> {\n try {\n return await candidate();\n } catch {\n return fallback;\n }\n}\n"],"names":["ZVerticalAnchor","ZHorizontalAnchor","ZOrientation"],"mappings":";AAGY,IAAA,oCAAAA,qBAAL;AAMLA,mBAAA,KAAM,IAAA;AAINA,mBAAA,QAAS,IAAA;AAMTA,mBAAA,QAAS,IAAA;AAhBCA,SAAAA;AAAA,GAAA,mBAAA,CAAA,CAAA;AAsBA,IAAA,sCAAAC,uBAAL;AAMLA,qBAAA,MAAO,IAAA;AAIPA,qBAAA,QAAS,IAAA;AAMTA,qBAAA,OAAQ,IAAA;AAhBEA,SAAAA;AAAA,GAAA,qBAAA,CAAA,CAAA;ACTL,MAAM,QAAQ;AAAA;AAAA;AAAA;AAAA,EAqBX,cAAc;AALtB,SAAQ,YAAmB;EAKJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EATvB,OAAc,MAAM,OAAgB,KAAmB;AACrD,WAAO,IAAI,QAAU,EAAA,MAAM,OAAO,GAAG;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBO,MAAM,OAAgB,KAAgB;AAC3C,QAAI,CAAC,OAAO;AACL,WAAA,UAAU,KAAK,GAAG;AAAA,IACzB;AACO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,SAAS,MAAS,KAAK,GAAG,MAAqB,QAAmC;AAChF,SAAA,IAAI,QAAuB,CAAC,YAAY,WAAW,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC;AACnF;ACLgB,SAAA,IAAI,YAAkC,aAAgC;AAChF,MAAA,CAAC,MAAM,IAAI;AAEf,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,IAAI,GAAG,KAAK;AACpC,cAAA,YAAY,IAAI,CAAC;AAC3B,cAAU,QAAQ,CAAC;AAAA,EACrB;AAEO,SAAA;AACT;AAQO,MAAM,OAAO;AAQb,MAAM,MAAM;AAQZ,MAAM,aAAa;AAQnB,MAAM,KAAK;AAKX,MAAM,WAAW;AAQjB,MAAM,KAAK;AAKX,MAAM,aAAa;ACzDV,SAAA,YAAe,WAAoB,UAA6B;AAC1E,MAAA;AACF,WAAO,UAAU;AAAA,EAAA,QACX;AACC,WAAA;AAAA,EACT;AACF;AAyCsB,eAAA,iBAAoB,WAA6B,UAAsC;AACvG,MAAA;AACF,WAAO,MAAM,UAAU;AAAA,EAAA,QACjB;AACC,WAAA;AAAA,EACT;AACF;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/anchor/anchor.mts","../src/assert/assert.mts","../src/count-buckets/count-buckets.mts","../src/create-error/create-error.mts","../src/create-guid/create-guid.mts","../src/first-where/first-where.mts","../src/geometry/quadrilateral.mts","../src/geometry/rectangle.mts","../src/global/global.mts","../src/join-defined/join-defined.mts","../src/obligation/obligation.mts","../src/orientation/orientation.mts","../src/peel/peel.mts","../src/schema/trilean.mts","../src/serialize/deserialize-json.mts","../src/serialize/deserialize-try.mts","../src/serialize/serialize-json.mts","../src/set-first/set-first.mts","../src/sleep/sleep.mts","../src/tag/tag.mts","../src/try-fallback/try-fallback.mts"],"sourcesContent":["/**\n * Represents a targeted point along a y axis.\n */\nexport enum ZVerticalAnchor {\n /**\n * Top boundary.\n *\n * In vertical device space, this would equate to y = 0.\n */\n Top = 'top',\n /**\n * Centerpoint between the top and bottom.\n */\n Middle = 'middle',\n /**\n * Bottom boundary.\n *\n * In vertical device space, this would equate to y = Infinity.\n */\n Bottom = 'bottom'\n}\n\n/**\n * Represents a targeted point along an x axis.\n */\nexport enum ZHorizontalAnchor {\n /**\n * Left boundary.\n *\n * In horizontal device space, this would equate to x = 0.\n */\n Left = 'left',\n /**\n * Centerpoint between the left and right boundary.\n */\n Center = 'center',\n /**\n * Right boundary.\n *\n * In horizontal device space, this would equate to x = Infinity.\n */\n Right = 'right'\n}\n\n/**\n * Represents an anchor point in 2d space.\n *\n * An anchor array is defined by [vertical, horizontal]\n * and is read as such.\n *\n * @example\n *\n * ```ts\n * const topCenter = [ZVerticalAnchor.Top, ZHorizontalAnchor.Center];\n * const bottomRight = [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Right];\n * ```\n *\n * @see {@link ZVerticalAnchor} For more information.\n * @see {@link ZHorizontalAnchor} For more information.\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 * Represents an object that can be used to build a list of assertions.\n *\n * @example\n *\n * ```ts\n * import { ZAssert, createError } from '@zthun/helpful-fn';\n *\n * const user = readUser();\n *\n * ZAssert\n * .claim(user.name != null, 'User name is required')\n * .claim(user.email != null, 'User email is required')\n * .assert((m) => createError(m));\n * ```\n */\nexport class ZAssert {\n /**\n * Initializes a new instance of a ZAssert with one claim.\n *\n * @param claim -\n * The claim to make.\n * @param msg -\n * The message to throw if the claim is false.\n *\n * @returns\n * A new ZAssert object with an initial claim.\n */\n public static claim(claim: boolean, msg: any): ZAssert {\n return new ZAssert().claim(claim, msg);\n }\n\n private _messages: any[] = [];\n\n /**\n * Initializes a new instance of this object.\n */\n private constructor() {}\n\n /**\n * Adds a claim.\n *\n * @param claim -\n * The claim predicate.\n * @param msg -\n * The message to add if the claim fails.\n *\n * @returns This object.\n */\n public claim(claim: boolean, msg: any): this {\n if (!claim) {\n this._messages.push(msg);\n }\n return this;\n }\n\n /**\n * Runs the assertion.\n *\n * @param fail -\n * The factory that is responsible for returning the specified error to throw.\n */\n public assert<E extends Error>(fail: (message: any | any[]) => E): void {\n if (this._messages.length === 1) {\n throw fail(this._messages[0]);\n }\n\n if (this._messages.length) {\n throw fail(this._messages);\n }\n }\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. If this value receives\n * Infinity, then it will result in 1 or min buckets being returned,\n * whichever is larger. If this receives NaN, then this method will\n * result in NaN. Finally, if this receives a negative value, then\n * the result will be max.\n * @param items -\n * The total number of items you need to store where each item\n * counts as 1 towards the weight. If the total number of items\n * is Infinity, then this method will result in max buckets.\n * If this receives NaN, then this method will result in NaN. Finally,\n * if you pass 0, or a negative number of items, then result will be min.\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 * The default is 0.\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 * The default is Infinity.\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 *\n * @example\n *\n * ```ts\n * // The following will return 5 for numberOfPages since you need 5 buckets\n * // to store 101 number of items where each bucket can hold a max of 25\n * // items. The 5th page would be a page of 1 item, since 1 is the remainder.\n * const numberOfPages = countBuckets(25, 101);\n *\n * // In this case, the numberOfPages would be 1 here since our minimum buckets\n * // is 1. By default, this would be 0.\n * const numberOfPages = countBuckets(10, 0, 1);\n *\n * // In this case, we have more items that can be held in the number of buckets\n * // available, so only 4 is returned instead of the 5.\n * const numberOfPages = countBuckets(25, 101, undefined, 4);\n * ```\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]. By default, the schema will look for properties\n * named, message, error, exception, and data, in that order.\n *\n * @returns\n * An error object that is the best evaluation of what the problem actually is.\n *\n * @example\n *\n * ```ts\n * // All of these result an Error with the message, 'Something went wrong'\n * const errorWithStringProblem = createError('Something went wrong');\n * const errorWithObjectProblemInSchema = createError({ error: 'Something went wrong'});\n * const errorWithCustomSchema = createError({ issue: 'Something went wrong'}, ['issue']);\n * const errorRecursive = createError({ error: { message: 'Something went wrong' }});\n *\n * // This would result in '[Object object]' as there is no way to figure out how to deconstruct this problem.\n * const errorCannotBeFound = createError({ wut: 'Something went wrong' });\n * ```\n */\nexport function createError(problem: any, schema = ['message', 'error', 'exception', 'data']): 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 * The identifier holds to v4 of the UUID specification. A summary\n * of the specification can be found at\n * {@link https://commons.apache.org/sandbox/commons-id/uuid.html | Apache Commons UUID Documentation}.\n *\n * The official documentation of the UUID specification is under\n * {@link https://www.rfc-editor.org/info/rfc4122 | RFC 4122}\n *\n * @returns\n * A new generated globally unique identifier based on random bytes.\n *\n * @example\n *\n * ```ts\n * // Will get a value similar to 53e33fb6-d05a-4fa9-8dc0-b78e4feaa702\n * const guidA = createGuid();\n * // Will most likely not ever be equal to guidA\n * const guidB = createGuid();\n * ```\n */\nexport const createGuid: () => string = v4;\n","/**\n * Returns the first value in an argument list that matches a predicate.\n *\n * @param predicate -\n * The match method against each value argument.\n * @param fallback -\n * The fallback value in the case that all arguments fail\n * the predicate.\n * @param first -\n * The first value to check.\n * @param remaining -\n * The remaining values beyond the first to check.\n * @param T -\n * The type of data that will be enumerated.\n *\n * @returns\n * The first value for where {@link predicate} returns true for the given argument value.\n * If first and all values of remaining fail the predicate then fallback is returned.\n */\nexport function firstWhere<T = any>(\n predicate: (v: T | null | undefined) => boolean,\n fallback: T,\n first: T,\n ...remaining: T[]\n): T {\n if (predicate(first)) {\n return first;\n }\n\n for (let i = 0; i < remaining.length; ++i) {\n const val = remaining[i];\n\n if (predicate(val)) {\n return val;\n }\n }\n\n return fallback;\n}\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 * @param T -\n * The type of data that will be enumerated.\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 *\n * @example\n *\n * ```ts\n * // 'Defined'\n * const shouldBeDefined = firstDefined('Fallback', null, undefined, 'Defined');\n * // 'Fallback'\n * const shouldBeFallback = firstDefined('Fallback', null, undefined);\n * const shouldAlsoBeFallback = firstDefined('Fallback', undefined);\n * // 'First'\n * const shouldBeFirst = firstDefined('Fallback', 'First', null, 'Third');\n * ```\n */\nexport function firstDefined<T = any>(\n fallback: T,\n first: T | null | undefined,\n ...remaining: (T | null | undefined)[]\n): T {\n return firstWhere<T | null | undefined>((v) => v != null, fallback, first, ...remaining) as T;\n}\n\n/**\n * Returns the first value in args such that args is truthy\n *\n * @param fallback -\n * The fallback value in the case that all values in args are falsy.\n * @param first -\n * The first value to check.\n * @param remaining -\n * The remaining values beyond the first to check.\n * @param T -\n * The type of data that will be enumerated.\n *\n * @returns\n * The first value if it is truthy. If first is falsy, then the first item\n * in remaining such that remaining[i] is truthy is returned. If first and\n * all values of remaining are falsy, then fallback is returned.\n *\n * @example\n *\n * ```ts\n * // 'Defined'\n * const shouldBeDefined = firstTruthy('Fallback', null, undefined, 'Defined');\n * // 'Fallback'\n * const shouldBeFallback = firstTruthy('Fallback', '', undefined);\n * const shouldAlsoBeFallback = firstDefined('Fallback', 0, false);\n * // 'First'\n * const shouldBeFirst = firstDefined('Fallback', 'First', null, false, 0, NaN);\n * ```\n */\nexport function firstTruthy<T = any>(\n fallback: T,\n first: T | null | undefined,\n ...remaining: (T | null | undefined)[]\n): T {\n return firstWhere<T | null | undefined>((v) => !!v, fallback, first, ...remaining) as T;\n}\n","/**\n * Represents a object of 4 side values.\n *\n * @param T -\n * Value type. Typically number.\n */\nexport interface IZQuadrilateral<T = number> {\n /**\n * Bottom value.\n */\n bottom: T;\n /**\n * Left value.\n */\n left: T;\n /**\n * Right value.\n */\n right: T;\n /**\n * Top value.\n */\n top: T;\n}\n\n/**\n * Represents a builder for a quadrilateral object.\n */\nexport class ZQuadrilateralBuilder<T = number> {\n private _quad: IZQuadrilateral<T>;\n\n /**\n * Initializes a new instance of this object.\n *\n * @param start -\n * The starting value.\n */\n public constructor(start: T) {\n this._quad = {\n bottom: start,\n left: start,\n right: start,\n top: start\n };\n }\n\n /**\n * Sets the bottom value.\n *\n * @param bottom -\n * The bottom value.\n *\n * @returns\n * This object.\n */\n public bottom(bottom: T): this {\n this._quad.bottom = bottom;\n return this;\n }\n\n /**\n * Sets the left value.\n *\n * @param left -\n * The left value.\n *\n * @returns\n * This object.\n */\n public left(left: T): this {\n this._quad.left = left;\n return this;\n }\n\n /**\n * Sets the right value.\n *\n * @param right -\n * The right value.\n *\n * @returns\n * This object.\n */\n public right(right: T): this {\n this._quad.right = right;\n return this;\n }\n\n /**\n * Sets the top value.\n *\n * @param top -\n * The top value.\n *\n * @returns\n * This object.\n */\n public top(top: T): this {\n this._quad.top = top;\n return this;\n }\n\n /**\n * Sets the left and right value.\n *\n * @param x -\n * The left and right value.\n *\n * @returns\n * This object.\n */\n public x(x: T): this {\n return this.left(x).right(x);\n }\n\n /**\n * Sets the top and bottom value.\n *\n * @param y -\n * The top and bottom value.\n *\n * @returns\n * This object.\n */\n public y(y: T): this {\n return this.bottom(y).top(y);\n }\n\n /**\n * Copies another quadrilateral object into the current instance.\n *\n * @param other -\n * The quadrilateral object to copy.\n *\n * @returns\n * This object.\n */\n public copy(other: IZQuadrilateral<T>): this {\n this._quad = structuredClone(other);\n return this;\n }\n\n /**\n * Returns the built quadrilateral object.\n *\n * @returns\n * The built quadrilateral.\n */\n public build(): IZQuadrilateral<T> {\n return structuredClone(this._quad);\n }\n}\n","import { ZAnchor, ZHorizontalAnchor, ZVerticalAnchor } from '../anchor/anchor.mjs';\nimport { IZPoint2d } from './point.mjs';\nimport { IZQuadrilateral } from './quadrilateral.mjs';\n\n/**\n * Represents a helper object that can run calculations on a numeric quadrilateral.\n */\nexport class ZRectangle {\n /**\n * Initializes a new instance of this object.\n *\n * @param sides -\n * The numeric sides of a quadrilateral.\n */\n public constructor(public readonly sides: IZQuadrilateral) {}\n\n /**\n * Calculates the width of the rectangle.\n *\n * @returns\n * The numeric width of the rectangle.\n */\n public width(): number {\n const { left, right } = this.sides;\n return right - left;\n }\n\n /**\n * Calculates the height of the rectangle.\n *\n * @returns\n * The numeric height of the rectangle.\n */\n public height(): number {\n const { top, bottom } = this.sides;\n return bottom - top;\n }\n\n /**\n * Calculates the area of the rectangle.\n *\n * @returns\n * The numeric area of the rectangle.\n */\n public area(): number {\n return this.width() * this.height();\n }\n\n /**\n * Calculates the (x, y) point given an anchor target.\n *\n * @param anchor -\n * The anchor target to calculate the point for.\n *\n * @returns\n * The numeric width of the rectangle.\n */\n public point(anchor: ZAnchor): IZPoint2d {\n const { bottom, left, right, top } = this.sides;\n const [vertical, horizontal] = anchor;\n\n const v: Record<ZVerticalAnchor, number> = {\n [ZVerticalAnchor.Top]: top,\n [ZVerticalAnchor.Middle]: (bottom + top) / 2,\n [ZVerticalAnchor.Bottom]: bottom\n };\n\n const h: Record<ZHorizontalAnchor, number> = {\n [ZHorizontalAnchor.Left]: left,\n [ZHorizontalAnchor.Center]: (right + left) / 2,\n [ZHorizontalAnchor.Right]: right\n };\n\n return { x: h[horizontal], y: v[vertical] };\n }\n\n /**\n * Calculates the top left point of the rectangle.\n *\n * @returns\n * The top left point of the rectangle.\n */\n public topLeft = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Left]);\n /**\n * Calculates the top center point of the rectangle.\n *\n * @returns\n * The top center point of the rectangle.\n */\n public topCenter = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Center]);\n /**\n * Calculates the top right point of the rectangle.\n *\n * @returns\n * The top right point of the rectangle.\n */\n public topRight = this.point.bind(this, [ZVerticalAnchor.Top, ZHorizontalAnchor.Right]);\n /**\n * Calculates the middle left point of the rectangle.\n *\n * @returns\n * The middle left point of the rectangle.\n */\n public middleLeft = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Left]);\n /**\n * Calculates the middle center point of the rectangle.\n *\n * @returns\n * The middle center point of the rectangle.\n */\n public middleCenter = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Center]);\n /**\n * Calculates the middle right point of the rectangle.\n *\n * @returns\n * The middle right point of the rectangle.\n */\n public middleRight = this.point.bind(this, [ZVerticalAnchor.Middle, ZHorizontalAnchor.Right]);\n /**\n * Calculates the bottom left point of the rectangle.\n *\n * @returns\n * The bottom left point of the rectangle.\n */\n public bottomLeft = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Left]);\n /**\n * Calculates the bottom center point of the rectangle.\n *\n * @returns\n * The bottom center point of the rectangle.\n */\n public bottomCenter = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Center]);\n /**\n * Calculates the bottom right point of the rectangle.\n *\n * @returns\n * The bottom right point of the rectangle.\n */\n public bottomRight = this.point.bind(this, [ZVerticalAnchor.Bottom, ZHorizontalAnchor.Right]);\n}\n","/* istanbul ignore next -- @preserve */\nexport const $global = typeof window === 'undefined' ? global : window;\n","/**\n * A set of parameters that can be used for a string join.\n *\n * Join lists can be a regular object, null, undefined, or a tuple where the\n * first item is the object to join, and the second item is a boolean that specifies\n * whether to include it if the value is truthy.\n *\n * @param T -\n * The type of data to join.\n */\nexport type JoinListInputParameter<T> = T | [T, boolean] | null | undefined;\n\n/**\n * Similar to {@link Array.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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by delimiter.\n *\n * @example\n *\n * ```ts\n * // 'a b d'\n * const joinBySpace = joinDefined(' ', 'a', 'b', ['c', false], null, undefined, ['d', true]);\n * // (Empty String)\n * const joinEmpty = joinDefined('?');\n * ```\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 space delimiter.\n *\n * @param items -\n * The items to join.\n * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by space delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a space delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a comma delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a semi-colon delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\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 * @param T -\n * The type of data to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a pipe delimiter.\n *\n * @see\n * {@link joinDefined} for more information and examples.\n */\nexport const pipeJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, '|');\n","/**\n * A specific set of possible values that need to be checked for requirements.\n *\n * @param T -\n * The type of value that is being checked.\n */\nexport type ZObligatedValue<T> = T | null | undefined | Promise<T | null | undefined>;\n\n/**\n * Requires a value to be non null.\n *\n * @param val -\n * The value to require. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, an error is thrown.\n *\n * @throws\n * An error if the value is null or undefined.\n */\nexport async function required<T>(val: ZObligatedValue<T>): Promise<T> {\n if (val == null) {\n throw new Error('A required value was not provided');\n }\n\n const _val = await val;\n\n if (_val == null) {\n throw new Error('A required value was not provided');\n }\n\n return _val;\n}\n\n/**\n * Allows a value to be null or undefined and has a fallback.\n *\n * @param val -\n * The value to check. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param fallback -\n * The fallback value in the case that val is\n * null or undefined.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, the fallback is returned.\n * If val is a promise and rejects, then fallback is\n * also returned.\n */\nexport function optional<T>(val: ZObligatedValue<T>, fallback: T): Promise<T>;\n\n/**\n * Allows a value to be null or undefined and has a fallback.\n *\n * @param val -\n * The value to check. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, null is returned.\n * If val is a promise and rejects, then null is\n * also returned.\n */\nexport function optional<T>(val: ZObligatedValue<T>): Promise<T | null>;\n\n/**\n * Allows a value to be null or undefined and has a fallback.\n *\n * @param val -\n * The value to check. This can be a promise\n * that can return null or undefined in addition to the\n * value.\n * @param fallback -\n * The fallback value in the case that val is\n * null or undefined.\n * @param T -\n * The type of value that is being checked.\n *\n * @returns\n * This method returns val if it is not null\n * or undefined, otherwise, the fallback is returned.\n * If val is a promise and rejects, then fallback is\n * also returned.\n */\nexport async function optional<T>(val: ZObligatedValue<T>, fallback: T | null = null): Promise<T | null> {\n if (val == null) {\n return fallback;\n }\n\n try {\n const _val = await val;\n return _val == null ? fallback : _val;\n } catch {\n return fallback;\n }\n}\n","/**\n * Represents a direction orientation.\n */\nexport enum ZOrientation {\n /**\n * Horizontal 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 * Peels a candidate string from the start of a string and splits it into two segments.\n *\n * @param str -\n * The string to peel from.\n * @param candidates -\n * The candidate list of values to peel from str.\n *\n * @returns\n * A tuple where the first item is the peeled string and\n * the second item is the remainder of the string. If the string\n * does not start with any given candidates, then the first\n * item will be null and the second item will be str.\n */\nexport function peel<T extends string = string>(str: string, candidates: T[]): [T | null, string] {\n for (const check of candidates) {\n if (str.startsWith(check)) {\n return [str.substring(0, check.length) as T, str.substring(check.length)];\n }\n }\n\n return [null, str];\n}\n\n/**\n * Peels the values between an opening string set and a closing string set.\n *\n * The actual value will handle issues with internal opening and closing brackets\n *\n * @example\n *\n * ```ts\n * const [peeled, rest] = peelBetween('[a, b, [c1, c2],[d]] other', '[' ']');\n *\n * // Outputs 'a, b, [c1, c2], [d]'\n * console.log(peeled);\n *\n * // Outputs ' other' - white space is included'\n * console.log(rest);\n * ```\n *\n * @param str -\n * The string to peel between.\n * @param open -\n * The opening string. This will test\n * at the start of str.\n * @param close -\n * The closing string. This can be anywhere\n * in the str. If this is equal to open, then\n * the open string is removed from the start of the\n * string and the rest of the string would be returned.\n *\n * @returns\n * A tuple where the first argument is string that was found between\n * the opening and closing bracket. Returns null if no string could\n * be found between an open and close pair. The second argument will\n * be the remaining text of the string, including whitespace.\n */\nexport function peelBetween(str: string, open: string, close: string): [string | null, string] {\n if (!str.startsWith(open)) {\n return [null, str];\n }\n\n let stack = 1;\n\n const _str = str.substring(open.length);\n\n for (let i = 0; i < _str.length; ++i) {\n if (_str.startsWith(open, i)) {\n stack += 1;\n i += open.length - 1;\n continue;\n }\n\n if (_str.startsWith(close, i)) {\n stack -= 1;\n\n if (stack === 0) {\n return [_str.substring(0, i), _str.substring(i + close.length)];\n }\n\n i += close.length - 1;\n }\n }\n\n return [null, str];\n}\n","/**\n * Represents a tri logic state.\n *\n * See {@link ZTrilean.Indeterminate} for what the symbol value should be.\n *\n * @deprecated Use the one found in [\\@zthun/trilean](https://www.npmjs.com/package/\\@zthun/trilean) instead.\n */\nexport type trilean = boolean | symbol;\n\n/**\n * A utility class for trilean values.\n *\n * @deprecated Use the one found in [\\@zthun/trilean](https://www.npmjs.com/package/\\@zthun/trilean) instead.\n */\nexport abstract class ZTrilean {\n /**\n * A unique value for the third, indeterminate, state.\n */\n public static readonly Indeterminate = Symbol('helpful-fn-indeterminate');\n\n /**\n * Converts a trilean value to a string.\n *\n * @param x -\n * The value to convert.\n *\n * @returns\n * A string of true if x is true, false if x is false,\n * and indeterminate if x is null.\n */\n public static stringify(x: trilean): string {\n return ZTrilean.isIndeterminate(x) ? 'indeterminate' : String(x);\n }\n\n /**\n * Converts a string to a trilean value.\n *\n * @param str -\n * The text to parse.\n * @param fallback -\n * The fallback in the case that str is not a parsable value.\n *\n * @returns\n * The parsed trilean value or fallback if str is not a valid\n * trilean value.\n */\n public static parse(str: string | null | undefined, fallback: trilean = false): trilean {\n if (str?.toUpperCase().localeCompare('TRUE') === 0) {\n return true;\n }\n\n if (str?.toUpperCase().localeCompare('FALSE') === 0) {\n return false;\n }\n\n if (str?.toUpperCase().localeCompare('INDETERMINATE') === 0) {\n return ZTrilean.Indeterminate;\n }\n\n return fallback;\n }\n\n /**\n * Gets a value that determines if val is a trilean supported value.\n *\n * @param val -\n * The value to test.\n *\n * @returns\n * True if val is a trilean value. False otherwise.\n */\n public static is(val: any): val is trilean {\n return typeof val === 'boolean' || ZTrilean.isIndeterminate(val);\n }\n\n /**\n * Gets whether val is the indeterminate value.\n */\n public static isIndeterminate(val: trilean): val is symbol {\n return val === ZTrilean.Indeterminate;\n }\n\n /**\n * Converts from a value to a trilean value.\n *\n * This is similar to parse, but it also supports non\n * string inputs which will be converted to a boolean.\n *\n * @param val -\n * The value to convert.\n * @param fallback -\n * The fallback value in the case that val cannot be converted. This will\n * only be used in the case that val is a string, null, or undefined.\n *\n * @returns\n * The trilean value of val. If val is null or undefined, then\n * fallback is returned. If val is a string, then the return value of\n * {@link parse} will be used. If val is a boolean, then it will be\n * directly returned. If val is equal to {@link Indeterminate}, then\n * {@link Indeterminate} will be returned. Otherwise, the truthy\n * nature of value will be returned.\n */\n public static convert(val: any, fallback: trilean = false): trilean {\n if (val == null) {\n return fallback;\n }\n\n if (ZTrilean.is(val)) {\n return val;\n }\n\n if (typeof val === 'string') {\n return ZTrilean.parse(val, fallback);\n }\n\n return !!val;\n }\n}\n","import { IZDeserialize } from './deserialize.mjs';\n\n/**\n * A deserializer that deserializes a JSON string.\n */\nexport class ZDeserializeJson<T> implements IZDeserialize<T> {\n public constructor(private _schema?: (k: any) => k is T) {}\n\n public deserialize(candidate: string): T {\n const parsed = JSON.parse(candidate);\n\n if (this._schema && !this._schema(parsed)) {\n throw new Error('The parsed JSON does not conform to the given schema requirement');\n }\n\n return parsed;\n }\n}\n","import { IZDeserialize } from './deserialize.mjs';\n\n/**\n * A deserializer that attempts to deserialize multiple times through a series of supported languages.\n *\n * @param T -\n * The type of data to deserialize.\n * @param S -\n * The input type\n */\nexport class ZDeserializeTry<T, S = string> implements IZDeserialize<T, S> {\n /**\n * Initializes a new instance of this object.\n *\n * @param _children -\n * The list of deserializer objects to try on a specific candidate.\n * The first deserializer to succeed will return the target object.\n * If no deserializer is able to deserialize the candidate, then an\n * error is throw with a mapping of serialization errors between each\n * deserializer.\n */\n public constructor(private _children: IZDeserialize<T, S>[]) {}\n\n public deserialize(candidate: S): T {\n const errors: string[] = [];\n\n for (const child of this._children) {\n try {\n return child.deserialize(candidate);\n } catch (e) {\n errors.push(e.message);\n }\n }\n\n const msg = `Unable to deserialize candidate, ${candidate}.`;\n errors.splice(0, 0, msg);\n throw new Error(errors.join('\\n\\n'));\n }\n}\n","import { IZSerialize } from './serialize.mjs';\n\n/**\n * Represents a serializer that serializes anything to a JSON string.\n */\nexport class ZSerializeJson implements IZSerialize<any> {\n public serialize(candidate: any): string | undefined {\n return JSON.stringify(candidate, undefined, 2);\n }\n}\n","/**\n * Represents a setter function for when you want to set a single value,\n * 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. This is primarily meant\n * to be use with bind to construct a new method setter that takes an array\n * and forwards it to a setter method which will accept a single value of the\n * first item in the target value.\n *\n * @param setValue -\n * The setter function that takes a single value. This will receive\n * the first item of the value list.\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 * @param T -\n * The type of data that the array holds.\n *\n * @example\n *\n * ```ts\n * // An example of a react component that needs a value of an array, but you only care about a single selection.\n * const [value, setValue] = useState<TypesOfPie>();\n * const _values = useMemo(() => value ? [value] : [], [value]);\n * const _setValues = setFirst.bind(null, setValue, undefined);\n *\n * return <ComponentWithMultiSelectSupport values={_values} onValuesChange={_setValues} />\n * ```\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 * @param T -\n * The type of value that will be resolved.\n *\n * @returns\n * A promise that resolves with val 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 * @param T -\n * The type of value that will be resolved.\n *\n * @returns\n * A promise that resolves with val 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","/**\n * This is just a method that allows you to tag an interpolation\n * string as a syntax language.\n *\n * This is useful with IDE extensions that can detect the language\n * and do the syntax highlighting for you.\n *\n * @param strings -\n * The string breaks for interpolation.\n * @param expressions -\n * The equivalent expressions that break apart\n * the single string literal.\n *\n * @returns\n * The compiled string literal. This is no different\n * than letting native JavaScript do it for you.\n *\n * @example\n *\n * ```ts\n * const html = tag;\n * const css = tag;\n *\n * const $html = html`\n * <div>Some IDE extensions will highlight this as html</div>\n * `\n *\n * const $css = css`\n * button {\n * display: grid;\n * }\n * `\n * ```\n */\nexport function tag(strings: TemplateStringsArray, ...expressions: unknown[]): string {\n let [result] = strings;\n\n for (let i = 1, l = strings.length; i < l; i++) {\n result += expressions[i - 1];\n result += strings[i];\n }\n\n return result;\n}\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=Tobermory.es6-string-html | IDE extensions will detect the string}\n * interpolation as html when using this tag.\n */\nexport const html = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=bashmish.es6-string-css | IDE extensions will detect the string}\n * interpolation as css when using this tag.\n */\nexport const css = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=zjcompt.es6-string-javascript | IDE extensions will detect the string}\n * interpolation as javascript when using this tag.\n */\nexport const javascript = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=jeoht.es6-string-markdown | IDE extensions will detect the string}\n * interpolation as markdown when using this tag.\n */\nexport const md = tag;\n\n/**\n * See {@link md}\n */\nexport const markdown = tag;\n\n/**\n * An alias for {@link tag}.\n *\n * Some {@link https://marketplace.visualstudio.com/items?itemName=HoodieCollin.es6-string-typescript | IDE extensions will detect the string}\n * interpolation as typescript when using this tag.\n */\nexport const ts = tag;\n\n/**\n * See {@link ts}\n */\nexport const typescript = tag;\n","/**\n * Invokes the candidate function and returns undefined if an error is thrown from it.\n *\n * @param candidate -\n * The candidate function to run.\n *\n * @returns\n * The result from candidate. Returns undefined if candidate throws an Error.\n */\nexport function tryFallback<T>(candidate: () => T): T | undefined;\n\n/**\n * Invokes the candidate function and returns fallback if an error is thrown from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The fallback value to return if candidate throws an error.\n *\n * @returns\n * The result from candidate. Returns fallback if candidate throws an Error.\n */\nexport function tryFallback<T>(candidate: () => T, fallback: T): T;\n\n/**\n * Invokes the candidate function and returns fallback if an error is thrown from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The fallback value to return if candidate throws an error.\n *\n * @returns\n * The result from candidate. Returns fallback if candidate throws an Error.\n * If no fallback value is provided, then undefined is returned.\n */\nexport function tryFallback<T>(candidate: () => T, fallback?: T): T | undefined {\n try {\n return candidate();\n } catch {\n return fallback;\n }\n}\n\n/**\n * Invokes the candidate function and returns undefined if an rejected promise is returned from it.\n *\n * @param candidate -\n * The candidate function to run.\n *\n * @returns\n * A promise that resolves with the result from candidate. Returns undefined\n * if candidate returns a rejected promise.\n */\nexport function tryFallbackAsync<T>(candidate: () => Promise<T>): Promise<T | undefined>;\n\n/**\n * Invokes the candidate function and returns undefined if an rejected promise is returned from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The fallback value that will be returned if candidate returns a rejected promise.\n *\n * @returns\n * A promise that resolves with the result from candidate. Returns fallback\n * if candidate returns a rejected promise.\n */\nexport function tryFallbackAsync<T>(candidate: () => Promise<T>, fallback: T): Promise<T>;\n\n/**\n * Invokes the candidate function and returns undefined if an rejected promise is returned from it.\n *\n * @param candidate -\n * The candidate function to run.\n * @param fallback -\n * The optional fallback value to return if the candidate throws an Error.\n *\n * @returns\n * A promise that resolves with the result from candidate or fallback\n * if candidate returns a rejected promise. Resolves with undefined\n * if no fallback is provided.\n */\nexport async function tryFallbackAsync<T>(candidate: () => Promise<T>, fallback?: T): Promise<T | undefined> {\n try {\n return await candidate();\n } catch {\n return fallback;\n }\n}\n"],"names":["ZVerticalAnchor","ZHorizontalAnchor","ZOrientation"],"mappings":";AAGY,IAAA,oCAAAA,qBAAL;AAMLA,mBAAA,KAAM,IAAA;AAINA,mBAAA,QAAS,IAAA;AAMTA,mBAAA,QAAS,IAAA;AAhBCA,SAAAA;AAAA,GAAA,mBAAA,CAAA,CAAA;AAsBA,IAAA,sCAAAC,u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AACF;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zthun/helpful-fn",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
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",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"sideEffects": false,
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "e88172d0ba1bd2b4bd548af337993cc7b95f712c"
|
|
41
41
|
}
|