@zayne-labs/toolkit-type-helpers 0.8.38 → 0.8.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.
@@ -8,14 +8,10 @@ type PrettyOmit<TObject, Key extends keyof TObject> = Prettify<Omit<TObject, Key
8
8
  type PrettyPick<TObject, Key extends keyof TObject> = Prettify<Pick<TObject, Key>>;
9
9
  type CallbackFn<in TParams, out TResult = void> = (...params: TParams[]) => TResult;
10
10
  type SelectorFn<TStore, TResult> = (state: TStore) => TResult;
11
- type ExtractUnion<TEnum extends Record<string, unknown> | unknown[]> = TEnum extends unknown[] ? TEnum[number] : TEnum[keyof TEnum];
12
- type WriteableLevel = "deep" | "shallow";
13
- type Writeable<TObject, TType extends WriteableLevel = "shallow"> = {
14
- -readonly [key in keyof TObject]: TType extends "shallow" ? TObject[key] : TType extends "deep" ? TObject[key] extends object ? Writeable<TObject[key], TType> : TObject[key] : never;
15
- };
16
- type InferEnum<TObject, TVariant extends "keys" | "values" = "values"> = TObject extends Array<infer TUnion> | ReadonlyArray<infer TUnion> | Set<infer TUnion> ? TUnion : TObject extends Record<infer TKeys, infer TValues> ? TVariant extends "keys" ? TKeys : Prettify<Writeable<TValues, "deep">> : never;
17
11
  type NonEmptyArray<TArrayItem> = [TArrayItem, ...TArrayItem[]];
18
- type AnyObject = UnmaskType<Record<string, unknown>>;
12
+ type UnknownObject = UnmaskType<Record<string, unknown>>;
13
+ type UnknownObjectWithAnyKey = UnmaskType<Record<keyof any, unknown>>;
14
+ type AnyObject = UnmaskType<Record<keyof any, any>>;
19
15
  type AnyFunction<TResult = any> = UnmaskType<(...args: any[]) => TResult>;
20
16
  type AnyAsyncFunction<TResult = any> = UnmaskType<(...args: any[]) => Promise<TResult>>;
