@zayne-labs/toolkit-type-helpers 0.9.44 → 0.9.45
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/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/guard.ts","../../src/assert.ts","../../src/
|
1
|
+
{"version":3,"sources":["../../src/guard.ts","../../src/assert.ts","../../src/enum.ts"],"names":[],"mappings":";AAOO,IAAM,QAAW,GAAA,CAAC,KAAmB,KAAA,OAAO,KAAU,KAAA;AAEtD,IAAM,QAAW,GAAA,CAAC,KAAmB,KAAA,OAAO,KAAU,KAAA;AAEtD,IAAM,QAAW,GAAA,CAAC,KAAmB,KAAA,OAAO,KAAU,KAAA;AAEtD,IAAM,SAAY,GAAA,CAAC,KAAmB,KAAA,OAAO,KAAU,KAAA;AAEvD,IAAM,OAAU,GAAA,CAAS,KAAsC,KAAA,KAAA,CAAM,QAAQ,KAAK;AAE5E,IAAA,UAAA,GAAa,CAAC,KAAA,KAAmB,KAAiB,YAAA;AAExD,IAAM,WAAW,CAAC,KAAA,KAAmB,OAAO,KAAA,KAAU,YAAY,KAAU,KAAA;AAEtE,IAAA,mBAAA,GAAsB,CAA0B,KAAqC,KAAA;AACjG,EAAA,OAAO,QAAS,CAAA,KAAK,CAAK,IAAA,CAAC,QAAQ,KAAK,CAAA;AACzC;AAEa,IAAA,kBAAA,GAAqB,CAAC,KAAmB,KAAA;AACrD,EAAA,OAAO,MAAO,CAAA,SAAA,CAAU,QAAS,CAAA,IAAA,CAAK,KAAK,CAAM,KAAA,iBAAA;AAClD;AAMa,IAAA,aAAA,GAAgB,CAC5B,KAC2B,KAAA;AAC3B,EAAI,IAAA,CAAC,kBAAmB,CAAA,KAAK,CAAG,EAAA;AAC/B,IAAO,OAAA,KAAA;AAAA;AAIR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AAyB,CAAI,EAAA,CAAA,CAAA;AAAA;AAG/E,EAAO,OAAA,KAAA;AACR;AAEa,IAAA,SAAA,GAAY,CAAC,QAAA,EAA8B,OAAqB,KAAA;AAC5E,EAAA,IAAI,aAAa,MAAW,EAAA;AAC3B,IAAM,MAAA,IAAI,eAAe,OAAO,CAAA;AAAA;AAGjC,EAAO,OAAA,QAAA;AACR;AAea,IAAA,MAAA,GAAmB,CAAC,KAAA,EAAgB,gBAA8C,KAAA;AAC9F,EAAI,IAAA,KAAA,KAAU,KAAS,IAAA,KAAA,IAAS,IAAM,EAAA;AACrC,IAAA,MAAM,OAAU,GAAA,QAAA,CAAS,gBAAgB,CAAA,GAAI,mBAAmB,gBAAkB,EAAA,OAAA;AAElF,IAAM,MAAA,IAAI,eAAe,OAAO,CAAA;AAAA;AAElC;;;AC7Ca,IAAA,UAAA,GAAa,CAAe,KAAkB,KAAA;AAC1D,EAAO,OAAA,KAAA;AACR;AAEa,IAAA,cAAA,GAAiB,CAAe,KAAkB,KAAA;AAC9D,EAAO,OAAA,KAAA;AACR","file":"index.js","sourcesContent":["import type {\n\tAnyAsyncFunction,\n\tAnyFunction,\n\tUnknownObject,\n\tUnknownObjectWithAnyKey,\n} from \"./type-utils/common\";\n\nexport const isString = (value: unknown) => typeof value === \"string\";\n\nexport const isNumber = (value: unknown) => typeof value === \"number\";\n\nexport const isSymbol = (value: unknown) => typeof value === \"symbol\";\n\nexport const isBoolean = (value: unknown) => typeof value === \"boolean\";\n\nexport const isArray = <TArray>(value: unknown): value is TArray[] => Array.isArray(value);\n\nexport const isFormData = (value: unknown) => value instanceof FormData;\n\nexport const isObject = (value: unknown) => typeof value === \"object\" && value !== null;\n\nexport const isObjectAndNotArray = <TObject = UnknownObject>(value: unknown): value is TObject => {\n\treturn isObject(value) && !isArray(value);\n};\n\nexport const hasObjectPrototype = (value: unknown) => {\n\treturn Object.prototype.toString.call(value) === \"[object Object]\";\n};\n\n/**\n * @description Copied from TanStack Query's isPlainObject\n * @see https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L321\n */\nexport const isPlainObject = <TPlainObject extends UnknownObjectWithAnyKey = UnknownObject>(\n\tvalue: unknown\n): value is TPlainObject => {\n\tif (!hasObjectPrototype(value)) {\n\t\treturn false;\n\t}\n\n\t// If has no constructor\n\tconst constructor = (value as object | undefined)?.constructor;\n\tif (constructor === undefined) {\n\t\treturn true;\n\t}\n\n\t// If has modified prototype\n\tconst prototype = constructor.prototype as object;\n\tif (!hasObjectPrototype(prototype)) {\n\t\treturn false;\n\t}\n\n\t// If constructor does not have an Object-specific method\n\tif (!Object.hasOwn(prototype, \"isPrototypeOf\")) {\n\t\treturn false;\n\t}\n\n\t// Handles Objects created by Object.create(<arbitrary prototype>)\n\tif (Object.getPrototypeOf(value) !== Object.prototype) {\n\t\treturn false;\n\t}\n\n\t// It's probably a plain object at this point\n\treturn true;\n};\n\nexport const isFunction = <TFunction extends AnyFunction>(value: unknown): value is TFunction => {\n\treturn typeof value === \"function\";\n};\n\nexport const isAsyncFunction = <TAsyncFunction extends AnyAsyncFunction>(\n\tvalue: unknown\n): value is TAsyncFunction => {\n\treturn isFunction(value) && value.constructor.name === \"AsyncFunction\";\n};\n\nexport const isFile = (value: unknown): value is File => value instanceof File;\n\nexport const isIterable = <TIterable>(obj: object): obj is Iterable<TIterable> => Symbol.iterator in obj;\n","import { isString } from \"./guard\";\n\nexport class AssertionError extends Error {\n\toverride name = \"AssertionError\";\n\n\tconstructor(message?: string) {\n\t\tconst prefix = \"Assertion failed\";\n\n\t\tsuper(message ? `${prefix}: ${message}` : message);\n\t}\n}\n\nexport const assertDefined = <TValue>(value: TValue) => {\n\tif (value == null) {\n\t\tthrow new AssertionError(`The value passed is \"${value as null | undefined}!\"`);\n\t}\n\n\treturn value;\n};\n\nexport const assertENV = (variable: string | undefined, message?: string) => {\n\tif (variable === undefined) {\n\t\tthrow new AssertionError(message);\n\t}\n\n\treturn variable;\n};\n\ntype AssertOptions = {\n\tmessage: string;\n};\n\ntype AssertFn = {\n\t(condition: boolean, messageOrOptions?: string | AssertOptions): asserts condition;\n\n\t<TValue>(\n\t\tvalue: TValue,\n\t\tmessageOrOptions?: string | AssertOptions\n\t): asserts value is NonNullable<TValue>;\n};\n\nexport const assert: AssertFn = (input: unknown, messageOrOptions?: string | AssertOptions) => {\n\tif (input === false || input == null) {\n\t\tconst message = isString(messageOrOptions) ? messageOrOptions : messageOrOptions?.message;\n\n\t\tthrow new AssertionError(message);\n\t}\n};\n","import type { Prettify, Writeable } from \"./type-utils\";\n\nexport const defineEnum = <const TValue>(value: TValue) => {\n\treturn value as Prettify<Writeable<TValue>>;\n};\n\nexport const defineEnumDeep = <const TValue>(value: TValue) => {\n\treturn value as Prettify<Writeable<TValue, \"deep\">>;\n};\n"]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zayne-labs/toolkit-type-helpers",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.9.
|
4
|
+
"version": "0.9.45",
|
5
5
|
"description": "A collection of utility functions, types and composables used by my other projects. Nothing too fancy but can be useful.",
|
6
6
|
"author": "Ryan Zayne",
|
7
7
|
"license": "MIT",
|