@zayne-labs/toolkit-type-helpers 0.9.46 → 0.9.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,7 @@
1
- type Prettify<TObject> = NonNullable<unknown> & {
2
- [Key in keyof TObject]: TObject[Key];
3
- };
1
+ //#region src/type-utils/common.d.ts
2
+ type Prettify<TObject> = NonNullable<unknown> & { [Key in keyof TObject]: TObject[Key] };
4
3
  type UnmaskType<TType> = {
5
- _: TType;
4
+ _: TType;
6
5
  }["_"];
7
6
  type NonFalsy<TType> = TType extends "" | 0 | 0n | false | null | undefined ? never : TType;
8
7
  type PrettyOmit<TObject, Key extends keyof TObject> = Prettify<Omit<TObject, Key>>;
@@ -30,7 +29,12 @@ type AnyString = string & Record<never, never>;
30
29
  */
31
30
  type AnyNumber = number & Record<never, never>;
32
31
  type LiteralUnion<TUnion extends TBase, TBase = string> = TUnion | (TBase & Record<never, never>);
32
+ type Expect<TType extends true> = TType;
33
+ type GetGenericFn<TType> = <TGenericFnParam>() => TGenericFnParam extends TType ? true : false;
34
+ type Equal<TTypeOne, TTypeTwo> = GetGenericFn<TTypeOne> extends GetGenericFn<TTypeTwo> ? true : false;
33
35
 
36
+ //#endregion
37
+ //#region src/type-utils/writeable.d.ts
34
38
  type ArrayOrObject = Record<number | string | symbol, unknown> | unknown[];
35
39
  type WriteableLevel = "deep" | "shallow";
36
40
  /**
@@ -39,16 +43,10 @@ type WriteableLevel = "deep" | "shallow";
39
43
  * @template TObject - The object type to make writeable
40
44
  * @template TVariant - The level of writeable transformation ("shallow" | "deep")
41
45
  */
42
- type Writeable<TObject, TLevel extends WriteableLevel = "shallow"> = TObject extends readonly [
43
- ...infer TTupleItems
44
- ] ? [
45
- ...{
46
- [Index in keyof TTupleItems]: TLevel extends "deep" ? Writeable<TTupleItems[Index], "deep"> : TTupleItems[Index];
47
- }
48
- ] : TObject extends ArrayOrObject ? {
49
- -readonly [Key in keyof TObject]: TLevel extends "deep" ? Writeable<TObject[Key], "deep"> : TObject[Key];
50
- } : TObject;
46
+ type Writeable<TObject, TLevel extends WriteableLevel = "shallow"> = TObject extends readonly [...infer TTupleItems] ? [...{ [Index in keyof TTupleItems]: TLevel extends "deep" ? Writeable<TTupleItems[Index], "deep"> : TTupleItems[Index] }] : TObject extends ArrayOrObject ? { -readonly [Key in keyof TObject]: TLevel extends "deep" ? Writeable<TObject[Key], "deep"> : TObject[Key] } : TObject;
51
47
 
48
+ //#endregion
49
+ //#region src/type-utils/union.d.ts
52
50
  type ErrorMessages<TType extends number | string | symbol = never> = Partial<Record<"$all" | number | symbol | (AnyString | TType), unknown>> | null;
53
51
  /**
54
52
  * Type utility that takes two types and allows only the properties of the first type. The properties of the second will be disallowed (typed as `never` by default or a custom message).
@@ -57,9 +55,7 @@ type ErrorMessages<TType extends number | string | symbol = never> = Partial<Rec
57
55
  * @template TSecondType The second type. Properties of this type will be disallowed.
58
56
  * @template TErrorMessages An object of custom messages to display on the properties of the second type that are disallowed.
59
57
  */
