@zayne-labs/toolkit-type-helpers 0.8.47 → 0.8.49

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.
@@ -102,6 +102,6 @@ type AssertFn = {
102
102
  };
103
103
  declare const assert: AssertFn;
104
104
 
105
- declare const defineEnum: <const TValue, TVariant extends WriteableVariantUnion = "shallow">(value: TValue) => Prettify<Writeable<TValue, TVariant>>;
105
+ declare const defineEnum: <const TValue, TVariant extends WriteableVariantUnion = "shallow">(value: TValue) => Writeable<TValue, TVariant> extends infer T ? { [Key in keyof T]: Writeable<TValue, TVariant>[Key]; } : never;
106
106
 
107
107
  export { type AnyAsyncFunction, type AnyFunction, type AnyNumber, type AnyObject, type AnyString, AssertionError, type CallbackFn, type ExtractUnion, type LiteralUnion, type NonEmptyArray, type Prettify, type PrettyOmit, type PrettyPick, type SelectorFn, type UnionDiscriminator, type UnionDiscriminatorRequired, type UnknownObject, type UnknownObjectWithAnyKey, type UnmaskType, type Writeable, type WriteableVariantUnion, assert, assertDefined, assertENV, defineEnum, hasObjectPrototype, isArray, isAsyncFunction, isBoolean, isFile, isFormData, isFunction, isIterable, isNumber, isObject, isObjectAndNotArray, isPlainObject, isString, isSymbol };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/guard.ts","../../src/assert.ts","../../src/common.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;AAEx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AAkC,KAAiB,YAAA;AAEnE,IAAM,UAAa,GAAA,CAAY,GAA4C,KAAA,MAAA,CAAO,QAAY,IAAA;;;AC5ExF,IAAA,cAAA,GAAN,cAA6B,KAAM,CAAA;AAAA,EAChC,IAAO,GAAA,gBAAA;AAAA,EAEhB,YAAY,OAAkB,EAAA;AAC7B,IAAA,MAAM,MAAS,GAAA,kBAAA;AAEf,IAAA,KAAA,CAAM,UAAU,CAAG,EAAA,MAAM,CAAK,EAAA,EAAA,OAAO,KAAK,OAAO,CAAA;AAAA;AAEnD;AAEa,IAAA,aAAA,GAAgB,CAAS,KAAkB,KAAA;AACvD,EAAA,IAAI,SAAS,IAAM,EAAA;AAClB,IAAA,MAAM,IAAI,cAAA,CAAe,CAAwB,qBAAA,EAAA,KAAyB,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,CACzB,KACI,KAAA;AACJ,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, WriteableVariantUnion } from \"./type-utils\";\n\nexport const defineEnum = <const TValue, TVariant extends WriteableVariantUnion = \"shallow\">(\n\tvalue: TValue\n) => {\n\treturn value as Prettify<Writeable<TValue, TVariant>>;\n};\n"]}
1
+ {"version":3,"sources":["../../src/guard.ts","../../src/assert.ts","../../src/common.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,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WithAnyKey,\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, WriteableVariantUnion } from \"./type-utils\";\n\nexport const defineEnum = <const TValue, TVariant extends WriteableVariantUnion = \"shallow\">(\n\tvalue: TValue\n) => {\n\ttype Enum<$TValue> = Prettify<Writeable<$TValue, TVariant>>;\n\n\treturn value as Enum<TValue>;\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.8.47",
4
+ "version": "0.8.49",
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",
@@ -37,17 +37,17 @@
37
37
  "@size-limit/esbuild-why": "^11.2.0",
38
38
  "@size-limit/preset-small-lib": "^11.2.0",
39
39
  "@total-typescript/ts-reset": "^0.6.1",
40
- "@types/node": "^22.13.6",
41
- "@zayne-labs/tsconfig": "0.2.1",
40
+ "@types/node": "^22.13.10",
41
+ "@zayne-labs/tsconfig": "0.6.4",
42
42
  "clsx": "^2.1.1",
43
43
  "concurrently": "^9.1.2",
44
44
  "cross-env": "^7.0.3",
45
- "publint": "^0.3.7",
45
+ "publint": "^0.3.9",
46
46
  "size-limit": "^11.2.0",
47
47
  "terser": "^5.39.0",
48
48
  "tsup": "^8.4.0",
49
49
  "typescript": "5.8.2",
50
- "vitest": "3.0.7"
50
+ "vitest": "3.0.9"
51
51
  },
52
52
  "publishConfig": {
53
53
  "access": "public",