21
17
  /**
@@ -32,14 +28,60 @@ type AnyString = string & Record<never, never>;
32
28
  type AnyNumber = number & Record<never, never>;
33
29
  type LiteralUnion<TUnion extends TBase, TBase = string> = TUnion | (TBase & Record<never, never>);
34
30
 
31
+ type WriteableVariantUnion = "deep" | "shallow";
32
+ /**
33
+ * Makes all properties in an object type writeable (removes readonly modifiers).
34
+ * Supports both shallow and deep modes, and handles special cases like arrays, tuples, and unions.
35
+ * @template TObject - The object type to make writeable
36
+ * @template TVariant - The level of writeable transformation ("shallow" | "deep")
37
+ */
38
+ type Writeable<TObject, TVariant extends WriteableVariantUnion = "shallow"> = TObject extends readonly [...infer TTupleItems] ? TVariant extends "deep" ? [
39
+ ...{
40
+ [Key in keyof TTupleItems]: TTupleItems[Key] extends object ? Writeable<TTupleItems[Key], TVariant> : TTupleItems[Key];
41
+ }
42
+ ] : [...TTupleItems] : TObject extends ReadonlyArray<infer TArrayItem> ? TVariant extends "deep" ? Array<TArrayItem extends object ? Writeable<TArrayItem, TVariant> : TArrayItem> : TArrayItem[] : TObject extends object ? {
43
+ -readonly [Key in keyof TObject]: TVariant extends "shallow" ? TObject[Key] : TVariant extends "deep" ? TObject[Key] extends object ? Writeable<TObject[Key], TVariant> : TObject[Key] : never;
44
+ } : TObject;
45
+
46
+ type AllowOnlyFirst<TFirstType, TSecondType, TExclusionValue = never> = Prettify<TFirstType & Partial<Record<keyof Omit<TSecondType, keyof TFirstType>, TExclusionValue>>>;
47
+ type AllowOnlyFirstRequired<TFirstType, TSecondType, TExclusionValue = never> = Prettify<TFirstType & Record<keyof Omit<TSecondType, keyof TFirstType>, TExclusionValue>>;
48
+ type MergeTypes<TArrayOfTypes extends unknown[], TAccumulator = NonNullable<unknown>> = TArrayOfTypes extends [infer TFirstType, ...infer TRest] ? MergeTypes<TRest, TAccumulator & TFirstType> : TAccumulator;
49
+ /**
50
+ * Type utility that extracts discriminated properties from a union of types.
51
+ * Takes an array of types and returns a union of types where each type has unique properties.
52
+ *
53
+ * @template TArrayOfTypes Array of types to process
54
+ * @template TExclusionValue Value to exclude from the resulting union
55
+ * @template TAccumulator Accumulator for the resulting union
56
+ * @template TMergedProperties Merged properties from all types
57
+ */
58
+ type UnionDiscriminator<TArrayOfTypes extends unknown[], TExclusionValue = never, TAccumulator = never, TMergedProperties = MergeTypes<TArrayOfTypes>> = TArrayOfTypes extends [infer TFirstType, ...infer TRest] ? UnionDiscriminator<TRest, TExclusionValue, TAccumulator | AllowOnlyFirst<TFirstType, TMergedProperties, TExclusionValue>, TMergedProperties> : TAccumulator;
59
+ /**
60
+ * Type utility that extracts discriminated properties from a union of types.
61
+ * Takes an array of types and returns a union of types where each type has unique properties.
62
+ *
63
+ * @template TArrayOfTypes - Array of types to process
64
+ * @template TExclusionValue - Value to exclude from the resulting union
65
+ * @template TAccumulator - Accumulator for the resulting union
66
+ * @template TMergedProperties - Merged properties from all types
67
+ */
68
+ type UnionDiscriminatorRequired<TArrayOfTypes extends unknown[], TExclusionValue = never, TAccumulator = never, TMergedProperties = MergeTypes<TArrayOfTypes>> = TArrayOfTypes extends [infer TFirstType, ...infer TRest] ? UnionDiscriminatorRequired<TRest, TExclusionValue, TAccumulator | AllowOnlyFirstRequired<TFirstType, TMergedProperties, TExclusionValue>, TMergedProperties> : TAccumulator;
69
+ type ExtractUnion<TObject, TVariant extends "keys" | "values" = "values"> = TObject extends Array<infer TUnion> | ReadonlyArray<infer TUnion> | Set<infer TUnion> ? TUnion : TObject extends Record<infer TKeys, infer TValues> ? TVariant extends "keys" ? TKeys : Prettify<Writeable<TValues, "deep">> : never;
70
+
35
71
  declare const isString: (value: unknown) => value is string;
36
72
  declare const isNumber: (value: unknown) => value is number;
73
+ declare const isSymbol: (value: unknown) => value is symbol;
37
74
  declare const isBoolean: (value: unknown) => value is boolean;
38
75
  declare const isArray: <TArray>(value: unknown) => value is TArray[];
39
76
  declare const isFormData: (value: unknown) => value is FormData;
40
77
  declare const isObject: (value: unknown) => value is object;
41
- declare const isObjectAndNotArray: <TObject = Record<string, unknown>>(value: unknown) => value is TObject;
42
- declare const isPlainObject: <TObject extends AnyObject>(value: unknown) => value is TObject;
78
+ declare const isObjectAndNotArray: <TObject = UnknownObject>(value: unknown) => value is TObject;
79
+ declare const hasObjectPrototype: (value: unknown) => boolean;
80
+ /**
81
+ * @description Copied from TanStack Query's isPlainObject
82
+ * @see https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L321
83
+ */
84
+ declare const isPlainObject: <TPlainObject extends UnknownObjectWithAnyKey = UnknownObject>(value: unknown) => value is TPlainObject;
43
85
  declare const isFunction: <TFunction extends AnyFunction>(value: unknown) => value is TFunction;
44
86
  declare const isAsyncFunction: <TAsyncFunction extends AnyAsyncFunction>(value: unknown) => value is TAsyncFunction;
45
87
  declare const isFile: (value: unknown) => value is File;
@@ -60,6 +102,6 @@ type AssertFn = {
60
102
  };
61
103
  declare const assert: AssertFn;
62
104
 