60
- type AllowOnlyFirst<TFirstType, TSecondType, TErrorMessages extends ErrorMessages = never> = Prettify<TFirstType & {
61
- [Key in keyof Omit<TSecondType, keyof TFirstType>]?: Key extends keyof TErrorMessages ? TErrorMessages[Key] : "$all" extends keyof TErrorMessages ? TErrorMessages["$all"] : TErrorMessages extends null ? TErrorMessages : never;
62
- }>;
58
+ type AllowOnlyFirst<TFirstType, TSecondType, TErrorMessages extends ErrorMessages = never> = Prettify<TFirstType & { [Key in keyof Omit<TSecondType, keyof TFirstType>]?: Key extends keyof TErrorMessages ? TErrorMessages[Key] : "$all" extends keyof TErrorMessages ? TErrorMessages["$all"] : TErrorMessages extends null ? TErrorMessages : never }>;
63
59
  /**
64
60
  * Merges all types in an array of types into one type.
65
61
  *
@@ -79,8 +75,10 @@ type MergeTypes<TArrayOfTypes extends unknown[], TAccumulator = NonNullable<unkn
79
75
  type UnionDiscriminator<TArrayOfTypes extends unknown[], TErrorMessages extends ErrorMessages<keyof MergeTypes<TArrayOfTypes>> = never, TAccumulator = never, TMergedProperties = MergeTypes<TArrayOfTypes>> = TArrayOfTypes extends [infer TFirstType, ...infer TRest] ? UnionDiscriminator<TRest, TErrorMessages, TAccumulator | AllowOnlyFirst<TFirstType, TMergedProperties, TErrorMessages>, TMergedProperties> : TAccumulator;
80
76
  type UnionVariant = "keys" | "values";
81
77
  type ExtractUnion<TObject, TVariant extends UnionVariant = "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;
82
- type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : never) extends (param: infer TParam) => void ? TParam : never;
78
+ type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : never) extends ((param: infer TParam) => void) ? TParam : never;
83
79
 
80
+ //#endregion
81
+ //#region src/guard.d.ts
84
82
  declare const isString: (value: unknown) => value is string;
85
83
  declare const isNumber: (value: unknown) => value is number;
86
84
  declare const isSymbol: (value: unknown) => value is symbol;
@@ -100,43 +98,49 @@ declare const isAsyncFunction: <TAsyncFunction extends AnyAsyncFunction>(value:
100
98
  declare const isFile: (value: unknown) => value is File;
101
99
  declare const isIterable: <TIterable>(obj: object) => obj is Iterable<TIterable>;
102
100
 
101
+ //#endregion
102
+ //#region src/assert.d.ts
103
103
  declare class AssertionError extends Error {
104
- name: string;
105
- constructor(message?: string);
104
+ name: string;
105
+ constructor(message?: string);
106
106
  }
107
107
  declare const assertDefined: <TValue>(value: TValue) => NonNullable<TValue>;
108
108
  declare const assertENV: (variable: string | undefined, message?: string) => string;
109
109
  type AssertOptions = {
110
- message: string;
110
+ message: string;
111
111
  };
112
112
  type AssertFn = {
113
- (condition: boolean, messageOrOptions?: string | AssertOptions): asserts condition;
114
- <TValue>(value: TValue, messageOrOptions?: string | AssertOptions): asserts value is NonNullable<TValue>;
113
+ (condition: boolean, messageOrOptions?: string | AssertOptions): asserts condition;
114
+ <TValue>(value: TValue, messageOrOptions?: string | AssertOptions): asserts value is NonNullable<TValue>;
115
115
  };
116
116
  declare const assert: AssertFn;
117
117
 
118
+ //#endregion
119
+ //#region src/enum.d.ts
118
120
  type DefineEnumOptions = {
119
- unionVariant?: UnionVariant;
120
- writeableLevel?: WriteableLevel;
121
+ unionVariant?: UnionVariant;
122
+ writeableLevel?: WriteableLevel;
121
123
  };
122
124
  declare const defineEnum: <const TValue extends object, TOptions extends DefineEnumOptions = DefineEnumOptions>(value: TValue, _options?: TOptions) => Prettify<Writeable<TValue, TOptions["writeableLevel"] extends WriteableLevel ? TOptions["writeableLevel"] : "shallow">> & {
123
- "~inferredUnion": ExtractUnion<TValue, TOptions["unionVariant"] extends UnionVariant ? TOptions["unionVariant"] : "values">;
125
+ "~inferredUnion": ExtractUnion<TValue, TOptions["unionVariant"] extends UnionVariant ? TOptions["unionVariant"] : "values">;
124
126
  };
125
127
  type DefineEnumDeepOptions = Pick<DefineEnumOptions, "unionVariant">;
126
128
  declare const defineEnumDeep: <const TValue extends object, TOptions extends DefineEnumDeepOptions = DefineEnumDeepOptions>(value: TValue, _options?: TOptions) => (Writeable<TValue, (TOptions & {
127
- writeableLevel: "deep";
129
+ writeableLevel: "deep";
128
130
  })["writeableLevel"] extends WriteableLevel ? (TOptions & {
129
- writeableLevel: "deep";
131
+ writeableLevel: "deep";
130
132
  })["writeableLevel"] : "shallow"> extends infer T ? { [Key in keyof T]: Writeable<TValue, (TOptions & {
131
- writeableLevel: "deep";
133
+ writeableLevel: "deep";
132
134
  })["writeableLevel"] extends WriteableLevel ? (TOptions & {
135
+ writeableLevel: "deep";
136
+ })["writeableLevel"] : "shallow">[Key] } : never) & {
137
+ "~inferredUnion": ExtractUnion<TValue, (TOptions & {
138
+ writeableLevel: "deep";
139
+ })["unionVariant"] extends UnionVariant ? (TOptions & {
133
140
  writeableLevel: "deep";
134
- })["writeableLevel"] : "shallow">[Key]; } : never) & {
135
- "~inferredUnion": ExtractUnion<TValue, (TOptions & {
136
- writeableLevel: "deep";
137
- })["unionVariant"] extends UnionVariant ? (TOptions & {
138
- writeableLevel: "deep";
139
- })["unionVariant"] : "values">;
141
+ })["unionVariant"] : "values">;
140
142
  };
141
143
 
142
- export { type AnyAsyncFunction, type AnyFunction, type AnyNumber, type AnyObject, type AnyString, AssertionError, type Awaitable, type CallbackFn, type EmptyObject, type ExtractUnion, type LiteralUnion, type NonEmptyArray, type NonFalsy, type Prettify, type PrettyOmit, type PrettyPick, type SelectorFn, type UnionDiscriminator, type UnionToIntersection, type UnionVariant, type UnknownObject, type UnknownObjectWithAnyKey, type UnmaskType, type Writeable, type WriteableLevel, assert, assertDefined, assertENV, defineEnum, defineEnumDeep, hasObjectPrototype, isArray, isAsyncFunction, isBoolean, isFile, isFormData, isFunction, isIterable, isNumber, isObject, isObjectAndNotArray, isPlainObject, isString, isSymbol };
144
+ //#endregion
145
+ export { AnyAsyncFunction, AnyFunction, AnyNumber, AnyObject, AnyString, AssertionError, Awaitable, CallbackFn, EmptyObject, Equal, Expect, ExtractUnion, LiteralUnion, NonEmptyArray, NonFalsy, Prettify, PrettyOmit, PrettyPick, SelectorFn, UnionDiscriminator, UnionToIntersection, UnionVariant, UnknownObject, UnknownObjectWithAnyKey, UnmaskType, Writeable, WriteableLevel, assert, assertDefined, assertENV, defineEnum, defineEnumDeep, hasObjectPrototype, isArray, isAsyncFunction, isBoolean, isFile, isFormData, isFunction, isIterable, isNumber, isObject, isObjectAndNotArray, isPlainObject, isString, isSymbol };
146
+ //# sourceMappingURL=index.d.ts.map
package/dist/esm/index.js CHANGED
@@ -1,81 +1,73 @@
1
- // src/guard.ts
2
- var isString = (value) => typeof value === "string";
3
- var isNumber = (value) => typeof value === "number";
4
- var isSymbol = (value) => typeof value === "symbol";
5
- var isBoolean = (value) => typeof value === "boolean";
6
- var isArray = (value) => Array.isArray(value);
7
- var isFormData = (value) => value instanceof FormData;
8
- var isObject = (value) => typeof value === "object" && value !== null;
9
- var isObjectAndNotArray = (value) => {
10
- return isObject(value) && !isArray(value);
1
+ //#region src/guard.ts
2
+ const isString = (value) => typeof value === "string";
3
+ const isNumber = (value) => typeof value === "number";
4
+ const isSymbol = (value) => typeof value === "symbol";
5
+ const isBoolean = (value) => typeof value === "boolean";
6
+ const isArray = (value) => Array.isArray(value);
7
+ const isFormData = (value) => value instanceof FormData;
8
+ const isObject = (value) => typeof value === "object" && value !== null;
9
+ const isObjectAndNotArray = (value) => {
10
+ return isObject(value) && !isArray(value);
11
11
  };
12
- var hasObjectPrototype = (value) => {
13
- return Object.prototype.toString.call(value) === "[object Object]";
12
+ const hasObjectPrototype = (value) => {
13
+ return Object.prototype.toString.call(value) === "[object Object]";
14
14
  };
15
- var isPlainObject = (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) {
31
- return false;
32
- }
33
- return true;
15
+ /**
16
+ * @description Copied from TanStack Query's isPlainObject
17
+ * @see https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L321
18
+ */
19
+ const isPlainObject = (value) => {
20
+ if (!hasObjectPrototype(value)) return false;
21
+ const constructor = value?.constructor;
22
+ if (constructor === void 0) return true;
23
+ const prototype = constructor.prototype;
24
+ if (!hasObjectPrototype(prototype)) return false;
25
+ if (!Object.hasOwn(prototype, "isPrototypeOf")) return false;
26
+ if (Object.getPrototypeOf(value) !== Object.prototype) return false;
27
+ return true;
34
28
  };
