@esposter/shared 1.42.3 → 2.1.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.
- package/dist/index.d.ts +91 -126
- package/dist/index.js +1 -45393
- package/package.json +4 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
//#region src/util/parseXmlString.d.ts
|
|
2
|
-
declare const parseXmlString: <T extends object>(xmlString: string) => Promise<T>;
|
|
3
|
-
|
|
4
|
-
//#endregion
|
|
5
|
-
//#region src/util/parseXmlValue.d.ts
|
|
6
|
-
declare const parseXmlValue: (value: string) => boolean | number | string;
|
|
7
|
-
|
|
8
|
-
//#endregion
|
|
9
1
|
//#region src/models/shared/Operation.d.ts
|
|
10
2
|
declare enum Operation {
|
|
11
3
|
Create = "Create",
|
|
@@ -86,24 +78,24 @@ This is useful when you want to create a new type that contains different type v
|
|
|
86
78
|
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
87
79
|
|
|
88
80
|
interface User {
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
name: string;
|
|
82
|
+
surname: string;
|
|
91
83
|
|
|
92
|
-
|
|
84
|
+
luckyNumber?: number;
|
|
93
85
|
}
|
|
94
86
|
|
|
95
87
|
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
96
88
|
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
97
|
-
|
|
89
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
98
90
|
};
|
|
99
91
|
|
|
100
92
|
const update1: UpdateOperation<User> = {
|
|
101
|
-
|
|
93
|
+
name: 'Alice'
|
|
102
94
|
};
|
|
103
95
|
|
|
104
96
|
const update2: UpdateOperation<User> = {
|
|
105
|
-
|
|
106
|
-
|
|
97
|
+
name: 'Bob',
|
|
98
|
+
luckyNumber: REMOVE_FIELD
|
|
107
99
|
};
|
|
108
100
|
```
|
|
109
101
|
|
|
@@ -130,10 +122,10 @@ import type {RequiredKeysOf} from 'type-fest';
|
|
|
130
122
|
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
131
123
|
|
|
132
124
|
interface User {
|
|
133
|
-
|
|
134
|
-
|
|
125
|
+
name: string;
|
|
126
|
+
surname: string;
|
|
135
127
|
|
|
136
|
-
|
|
128
|
+
luckyNumber?: number;
|
|
137
129
|
}
|
|
138
130
|
|
|
139
131
|
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
@@ -164,20 +156,20 @@ import type {IsNever, And} from 'type-fest';
|
|
|
164
156
|
|
|
165
157
|
// https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
|
|
166
158
|
type AreStringsEqual<A extends string, B extends string> =
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
159
|
+
And<
|
|
160
|
+
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
161
|
+
IsNever<Exclude<B, A>> extends true ? true : false
|
|
162
|
+
>;
|
|
171
163
|
|
|
172
164
|
type EndIfEqual<I extends string, O extends string> =
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
165
|
+
AreStringsEqual<I, O> extends true
|
|
166
|
+
? never
|
|
167
|
+
: void;
|
|
176
168
|
|
|
177
169
|
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
170
|
+
if (input === output) {
|
|
171
|
+
process.exit(0);
|
|
172
|
+
}
|
|
181
173
|
}
|
|
182
174
|
|
|
183
175
|
endIfEqual('abc', 'abc');
|
|
@@ -235,7 +227,7 @@ const typedObject = {a: 1, b: 2} as const;
|
|
|
235
227
|
const anyObject: any = {a: 1, b: 2};
|
|
236
228
|
|
|
237
229
|
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
|
238
|
-
|
|
230
|
+
return obj[key];
|
|
239
231
|
}
|
|
240
232
|
|
|
241
233
|
const typedA = get(typedObject, 'a');
|
|
@@ -268,11 +260,11 @@ import type {IsEqual} from 'type-fest';
|
|
|
268
260
|
// This type returns a boolean for whether the given array includes the given item.
|
|
269
261
|
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
|
270
262
|
type Includes<Value extends readonly any[], Item> =
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
263
|
+
Value extends readonly [Value[0], ...infer rest]
|
|
264
|
+
? IsEqual<Value[0], Item> extends true
|
|
265
|
+
? true
|
|
266
|
+
: Includes<rest, Item>
|
|
267
|
+
: false;
|
|
276
268
|
```
|
|
277
269
|
|
|
278
270
|
@category Type Guard
|
|
@@ -294,13 +286,13 @@ Useful to flatten the type output to improve type hints shown in editors. And al
|
|
|
294
286
|
import type {Simplify} from 'type-fest';
|
|
295
287
|
|
|
296
288
|
type PositionProps = {
|
|
297
|
-
|
|
298
|
-
|
|
289
|
+
top: number;
|
|
290
|
+
left: number;
|
|
299
291
|
};
|
|
300
292
|
|
|
301
293
|
type SizeProps = {
|
|
302
|
-
|
|
303
|
-
|
|
294
|
+
width: number;
|
|
295
|
+
height: number;
|
|
304
296
|
};
|
|
305
297
|
|
|
306
298
|
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
@@ -316,15 +308,15 @@ If the type definition must be an interface (perhaps it was defined in a third-p
|
|
|
316
308
|
import type {Simplify} from 'type-fest';
|
|
317
309
|
|
|
318
310
|
interface SomeInterface {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
311
|
+
foo: number;
|
|
312
|
+
bar?: string;
|
|
313
|
+
baz: number | undefined;
|
|
322
314
|
}
|
|
323
315
|
|
|
324
316
|
type SomeType = {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
317
|
+
foo: number;
|
|
318
|
+
bar?: string;
|
|
319
|
+
baz: number | undefined;
|
|
328
320
|
};
|
|
329
321
|
|
|
330
322
|
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
@@ -372,13 +364,13 @@ Instead of causing a type error like the above, you can also use a [conditional
|
|
|
372
364
|
|
|
373
365
|
```
|
|
374
366
|
type Indexed = {} extends Record<string, unknown>
|
|
375
|
-
|
|
376
|
-
|
|
367
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
368
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
377
369
|
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
378
370
|
|
|
379
371
|
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
380
|
-
|
|
381
|
-
|
|
372
|
+
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
373
|
+
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
382
374
|
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
383
375
|
```
|
|
384
376
|
|
|
@@ -388,8 +380,8 @@ Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-type
|
|
|
388
380
|
import type {OmitIndexSignature} from 'type-fest';
|
|
389
381
|
|
|
390
382
|
type OmitIndexSignature<ObjectType> = {
|
|
391
|
-
|
|
392
|
-
|
|
383
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
384
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
393
385
|
};
|
|
394
386
|
```
|
|
395
387
|
|
|
@@ -399,12 +391,12 @@ type OmitIndexSignature<ObjectType> = {
|
|
|
399
391
|
import type {OmitIndexSignature} from 'type-fest';
|
|
400
392
|
|
|
401
393
|
type OmitIndexSignature<ObjectType> = {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
394
|
+
[KeyType in keyof ObjectType
|
|
395
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
396
|
+
as {} extends Record<KeyType, unknown>
|
|
397
|
+
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
398
|
+
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
399
|
+
]: ObjectType[KeyType];
|
|
408
400
|
};
|
|
409
401
|
```
|
|
410
402
|
|
|
@@ -415,19 +407,19 @@ If `{}` is assignable, it means that `KeyType` is an index signature and we want
|
|
|
415
407
|
import type {OmitIndexSignature} from 'type-fest';
|
|
416
408
|
|
|
417
409
|
interface Example {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
410
|
+
// These index signatures will be removed.
|
|
411
|
+
[x: string]: any
|
|
412
|
+
[x: number]: any
|
|
413
|
+
[x: symbol]: any
|
|
414
|
+
[x: `head-${string}`]: string
|
|
415
|
+
[x: `${string}-tail`]: string
|
|
416
|
+
[x: `head-${string}-tail`]: string
|
|
417
|
+
[x: `${bigint}`]: string
|
|
418
|
+
[x: `embedded-${number}`]: string
|
|
419
|
+
|
|
420
|
+
// These explicitly defined keys will remain.
|
|
421
|
+
foo: 'bar';
|
|
422
|
+
qux?: 'baz';
|
|
431
423
|
}
|
|
432
424
|
|
|
433
425
|
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
@@ -457,21 +449,21 @@ import type {PickIndexSignature} from 'type-fest';
|
|
|
457
449
|
declare const symbolKey: unique symbol;
|
|
458
450
|
|
|
459
451
|
type Example = {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
452
|
+
// These index signatures will remain.
|
|
453
|
+
[x: string]: unknown;
|
|
454
|
+
[x: number]: unknown;
|
|
455
|
+
[x: symbol]: unknown;
|
|
456
|
+
[x: `head-${string}`]: string;
|
|
457
|
+
[x: `${string}-tail`]: string;
|
|
458
|
+
[x: `head-${string}-tail`]: string;
|
|
459
|
+
[x: `${bigint}`]: string;
|
|
460
|
+
[x: `embedded-${number}`]: string;
|
|
461
|
+
|
|
462
|
+
// These explicitly defined keys will be removed.
|
|
463
|
+
['kebab-case-key']: string;
|
|
464
|
+
[symbolKey]: string;
|
|
465
|
+
foo: 'bar';
|
|
466
|
+
qux?: 'baz';
|
|
475
467
|
};
|
|
476
468
|
|
|
477
469
|
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
@@ -509,17 +501,17 @@ Merge two types into a new type. Keys of the second type overrides keys of the f
|
|
|
509
501
|
import type {Merge} from 'type-fest';
|
|
510
502
|
|
|
511
503
|
interface Foo {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
504
|
+
[x: string]: unknown;
|
|
505
|
+
[x: number]: unknown;
|
|
506
|
+
foo: string;
|
|
507
|
+
bar: symbol;
|
|
516
508
|
}
|
|
517
509
|
|
|
518
510
|
type Bar = {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
511
|
+
[x: number]: number;
|
|
512
|
+
[x: symbol]: unknown;
|
|
513
|
+
bar: Date;
|
|
514
|
+
baz: boolean;
|
|
523
515
|
};
|
|
524
516
|
|
|
525
517
|
export type FooBar = Merge<Foo, Bar>;
|
|
@@ -665,33 +657,6 @@ type Filtered = Filter<'bar', 'foo'>;
|
|
|
665
657
|
//=> 'bar'
|
|
666
658
|
```
|
|
667
659
|
|
|
668
|
-
@see {Except}
|
|
669
|
-
*/
|
|
670
|
-
/**
|
|
671
|
-
Filter out keys from an object.
|
|
672
|
-
|
|
673
|
-
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
674
|
-
Returns `never` if `Key` extends `Exclude`.
|
|
675
|
-
Returns `Key` otherwise.
|
|
676
|
-
|
|
677
|
-
@example
|
|
678
|
-
```
|
|
679
|
-
type Filtered = Filter<'foo', 'foo'>;
|
|
680
|
-
//=> never
|
|
681
|
-
```
|
|
682
|
-
|
|
683
|
-
@example
|
|
684
|
-
```
|
|
685
|
-
type Filtered = Filter<'bar', string>;
|
|
686
|
-
//=> never
|
|
687
|
-
```
|
|
688
|
-
|
|
689
|
-
@example
|
|
690
|
-
```
|
|
691
|
-
type Filtered = Filter<'bar', 'foo'>;
|
|
692
|
-
//=> 'bar'
|
|
693
|
-
```
|
|
694
|
-
|
|
695
660
|
@see {Except}
|
|
696
661
|
*/
|
|
697
662
|
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
@@ -722,8 +687,8 @@ This type was proposed to the TypeScript team, which declined it, saying they pr
|
|
|
722
687
|
import type {Except} from 'type-fest';
|
|
723
688
|
|
|
724
689
|
type Foo = {
|
|
725
|
-
|
|
726
|
-
|
|
690
|
+
a: number;
|
|
691
|
+
b: string;
|
|
727
692
|
};
|
|
728
693
|
|
|
729
694
|
type FooWithoutA = Except<Foo, 'a'>;
|
|
@@ -743,10 +708,10 @@ const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
|
743
708
|
// Consider the following example:
|
|
744
709
|
|
|
745
710
|
type UserData = {
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
711
|
+
[metadata: string]: string;
|
|
712
|
+
email: string;
|
|
713
|
+
name: string;
|
|
714
|
+
role: 'admin' | 'user';
|
|
750
715
|
};
|
|
751
716
|
|
|
752
717
|
// `Omit` clearly doesn't behave as expected in this case:
|
|
@@ -836,4 +801,4 @@ declare const UUIDV4_SEARCH_REGEX: RegExp;
|
|
|
836
801
|
declare const uuidValidateV4: (uuid: string) => boolean;
|
|
837
802
|
|
|
838
803
|
//#endregion
|
|
839
|
-
export { CamelToKebab, ExcludeFunctionProperties, FunctionProperties, ID_SEPARATOR, InvalidOperationError, KebabToCamel, MergeObjectsStrict, NIL, NotFoundError, NotInitializedError, Operation, SkipFirst, TakeFirst, TupleSlice, TupleSplit, TupleSplitHead, TupleSplitTail, UUIDV4_REGEX, UUIDV4_SEARCH_REGEX, capitalize, exhaustiveGuard, isPlainObject, mergeObjectsStrict,
|
|
804
|
+
export { CamelToKebab, ExcludeFunctionProperties, FunctionProperties, ID_SEPARATOR, InvalidOperationError, KebabToCamel, MergeObjectsStrict, NIL, NotFoundError, NotInitializedError, Operation, SkipFirst, TakeFirst, TupleSlice, TupleSplit, TupleSplitHead, TupleSplitTail, UUIDV4_REGEX, UUIDV4_SEARCH_REGEX, capitalize, exhaustiveGuard, isPlainObject, mergeObjectsStrict, toKebabCase, uuidValidateV4 };
|