@esposter/shared 2.13.1 → 2.14.0

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +126 -90
  2. package/package.json +3 -3
package/dist/index.d.ts CHANGED
@@ -90,27 +90,81 @@ declare const uncapitalize: <T extends string>(string: T) => Uncapitalize<T>;
90
90
  //#region src/util/types/FunctionProperties.d.ts
91
91
  type FunctionProperties<T> = { [K in keyof T]: T[K] extends Function ? K : never };
92
92
  //#endregion
93
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/observable-like.d.ts
94
- declare global {
95
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
96
- interface SymbolConstructor {
97
- readonly observable: symbol;
98
- }
93
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/is-any.d.ts
94
+ /**
95
+ Returns a boolean for whether the given type is `any`.
96
+
97
+ @link https://stackoverflow.com/a/49928360/1490091
98
+
99
+ Useful in type utilities, such as disallowing `any`s to be passed to a function.
100
+
101
+ @example
102
+ ```
103
+ import type {IsAny} from 'type-fest';
104
+
105
+ const typedObject = {a: 1, b: 2} as const;
106
+ const anyObject: any = {a: 1, b: 2};
107
+
108
+ function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
109
+ return obj[key];
99
110
  }
100
111
 
101
- /**
102
- @remarks
103
- The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021.
104
- As well, some guidance on making an `Observable` to not include `closed` property.
105
- @see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
106
- @see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
107
- @see https://github.com/benlesh/symbol-observable#making-an-object-observable
108
-
109
- @category Observable
112
+ const typedA = get(typedObject, 'a');
113
+ //=> 1
114
+
115
+ const anyA = get(anyObject, 'a');
116
+ //=> any
117
+ ```
118
+
119
+ @category Type Guard
120
+ @category Utilities
110
121
  */
122
+ type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
123
+ //#endregion
124
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/is-optional-key-of.d.ts
125
+ /**
126
+ Returns a boolean for whether the given key is an optional key of type.
127
+
128
+ This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
129
+
130
+ @example
131
+ ```
132
+ import type {IsOptionalKeyOf} from 'type-fest';
111
133
 
134
+ interface User {
135
+ name: string;
136
+ surname: string;
137
+
138
+ luckyNumber?: number;
139
+ }
140
+
141
+ interface Admin {
142
+ name: string;
143
+ surname?: string;
144
+ }
145
+
146
+ type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
147
+ //=> true
148
+
149
+ type T2 = IsOptionalKeyOf<User, 'name'>;
150
+ //=> false
151
+
152
+ type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
153
+ //=> boolean
154
+
155
+ type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
156
+ //=> false
157
+
158
+ type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
159
+ //=> boolean
160
+ ```
161
+
162
+ @category Type Guard
163
+ @category Utilities
164
+ */
165
+ type IsOptionalKeyOf<Type extends object, Key extends keyof Type> = IsAny<Type | Key> extends true ? never : Key extends keyof Type ? Type extends Record<Key, Type[Key]> ? false : true : false;
112
166
  //#endregion
113
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/optional-keys-of.d.ts
167
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/optional-keys-of.d.ts
114
168
  /**
115
169
  Extract all optional keys from the given type.
116
170
 
@@ -144,11 +198,11 @@ const update2: UpdateOperation<User> = {
144
198
 
145
199
  @category Utilities
146
200
  */
147
- type OptionalKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
148
- ? (keyof { [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
149
- : never; // Should never happen
201
+ type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
202
+ ? (keyof { [Key in keyof Type as IsOptionalKeyOf<Type, Key> extends false ? never : Key]: never }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
203
+ : never;
150
204
  //#endregion
151
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/required-keys-of.d.ts
205
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/required-keys-of.d.ts
152
206
  /**
153
207
  Extract all required keys from the given type.
154
208
 
@@ -173,11 +227,10 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
173
227
 
174
228
  @category Utilities
175
229
  */
176
- type RequiredKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
177
- ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>> : never; // Should never happen
178
-
230
+ type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
231
+ ? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
179
232
  //#endregion
180
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/is-never.d.ts
233
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/is-never.d.ts
181
234
  /**
182
235
  Returns a boolean for whether the given type is `never`.
183
236
 
@@ -221,64 +274,67 @@ endIfEqual('abc', '123');
221
274
  */
222
275
  type IsNever<T> = [T] extends [never] ? true : false;
223
276
  //#endregion
224
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/if-never.d.ts
277
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/if.d.ts
225
278
  /**
226
- An if-else-like type that resolves depending on whether the given type is `never`.
279
+ An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
227
280
 
228
- @see {@link IsNever}
281
+ Use-cases:
282
+ - You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
283
+
284
+ Note:
285
+ - Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
286
+ - Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
229
287
 
230
288
  @example
231
289
  ```
232
- import type {IfNever} from 'type-fest';
290
+ import {If} from 'type-fest';
233
291
 
234
- type ShouldBeTrue = IfNever<never>;
235
- //=> true
292
+ type A = If<true, 'yes', 'no'>;
293
+ //=> 'yes'
236
294
 
237
- type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
238
- //=> 'bar'
239
- ```
295
+ type B = If<false, 'yes', 'no'>;
296
+ //=> 'no'
240
297
 
241
- @category Type Guard
242
- @category Utilities
243
- */
244
- type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (IsNever<T> extends true ? TypeIfNever : TypeIfNotNever);
245
- //#endregion
246
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/is-any.d.ts
247
- // Can eventually be replaced with the built-in once this library supports
248
- // TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
249
- type NoInfer<T> = T extends infer U ? U : never;
298
+ type C = If<boolean, 'yes', 'no'>;
299
+ //=> 'yes' | 'no'
250
300
 
251
- /**
252
- Returns a boolean for whether the given type is `any`.
253
-
254
- @link https://stackoverflow.com/a/49928360/1490091
301
+ type D = If<any, 'yes', 'no'>;
302
+ //=> 'yes' | 'no'
255
303
 
256
- Useful in type utilities, such as disallowing `any`s to be passed to a function.
304
+ type E = If<never, 'yes', 'no'>;
305
+ //=> 'no'
306
+ ```
257
307
 
258
308
  @example
259
309
  ```
260
- import type {IsAny} from 'type-fest';
310
+ import {If, IsAny, IsNever} from 'type-fest';
261
311
 
262
- const typedObject = {a: 1, b: 2} as const;
263
- const anyObject: any = {a: 1, b: 2};
312
+ type A = If<IsAny<unknown>, 'is any', 'not any'>;
313
+ //=> 'not any'
264
314
 
265
- function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
266
- return obj[key];
267
- }
315
+ type B = If<IsNever<never>, 'is never', 'not never'>;
316
+ //=> 'is never'
317
+ ```
268
318
 
269
- const typedA = get(typedObject, 'a');
270
- //=> 1
319
+ @example
320
+ ```
321
+ import {If, IsEqual} from 'type-fest';
271
322
 
272
- const anyA = get(anyObject, 'a');
273
- //=> any
323
+ type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
324
+
325
+ type A = IfEqual<string, string, 'equal', 'not equal'>;
326
+ //=> 'equal'
327
+
328
+ type B = IfEqual<string, number, 'equal', 'not equal'>;
329
+ //=> 'not equal'
274
330
  ```
275
331
 
276
332
  @category Type Guard
277
333
  @category Utilities
278
334
  */
279
- type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
335
+ type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
280
336
  //#endregion
281
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/is-equal.d.ts
337
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/is-equal.d.ts
282
338
  /**
283
339
  Returns a boolean for whether the two given types are equal.
284
340
 
@@ -307,7 +363,7 @@ type Includes<Value extends readonly any[], Item> =
307
363
  */
308
364
  type IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
309
365
  //#endregion
310
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/simplify.d.ts
366
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/simplify.d.ts
311
367
  /**
312
368
  Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
313
369
 
@@ -367,7 +423,7 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
367
423
  */
368
424
  type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
369
425
  //#endregion
370
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/omit-index-signature.d.ts
426
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/omit-index-signature.d.ts
371
427
  /**
372
428
  Omit any index signatures from the given object type, leaving only explicitly defined properties.
373
429
 
@@ -460,7 +516,7 @@ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
460
516
  */
461
517
  type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
462
518
  //#endregion
463
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/pick-index-signature.d.ts
519
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/pick-index-signature.d.ts
464
520
  /**
465
521
  Pick only index signatures from the given object type, leaving out all explicitly defined properties.
466
522
 
@@ -508,7 +564,7 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
508
564
  */
509
565
  type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
510
566
  //#endregion
511
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/merge.d.ts
567
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/merge.d.ts
512
568
  // Merges two objects without worrying about index signatures.
513
569
  type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
514
570
 
@@ -548,29 +604,7 @@ export type FooBar = Merge<Foo, Bar>;
548
604
  */
549
605
  type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
550
606
  //#endregion
551
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/if-any.d.ts
552
- /**
553
- An if-else-like type that resolves depending on whether the given type is `any`.
554
-
555
- @see {@link IsAny}
556
-
557
- @example
558
- ```
559
- import type {IfAny} from 'type-fest';
560
-
561
- type ShouldBeTrue = IfAny<any>;
562
- //=> true
563
-
564
- type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
565
- //=> 'bar'
566
- ```
567
-
568
- @category Type Guard
569
- @category Utilities
570
- */
571
- type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (IsAny<T> extends true ? TypeIfAny : TypeIfNotAny);
572
- //#endregion
573
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/internal/object.d.ts
607
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/internal/object.d.ts
574
608
  /**
575
609
  Merges user specified options with default options.
576
610
 
@@ -623,10 +657,9 @@ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOp
623
657
  // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
624
658
  ```
625
659
  */
626
- type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = IfAny<SpecifiedOptions, Defaults, IfNever<SpecifiedOptions, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? Extract<SpecifiedOptions[Key], undefined> extends never ? Key : never : Key]: SpecifiedOptions[Key] }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
627
- >>;
660
+ type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
628
661
  //#endregion
629
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/except.d.ts
662
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/except.d.ts
630
663
  /**
631
664
  Filter out keys from an object.
632
665
 
@@ -729,6 +762,9 @@ type ExcludeFunctionProperties<T> = Except<T, FunctionProperties<T>[keyof T]>;
729
762
  //#region src/util/types/KebabToCamel.d.ts
730
763
  type KebabToCamel<S extends string> = S extends `${infer T}-${infer U}` ? `${T}${Capitalize<KebabToCamel<U>>}` : S;
731
764
  //#endregion
765
+ //#region src/util/types/MapValue.d.ts
766
+ type MapValue<BaseType> = BaseType extends Map<unknown, infer ValueType> ? ValueType : never;
767
+ //#endregion
732
768
  //#region src/util/types/TupleSplitHead.d.ts
733
769
  type TupleSplitHead<T extends unknown[], N extends number> = T["length"] extends N ? T : T extends [...infer R, unknown] ? TupleSplitHead<R, N> : never;
734
770
  //#endregion
@@ -757,4 +793,4 @@ declare const UUIDV4_REGEX: RegExp;
757
793
  //#region src/util/id/uuid/uuidValidateV4.d.ts
758
794
  declare const uuidValidateV4: (uuid: string) => boolean;
759
795
  //#endregion
760
- export { BinaryOperator, CamelToKebab, ExcludeFunctionProperties, FunctionProperties, ID_SEPARATOR, InvalidOperationError, KebabToCamel, Literal, MergeObjectsStrict, NIL, NotFoundError, NotInitializedError, Operation, SkipFirst, TakeFirst, TupleSlice, TupleSplit, TupleSplitHead, TupleSplitTail, UUIDV4_REGEX, UnaryOperator, capitalize, css, exhaustiveGuard, html, isNull, isPartitionKey, isPlainObject, isRowKey, mergeObjectsStrict, streamToText, toKebabCase, uncapitalize, uuidValidateV4 };
796
+ export { BinaryOperator, CamelToKebab, ExcludeFunctionProperties, FunctionProperties, ID_SEPARATOR, InvalidOperationError, KebabToCamel, Literal, MapValue, MergeObjectsStrict, NIL, NotFoundError, NotInitializedError, Operation, SkipFirst, TakeFirst, TupleSlice, TupleSplit, TupleSplitHead, TupleSplitTail, UUIDV4_REGEX, UnaryOperator, capitalize, css, exhaustiveGuard, html, isNull, isPartitionKey, isPlainObject, isRowKey, mergeObjectsStrict, streamToText, toKebabCase, uncapitalize, uuidValidateV4 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esposter/shared",
3
- "version": "2.13.1",
3
+ "version": "2.14.0",
4
4
  "description": "A library that contains shared typescript code.",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/Esposter/Esposter/blob/main/packages/shared#readme",
@@ -23,12 +23,12 @@
23
23
  },
24
24
  "scripts": {
25
25
  "build": "pnpm export:gen && rolldown --config rolldown.config.ts",
26
- "test": "NODE_OPTIONS=--max-old-space-size=8192 vitest",
26
+ "test": "vitest",
27
27
  "coverage": "vitest run --coverage",
28
28
  "lint": "oxlint && eslint .",
29
29
  "lint:fix": "oxlint --fix && eslint --fix .",
30
30
  "typecheck": "tsc",
31
31
  "export:gen": "ctix build --config ../configuration/.ctirc-ts"
32
32
  },
33
- "gitHead": "ccdc9fba1e2852a3a7f058c2dc73b1971c20d684"
33
+ "gitHead": "bf7676c2df907ab50a35ca2910abfcf237983a16"
34
34
  }