35
- var isFunction = (value) => {
36
- return typeof value === "function";
29
+ const isFunction = (value) => {
30
+ return typeof value === "function";
37
31
  };
38
- var isAsyncFunction = (value) => {
39
- return isFunction(value) && value.constructor.name === "AsyncFunction";
32
+ const isAsyncFunction = (value) => {
33
+ return isFunction(value) && value.constructor.name === "AsyncFunction";
40
34
  };
41
- var isFile = (value) => value instanceof File;
42
- var isIterable = (obj) => Symbol.iterator in obj;
35
+ const isFile = (value) => value instanceof File;
36
+ const isIterable = (obj) => Symbol.iterator in obj;
43
37
 
44
- // src/assert.ts
38
+ //#endregion
39
+ //#region src/assert.ts
45
40
  var AssertionError = class extends Error {
46
- name = "AssertionError";
47
- constructor(message) {
48
- const prefix = "Assertion failed";
49
- super(message ? `${prefix}: ${message}` : message);
50
- }
41
+ name = "AssertionError";
42
+ constructor(message) {
43
+ const prefix = "Assertion failed";
44
+ super(message ? `${prefix}: ${message}` : message);
45
+ }
51
46
  };
52
- var assertDefined = (value) => {
53
- if (value == null) {
54
- throw new AssertionError(`The value passed is "${value}!"`);
55
- }
56
- return value;
47
+ const assertDefined = (value) => {
48
+ if (value == null) throw new AssertionError(`The value passed is "${value}!"`);
49
+ return value;
57
50
  };
58
- var assertENV = (variable, message) => {
59
- if (variable === void 0) {
60
- throw new AssertionError(message);
61
- }
62
- return variable;
51
+ const assertENV = (variable, message) => {
52
+ if (variable === void 0) throw new AssertionError(message);
53
+ return variable;
63
54
  };
64
- var assert = (input, messageOrOptions) => {
65
- if (input === false || input == null) {
66
- const message = isString(messageOrOptions) ? messageOrOptions : messageOrOptions?.message;
67
- throw new AssertionError(message);
68
- }
55
+ const assert = (input, messageOrOptions) => {
56
+ if (input === false || input == null) {
57
+ const message = isString(messageOrOptions) ? messageOrOptions : messageOrOptions?.message;
58
+ throw new AssertionError(message);
59
+ }
69
60
  };
70
61
 
71
- // src/enum.ts
72
- var defineEnum = (value, _options) => {
73
- return value;
62
+ //#endregion
63
+ //#region src/enum.ts
64
+ const defineEnum = (value, _options) => {
65
+ return value;
74
66
  };
75
- var defineEnumDeep = (value, _options) => {
76
- return defineEnum(value);
67
+ const defineEnumDeep = (value, _options) => {
68
+ return defineEnum(value);
77
69
  };
78
70
 
71
+ //#endregion
79
72
  export { AssertionError, assert, assertDefined, assertENV, defineEnum, defineEnumDeep, hasObjectPrototype, isArray, isAsyncFunction, isBoolean, isFile, isFormData, isFunction, isIterable, isNumber, isObject, isObjectAndNotArray, isPlainObject, isString, isSymbol };
80
- //# sourceMappingURL=index.js.map
81
73
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/guard.ts","../../src/assert.ts","../../src/enum.ts"],"names":[],"mappings":"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","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 { ExtractUnion, Prettify, UnionVariant, Writeable, WriteableLevel } from \"./type-utils\";\n\ntype DefineEnumOptions = {\n\tunionVariant?: UnionVariant;\n\twriteableLevel?: WriteableLevel;\n};\n\nexport const defineEnum = <\n\tconst TValue extends object,\n\tTOptions extends DefineEnumOptions = DefineEnumOptions,\n>(\n\tvalue: TValue,\n\t_options?: TOptions\n) => {\n\ttype UnionProp = {\n\t\t\"~inferredUnion\": ExtractUnion<\n\t\t\tTValue,\n\t\t\tTOptions[\"unionVariant\"] extends UnionVariant ? TOptions[\"unionVariant\"] : \"values\"\n\t\t>;\n\t};\n\n\treturn value as Prettify<\n\t\tWriteable<\n\t\t\tTValue,\n\t\t\tTOptions[\"writeableLevel\"] extends WriteableLevel ? TOptions[\"writeableLevel\"] : \"shallow\"\n\t\t>\n\t>\n\t\t& UnionProp;\n};\n\ntype DefineEnumDeepOptions = Pick<DefineEnumOptions, \"unionVariant\">;\n\nexport const defineEnumDeep = <\n\tconst TValue extends object,\n\tTOptions extends DefineEnumDeepOptions = DefineEnumDeepOptions,\n>(\n\tvalue: TValue,\n\t_options?: TOptions\n) => {\n\treturn defineEnum<TValue, TOptions & { writeableLevel: \"deep\" }>(value);\n};\n"]}
1
+ {"version":3,"file":"index.js","names":["value: unknown","obj: object","message?: string","value: TValue","variable: string | undefined","assert: AssertFn","input: unknown","messageOrOptions?: string | AssertOptions","value: TValue","_options?: TOptions"],"sources":["../../src/guard.ts","../../src/assert.ts","../../src/enum.ts"],"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 { ExtractUnion, Prettify, UnionVariant, Writeable, WriteableLevel } from \"./type-utils\";\n\ntype DefineEnumOptions = {\n\tunionVariant?: UnionVariant;\n\twriteableLevel?: WriteableLevel;\n};\n\nexport const defineEnum = <\n\tconst TValue extends object,\n\tTOptions extends DefineEnumOptions = DefineEnumOptions,\n>(\n\tvalue: TValue,\n\t_options?: TOptions\n) => {\n\ttype UnionProp = {\n\t\t\"~inferredUnion\": ExtractUnion<\n\t\t\tTValue,\n\t\t\tTOptions[\"unionVariant\"] extends UnionVariant ? TOptions[\"unionVariant\"] : \"values\"\n\t\t>;\n\t};\n\n\treturn value as Prettify<\n\t\tWriteable<\n\t\t\tTValue,\n\t\t\tTOptions[\"writeableLevel\"] extends WriteableLevel ? TOptions[\"writeableLevel\"] : \"shallow\"\n\t\t>\n\t>\n\t\t& UnionProp;\n};\n\ntype DefineEnumDeepOptions = Pick<DefineEnumOptions, \"unionVariant\">;\n\nexport const defineEnumDeep = <\n\tconst TValue extends object,\n\tTOptions extends DefineEnumDeepOptions = DefineEnumDeepOptions,\n>(\n\tvalue: TValue,\n\t_options?: TOptions\n) => {\n\treturn defineEnum<TValue, TOptions & { writeableLevel: \"deep\" }>(value);\n};\n"],"mappings":";AAOA,MAAa,WAAW,CAACA,iBAA0B,UAAU;AAE7D,MAAa,WAAW,CAACA,iBAA0B,UAAU;AAE7D,MAAa,WAAW,CAACA,iBAA0B,UAAU;AAE7D,MAAa,YAAY,CAACA,iBAA0B,UAAU;AAE9D,MAAa,UAAU,CAASA,UAAsC,MAAM,QAAQ,MAAM;AAE1F,MAAa,aAAa,CAACA,UAAmB,iBAAiB;AAE/D,MAAa,WAAW,CAACA,iBAA0B,UAAU,YAAY,UAAU;AAEnF,MAAa,sBAAsB,CAA0BA,UAAqC;AACjG,QAAO,SAAS,MAAM,KAAK,QAAQ,MAAM;AACzC;AAED,MAAa,qBAAqB,CAACA,UAAmB;AACrD,QAAO,OAAO,UAAU,SAAS,KAAK,MAAM,KAAK;AACjD;;;;;AAMD,MAAa,gBAAgB,CAC5BA,UAC2B;AAC3B,MAAK,mBAAmB,MAAM,CAC7B,QAAO;CAIR,MAAM,cAAe,OAA8B;AACnD,KAAI,uBACH,QAAO;CAIR,MAAM,YAAY,YAAY;AAC9B,MAAK,mBAAmB,UAAU,CACjC,QAAO;AAIR,MAAK,OAAO,OAAO,WAAW,gBAAgB,CAC7C,QAAO;AAIR,KAAI,OAAO,eAAe,MAAM,KAAK,OAAO,UAC3C,QAAO;AAIR,QAAO;AACP;AAED,MAAa,aAAa,CAAgCA,UAAuC;AAChG,eAAc,UAAU;AACxB;AAED,MAAa,kBAAkB,CAC9BA,UAC6B;AAC7B,QAAO,WAAW,MAAM,IAAI,MAAM,YAAY,SAAS;AACvD;AAED,MAAa,SAAS,CAACA,UAAkC,iBAAiB;AAE1E,MAAa,aAAa,CAAYC,QAA4C,OAAO,YAAY;;;;AC5ErG,IAAa,iBAAb,cAAoC,MAAM;CACzC,AAAS,OAAO;CAEhB,YAAYC,SAAkB;EAC7B,MAAM,SAAS;AAEf,QAAM,WAAW,EAAE,OAAO,IAAI,QAAQ,IAAI,QAAQ;CAClD;AACD;AAED,MAAa,gBAAgB,CAASC,UAAkB;AACvD,KAAI,SAAS,KACZ,OAAM,IAAI,gBAAgB,uBAAuB,MAA0B;AAG5E,QAAO;AACP;AAED,MAAa,YAAY,CAACC,UAA8BF,YAAqB;AAC5E,KAAI,oBACH,OAAM,IAAI,eAAe;AAG1B,QAAO;AACP;AAeD,MAAaG,SAAmB,CAACC,OAAgBC,qBAA8C;AAC9F,KAAI,UAAU,SAAS,SAAS,MAAM;EACrC,MAAM,UAAU,SAAS,iBAAiB,GAAG,mBAAmB,kBAAkB;AAElF,QAAM,IAAI,eAAe;CACzB;AACD;;;;ACxCD,MAAa,aAAa,CAIzBC,OACAC,aACI;AAQJ,QAAO;AAOP;AAID,MAAa,iBAAiB,CAI7BD,OACAC,aACI;AACJ,QAAO,WAA0D,MAAM;AACvE"}
@@ -1 +0,0 @@
1
- export {};
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.46",
4
+ "version": "0.9.47",
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",
@@ -42,7 +42,7 @@
42
42
  "cross-env": "^7.0.3",
43
43
  "publint": "^0.3.12",
44
44
  "size-limit": "^11.2.0",
45
- "tsup": "^8.5.0",
45
+ "tsdown": "^0.12.3",
46
46
  "typescript": "5.8.3",
47
47
  "vitest": "3.1.3"
48
48
  },
@@ -58,8 +58,8 @@
58
58
  }
59
59
  ],
60
60
  "scripts": {
61
- "build": "tsup",
62
- "build:dev": "cross-env NODE_ENV=development tsup",
61
+ "build": "tsdown",
62
+ "build:dev": "cross-env NODE_ENV=development tsdown",
63
63
  "build:test": "concurrently --prefix-colors \"yellow.bold,#7da4f8.bold,magenta\" --names PUBLINT,TSUP 'pnpm:lint:publint' 'pnpm:build:dev'",
64
64
  "dev": "pnpm build:dev --watch",
65
65
  "lint:attw": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
@@ -1 +0,0 @@
1
- export {};