63
- declare const defineEnum: <const TValue, TWriteableLevel extends WriteableLevel = "shallow">(value: TValue) => Prettify<Writeable<TValue, TWriteableLevel>>;
105
+ declare const defineEnum: <const TValue, TVariant extends WriteableVariantUnion = "shallow">(value: TValue) => Prettify<Writeable<TValue, TVariant>>;
64
106
 
65
- export { type AnyAsyncFunction, type AnyFunction, type AnyNumber, type AnyObject, type AnyString, AssertionError, type CallbackFn, type ExtractUnion, type InferEnum, type LiteralUnion, type NonEmptyArray, type Prettify, type PrettyOmit, type PrettyPick, type SelectorFn, type UnmaskType, type Writeable, type WriteableLevel, assert, assertDefined, assertENV, defineEnum, isArray, isAsyncFunction, isBoolean, isFile, isFormData, isFunction, isIterable, isNumber, isObject, isObjectAndNotArray, isPlainObject, isString };
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 };
package/dist/esm/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/guard.ts
2
2
  var isString = (value) => typeof value === "string";
3
3
  var isNumber = (value) => typeof value === "number";
4
+ var isSymbol = (value) => typeof value === "symbol";
4
5
  var isBoolean = (value) => typeof value === "boolean";
5
6
  var isArray = (value) => Array.isArray(value);
6
7
  var isFormData = (value) => value instanceof FormData;
@@ -8,12 +9,28 @@ var isObject = (value) => typeof value === "object" && value !== null;
8
9
  var isObjectAndNotArray = (value) => {
9
10
  return isObject(value) && !isArray(value);
10
11
  };
12
+ var hasObjectPrototype = (value) => {
13
+ return Object.prototype.toString.call(value) === "[object Object]";
14
+ };
11
15
  var isPlainObject = (value) => {
12
- if (!isObject(value)) {
16
+ if (!hasObjectPrototype(value)) {
17
+ return false;
18
+ }
19
+ const constructor = value?.constructor;
20
+ if (constructor === void 0) {
21
+ return true;
22
+ }
23
+ const prototype = constructor.prototype;
24
+ if (!hasObjectPrototype(prototype)) {
25
+ return false;
26
+ }
27
+ if (!Object.hasOwn(prototype, "isPrototypeOf")) {
28
+ return false;
29
+ }
30
+ if (Object.getPrototypeOf(value) !== Object.prototype) {
13
31
  return false;
14
32
  }
15
- const prototype = Object.getPrototypeOf(value);
16
- return (prototype == null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value);
33
+ return true;
17
34
  };
18
35
  var isFunction = (value) => {
19
36
  return typeof value === "function";
@@ -39,7 +56,7 @@ var assertDefined = (value) => {
39
56
  return value;
40
57
  };
41
58
  var assertENV = (variable, message) => {
42
- if (variable === undefined) {
59
+ if (variable === void 0) {
43
60
  throw new AssertionError(message);
44
61
  }
45
62
  return variable;
@@ -52,8 +69,10 @@ var assert = (input, messageOrOptions) => {
52
69
  };
53
70
 
54
71
  // src/common.ts
55
- var defineEnum = (value) => value;
72
+ var defineEnum = (value) => {
73
+ return value;
74
+ };
56
75
 
57
- export { AssertionError, assert, assertDefined, assertENV, defineEnum, isArray, isAsyncFunction, isBoolean, isFile, isFormData, isFunction, isIterable, isNumber, isObject, isObjectAndNotArray, isPlainObject, isString };
76
+ export { AssertionError, assert, assertDefined, assertENV, defineEnum, hasObjectPrototype, isArray, isAsyncFunction, isBoolean, isFile, isFormData, isFunction, isIterable, isNumber, isObject, isObjectAndNotArray, isPlainObject, isString, isSymbol };
58
77
  //# sourceMappingURL=index.js.map
59
78
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/guard.ts","../../src/assert.ts","../../src/common.ts"],"names":[],"mappings":";AAEO,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,CAClC,KACsB,KAAA;AACtB,EAAA,OAAO,QAAS,CAAA,KAAK,CAAK,IAAA,CAAC,QAAQ,KAAK,CAAA;AACzC;AAEa,IAAA,aAAA,GAAgB,CAA4B,KAAqC,KAAA;AAC7F,EAAI,IAAA,CAAC,QAAS,CAAA,KAAK,CAAG,EAAA;AACrB,IAAO,OAAA,KAAA;AAAA;AAGR,EAAM,MAAA,SAAA,GAAY,MAAO,CAAA,cAAA,CAAe,KAAK,CAAA;AAG7C,EAAA,OAAA,CACE,SAAa,IAAA,IAAA,IAAQ,SAAc,KAAA,MAAA,CAAO,SAAa,IAAA,MAAA,CAAO,cAAe,CAAA,SAAS,CAAM,KAAA,IAAA,KAC7F,EAAE,MAA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AAA,OAAA;AAElF,IAAM,MAAA,IAAI,eAAe,OAAO,CAAA;AAAA;AAElC;;;AC7Ca,IAAA,UAAA,GAAa,CACzB,KACI,KAAA","file":"index.js","sourcesContent":["import type { AnyAsyncFunction, AnyFunction, AnyObject } from \"./type-utils\";\n\nexport const isString = (value: unknown) => typeof value === \"string\";\n\nexport const isNumber = (value: unknown) => typeof value === \"number\";\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 = Record<string, unknown>>(\n\tvalue: unknown\n): value is TObject => {\n\treturn isObject(value) && !isArray(value);\n};\n\nexport const isPlainObject = <TObject extends AnyObject>(value: unknown): value is TObject => {\n\tif (!isObject(value)) {\n\t\treturn false;\n\t}\n\n\tconst prototype = Object.getPrototypeOf(value) as unknown;\n\n\t// == Check if it's a plain object\n\treturn (\n\t\t(prototype == null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) &&\n\t\t!(Symbol.toStringTag in value)\n\t);\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, WriteableLevel } from \"./type-utils\";\n\nexport const defineEnum = <const TValue, TWriteableLevel extends WriteableLevel = \"shallow\">(\n\tvalue: TValue\n) => value as Prettify<Writeable<TValue, TWriteableLevel>>;\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,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,Q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AAA,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"]}
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.38",
4
+ "version": "0.8.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",
@@ -32,21 +32,22 @@
32
32
  "node": ">=18.x"
33
33
  },
34
34
  "devDependencies": {
35
- "@arethetypeswrong/cli": "^0.17.3",
35
+ "@arethetypeswrong/cli": "^0.17.4",
36
36
  "@changesets/cli": "^2.28.1",
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.4",
40
+ "@types/node": "^22.13.6",
41
41
  "@zayne-labs/tsconfig": "0.2.1",
42
42
  "clsx": "^2.1.1",
43
43
  "concurrently": "^9.1.2",
44
44
  "cross-env": "^7.0.3",
45
- "publint": "^0.3.6",
45
+ "publint": "^0.3.7",
46
46
  "size-limit": "^11.2.0",
47
47
  "terser": "^5.39.0",
48
- "tsup": "^8.3.6",
49
- "typescript": "5.7.3"
48
+ "tsup": "^8.4.0",
49
+ "typescript": "5.8.2",
50
+ "vitest": "3.0.7"
50
51
  },
51
52
  "publishConfig": {
52
53
  "access": "public",
@@ -63,11 +64,14 @@
63
64
  "build": "tsup",
64
65
  "build:dev": "cross-env NODE_ENV=development tsup",
65
66
  "build:test": "concurrently --prefix-colors \"yellow.bold,#7da4f8.bold,magenta\" --names PUBLINT,TSUP 'pnpm:lint:publint' 'pnpm:build:dev'",
67
+ "dev": "pnpm build:dev --watch",
66
68
  "lint:attw": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
67
- "lint:check-types": "tsc --pretty --incremental -p tsconfig.json",
68
69
  "lint:publint": "publint --strict .",
69
70
  "lint:size": "size-limit",
71
+ "lint:type-check": "tsc --pretty -p tsconfig.json",
70
72
  "release": "pnpm publish --no-git-checks",
71
- "test:release": "pnpx pkg-pr-new publish"
73
+ "release:test": "pnpx pkg-pr-new publish",
74
+ "test": "vitest run",
75
+ "test:dev": "vitest dev"
72
76
  }
73
77
  }