type-plus 3.12.1 → 3.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.
- package/README.md +35 -33
- package/lib/ComposableTypes.d.ts +8 -0
- package/lib/ComposableTypes.js +3 -0
- package/lib/ComposableTypes.js.map +1 -0
- package/lib/JSONTypes.js +10 -5
- package/lib/JSONTypes.js.map +1 -1
- package/lib/assertion/assertType.d.ts +0 -46
- package/lib/assertion/assertType.js +4 -4
- package/lib/assertion/assertType.js.map +1 -1
- package/lib/class/isConstructor.js +2 -2
- package/lib/class/isConstructor.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/math/Subtract.d.ts +1 -1
- package/lib/nominal-types/Brand.js.map +1 -1
- package/lib/nominal-types/Flavor.js +1 -2
- package/lib/nominal-types/Flavor.js.map +1 -1
- package/lib/object/KnownKeys.d.ts +2 -1
- package/lib/object/KnownKeys.js +3 -0
- package/lib/object/KnownKeys.js.map +1 -1
- package/lib/object/facade.js +3 -0
- package/lib/object/facade.js.map +1 -1
- package/lib/object/getField.js.map +1 -1
- package/lib/object/hasKey.js.map +1 -1
- package/lib/object/mapProperties.js +1 -1
- package/lib/object/mapProperties.js.map +1 -1
- package/lib/object/omit.js +1 -1
- package/lib/object/omit.js.map +1 -1
- package/lib/object/pick.js +1 -1
- package/lib/object/pick.js.map +1 -1
- package/lib/object/typeOverrideIncompatible.js.map +1 -1
- package/lib/predicates/CanAssign.d.ts +2 -1
- package/lib/predicates/CanAssign.js.map +1 -1
- package/lib/predicates/index.d.ts +1 -0
- package/lib/predicates/index.js +1 -0
- package/lib/predicates/index.js.map +1 -1
- package/lib/predicates/isEmptyObject.d.ts +1 -0
- package/lib/predicates/isEmptyObject.js +3 -0
- package/lib/predicates/isEmptyObject.js.map +1 -0
- package/lib/predicates/isType.d.ts +4 -13
- package/lib/predicates/isType.js +3 -6
- package/lib/predicates/isType.js.map +1 -1
- package/lib/promise/isPromise.d.ts +1 -1
- package/lib/promise/isPromise.js +2 -1
- package/lib/promise/isPromise.js.map +1 -1
- package/lib/promise/mapSeries.js +1 -7
- package/lib/promise/mapSeries.js.map +1 -1
- package/lib/types/Number.js +10 -6
- package/lib/types/Number.js.map +1 -1
- package/lib/types/Object.d.ts +4 -20
- package/lib/types/Object.js +1 -1
- package/lib/types/Object.js.map +1 -1
- package/lib/types/String.js +10 -6
- package/lib/types/String.js.map +1 -1
- package/lib/types/Tuple.js +10 -6
- package/lib/types/Tuple.js.map +1 -1
- package/lib/types/Union.js +9 -5
- package/lib/types/Union.js.map +1 -1
- package/lib/types/analyze.js +3 -2
- package/lib/types/analyze.js.map +1 -1
- package/lib/types/check.js +2 -2
- package/lib/types/check.js.map +1 -1
- package/lib/types/conform.js +2 -2
- package/lib/types/conform.js.map +1 -1
- package/lib/types/getPlainAnalysisReport.js +28 -24
- package/lib/types/getPlainAnalysisReport.js.map +1 -1
- package/lib/types/optional.d.ts +4 -20
- package/lib/types/required.d.ts +8 -40
- package/lib/types/satisfy.js +2 -2
- package/lib/types/satisfy.js.map +1 -1
- package/libm/ComposableTypes.js +2 -0
- package/libm/ComposableTypes.js.map +1 -0
- package/libm/JSONTypes.js +1 -0
- package/libm/JSONTypes.js.map +1 -1
- package/libm/assertion/assertType.js.map +1 -1
- package/libm/class/isConstructor.js +2 -1
- package/libm/class/isConstructor.js.map +1 -1
- package/libm/index.js +1 -0
- package/libm/index.js.map +1 -1
- package/libm/nominal-types/Brand.js.map +1 -1
- package/libm/nominal-types/Flavor.js +1 -2
- package/libm/nominal-types/Flavor.js.map +1 -1
- package/libm/object/KnownKeys.js +3 -0
- package/libm/object/KnownKeys.js.map +1 -1
- package/libm/object/facade.js +3 -0
- package/libm/object/facade.js.map +1 -1
- package/libm/object/getField.js.map +1 -1
- package/libm/object/hasKey.js.map +1 -1
- package/libm/object/omit.js.map +1 -1
- package/libm/object/pick.js.map +1 -1
- package/libm/object/typeOverrideIncompatible.js.map +1 -1
- package/libm/predicates/CanAssign.js.map +1 -1
- package/libm/predicates/index.js +1 -0
- package/libm/predicates/index.js.map +1 -1
- package/libm/predicates/isEmptyObject.js +2 -0
- package/libm/predicates/isEmptyObject.js.map +1 -0
- package/libm/predicates/isType.js +4 -5
- package/libm/predicates/isType.js.map +1 -1
- package/libm/promise/isPromise.js +2 -1
- package/libm/promise/isPromise.js.map +1 -1
- package/libm/promise/mapSeries.js +1 -7
- package/libm/promise/mapSeries.js.map +1 -1
- package/package.json +26 -29
- package/src/ComposableTypes.spec.ts +29 -0
- package/src/ComposableTypes.ts +10 -0
- package/src/JSONTypes.ts +2 -1
- package/src/UnionToIntersection.ts +1 -1
- package/src/assertion/assertType.spec.ts +4 -1
- package/src/assertion/assertType.ts +2 -2
- package/src/class/AnyConstructor.spec.ts +2 -2
- package/src/class/isConstructor.spec.ts +7 -2
- package/src/class/isConstructor.ts +4 -3
- package/src/function/AnyFunction.spec.ts +9 -9
- package/src/functional/Maybe.spec.ts +2 -3
- package/src/functional/Maybe.ts +1 -0
- package/src/index.ts +1 -0
- package/src/math/Abs.spec.ts +1 -1
- package/src/math/Digit.spec.ts +2 -2
- package/src/math/Subtract.spec.ts +1 -1
- package/src/math/Subtract.ts +1 -1
- package/src/nominal-types/Brand.ts +3 -3
- package/src/nominal-types/Flavor.ts +3 -5
- package/src/object/ExcludePropType.spec.ts +1 -1
- package/src/object/KnownKeys.spec.ts +1 -1
- package/src/object/KnownKeys.ts +13 -5
- package/src/object/Partial.spec.ts +4 -5
- package/src/object/RecursiveIntersect.spec.ts +3 -3
- package/src/object/Required.spec.ts +2 -2
- package/src/object/facade.ts +3 -0
- package/src/object/getField.spec.ts +3 -3
- package/src/object/getField.ts +2 -2
- package/src/object/hasKey.ts +1 -1
- package/src/object/hasProperty.spec.ts +3 -3
- package/src/object/mapProperties.spec.ts +2 -2
- package/src/object/omit.spec.ts +5 -5
- package/src/object/omit.ts +1 -1
- package/src/object/pick.spec.ts +1 -1
- package/src/object/pick.ts +1 -1
- package/src/object/typeOverrideIncompatible.ts +1 -1
- package/src/predicates/CanAssign.ts +6 -3
- package/src/predicates/index.ts +1 -0
- package/src/predicates/isEmptyObject.spec.ts +15 -0
- package/src/predicates/isEmptyObject.ts +2 -0
- package/src/predicates/isType.spec.ts +2 -2
- package/src/predicates/isType.ts +7 -9
- package/src/promise/PromiseValue.spec.ts +1 -1
- package/src/promise/isPromise.ts +3 -2
- package/src/promise/mapSeries.ts +3 -7
- package/src/type-checker/AnyType.ts +1 -1
- package/src/types/satisfy.accept.ts +3 -1
package/README.md
CHANGED
|
@@ -35,8 +35,8 @@ yarn add type-plus
|
|
|
35
35
|
## Runtime type checker
|
|
36
36
|
|
|
37
37
|
Bringing the power of TypeScript to JavaScript runtime.
|
|
38
|
-
At the moment, this
|
|
39
|
-
If you need more
|
|
38
|
+
At the moment, this provides some basic functionalities.
|
|
39
|
+
If you need more features, I would recommend other excellent type checking libraries such as [zod](https://github.com/colinhacks/zod).
|
|
40
40
|
|
|
41
41
|
```ts
|
|
42
42
|
const eslintConfig = T.object.create({
|
|
@@ -74,13 +74,13 @@ Types supported: `any`, `array`, `boolean`, `null`, `number`, `object`, `record`
|
|
|
74
74
|
i.e., most of the basic types are supported except `bigint`.
|
|
75
75
|
It is left out for backward compatibility reasons.
|
|
76
76
|
|
|
77
|
-
You can use one of the three functions to perform type
|
|
77
|
+
You can use one of the three functions to perform type-check:
|
|
78
78
|
|
|
79
79
|
`satisfy(type, subject)`:
|
|
80
80
|
A loose type check that permits extra elements in `Tuple` and properties in `Object`.
|
|
81
81
|
|
|
82
82
|
`conform(type, subject)`:
|
|
83
|
-
A
|
|
83
|
+
A strict type check that does not allow extra elements in `Tuple` and properties in `Object`.
|
|
84
84
|
|
|
85
85
|
`check(options, type, subject)`:
|
|
86
86
|
A general form of `satisfy()` and `conform()`.
|
|
@@ -107,7 +107,7 @@ Use the one that fits your specific needs.
|
|
|
107
107
|
✔️ `immediate`
|
|
108
108
|
|
|
109
109
|
It ensures `subject` satisfies `T`.
|
|
110
|
-
It is similar to `const x: T = subject` without introducing unused variable.
|
|
110
|
+
It is similar to `const x: T = subject` without introducing an unused variable.
|
|
111
111
|
You need to specify `T` for it to work.
|
|
112
112
|
|
|
113
113
|
`assertType<T>(subject, validator)`:
|
|
@@ -116,7 +116,7 @@ You need to specify `T` for it to work.
|
|
|
116
116
|
|
|
117
117
|
✔️ `assertion function`, `runtime`
|
|
118
118
|
|
|
119
|
-
These overloads of `assertType`
|
|
119
|
+
These overloads of `assertType` allow you to specify a `validator`.
|
|
120
120
|
With these overloads, `subject` can be `unknown` or `any`.
|
|
121
121
|
|
|
122
122
|
If `subject` fails the assertion,
|
|
@@ -163,7 +163,7 @@ const s: number | undefined = undefined
|
|
|
163
163
|
assertType.isUndefined(s) // TypeScript complains
|
|
164
164
|
```
|
|
165
165
|
|
|
166
|
-
They
|
|
166
|
+
They accept `any` and will be narrowed to the specific type.
|
|
167
167
|
|
|
168
168
|
```ts
|
|
169
169
|
const s: any = undefined
|
|
@@ -177,9 +177,9 @@ s // type is undefined
|
|
|
177
177
|
|
|
178
178
|
Check if the subject type is `never`.
|
|
179
179
|
This function is not very useful in actual code as TypeScript will indicate the error.
|
|
180
|
-
But it can be useful when writing tests for
|
|
180
|
+
But it can be useful when writing tests for types.
|
|
181
181
|
|
|
182
|
-
This is useful for
|
|
182
|
+
This is useful for variables. For type level only check, do the following:
|
|
183
183
|
|
|
184
184
|
```ts
|
|
185
185
|
assertType.isTrue(true as Equal<YourType, never>)
|
|
@@ -214,8 +214,8 @@ const s: number | undefined = 1
|
|
|
214
214
|
assertType.noUndefined(s) // TypeScript complains
|
|
215
215
|
```
|
|
216
216
|
|
|
217
|
-
They
|
|
218
|
-
assertion will
|
|
217
|
+
They accept `subject` with type `any` or `unknown`,
|
|
218
|
+
the assertion will happen in runtime to ensure `subject` is the specific type.
|
|
219
219
|
|
|
220
220
|
`isType<T>(subject: T)`:
|
|
221
221
|
|
|
@@ -250,11 +250,11 @@ It returns `true` when passes (which is the only case when used in TypeScript).
|
|
|
250
250
|
✔️ `immediate`
|
|
251
251
|
|
|
252
252
|
Slightly easier to use then `isType.t<>()` and `isType.f<>()`,
|
|
253
|
-
when doing type
|
|
253
|
+
when doing type-level only equality comparison as you don't have to import `Equal<>`.
|
|
254
254
|
|
|
255
255
|
✔️ `type guard`, `runtime`
|
|
256
256
|
|
|
257
|
-
These overloads of `isType`
|
|
257
|
+
These overloads of `isType` allow you to specify a `validator`.
|
|
258
258
|
With these overloads, `subject` can be `unknown` or `any`.
|
|
259
259
|
|
|
260
260
|
`Equal<A, B>`:
|
|
@@ -302,7 +302,7 @@ assertType.isTrue(true as CanAssign<{ a:string, b:number }, { a: string }>)
|
|
|
302
302
|
|
|
303
303
|
✔️ `immediate`, `logical`
|
|
304
304
|
|
|
305
|
-
Returns a compile
|
|
305
|
+
Returns a compile-time validating function to ensure `subject` is assignable to `T`.
|
|
306
306
|
|
|
307
307
|
```ts
|
|
308
308
|
const isConfig = canAssign<{ a: string }>()
|
|
@@ -313,7 +313,7 @@ assertType.isTrue(isConfig({ a: 'a' }))
|
|
|
313
313
|
|
|
314
314
|
✔️ `immediate`, `logical`
|
|
315
315
|
|
|
316
|
-
Returns a compile
|
|
316
|
+
Returns a compile-time validating function to ensure `subject` is not assignable to `T`.
|
|
317
317
|
|
|
318
318
|
```ts
|
|
319
319
|
const notA = canAssign<{ a: string }>(false)
|
|
@@ -324,7 +324,7 @@ notA({ a: '' }) // TypeScript complains
|
|
|
324
324
|
|
|
325
325
|
## Nominal Type
|
|
326
326
|
|
|
327
|
-
TypeScript type system is structural.
|
|
327
|
+
The TypeScript type system is structural.
|
|
328
328
|
|
|
329
329
|
In some cases, we want to express a type with nominal behavior.
|
|
330
330
|
`type-plus` provides two kinds of nominal types: `Brand` and `Flavor`.
|
|
@@ -383,12 +383,12 @@ nominalMatch(b1, b2) // false
|
|
|
383
383
|
|
|
384
384
|
## Functional Types
|
|
385
385
|
|
|
386
|
-
- `ChainFn<T>: T`: chain function that
|
|
386
|
+
- `ChainFn<T>: T`: chain function that returns the input type.
|
|
387
387
|
|
|
388
388
|
## Type Utilities
|
|
389
389
|
|
|
390
390
|
`type-plus` also provides additional type utilities.
|
|
391
|
-
These utilities
|
|
391
|
+
These utilities include utility types and type-adjusted functions.
|
|
392
392
|
|
|
393
393
|
Note that most `predicate` types (such as `IsAny<>`) have a `Then` and `Else` that you can override.
|
|
394
394
|
|
|
@@ -406,13 +406,13 @@ type No = IsAny<1, 'yes', 'no'> // 'no'
|
|
|
406
406
|
- `CreateTuple<L, T>`: creates `Tuple<T>` with `L` number of elements.
|
|
407
407
|
- `DropFirst<A>`: drops the first value type of `A`.
|
|
408
408
|
- `DropLast<A>`: drops the last value type of `A`.
|
|
409
|
-
- `Filter<A, Criteria>`: gets array of types satisfying `Criteria` in `A`.
|
|
410
|
-
- `FindFirst<A, Criteria>`: gets first type satisfying `Criteria`.
|
|
411
|
-
- `FindLast<A, Criteria>`: gets last type satisfying `Criteria`.
|
|
409
|
+
- `Filter<A, Criteria>`: gets the array of types satisfying `Criteria` in `A`.
|
|
410
|
+
- `FindFirst<A, Criteria>`: gets the first type satisfying `Criteria`.
|
|
411
|
+
- `FindLast<A, Criteria>`: gets the last type satisfying `Criteria`.
|
|
412
412
|
- `Head<A>`: gets the first entry in the array.
|
|
413
413
|
- `IntersectOfProps<A, K>`: gets the intersect of `A[K]` types (deprecate `MapToProp`)
|
|
414
414
|
- `IsArray<T>`: `logical` predicate for `Array`.
|
|
415
|
-
- `literalArray(...entries)`: return an array
|
|
415
|
+
- `literalArray(...entries)`: return an array whose items are restricted to the provided literals.
|
|
416
416
|
- `PadLeft<A, Total, PadWith>`: pads `A` with `PadWith` if the length of `A` is less than `L`.
|
|
417
417
|
- `reduceWhile()`: `reduce()` with predicate for early termination. \
|
|
418
418
|
A simple version of the same function in the `ramda` package.
|
|
@@ -426,6 +426,8 @@ type No = IsAny<1, 'yes', 'no'> // 'no'
|
|
|
426
426
|
|
|
427
427
|
- `KeyTypes`: type of all keys.
|
|
428
428
|
- `PrimitiveTypes`: all primitive types, including `Function`, `symbol`, and `bigint`.
|
|
429
|
+
- `ComposableTypes`: Types that can contain custom properties. i.e. `object`, `array`, `function`.
|
|
430
|
+
- `NonComposableTypes`: Types that cannot contain custom properties. i.e. not composable.
|
|
429
431
|
|
|
430
432
|
### JSON Support
|
|
431
433
|
|
|
@@ -467,9 +469,9 @@ JSONTypes.get<string>(someJson, 'a', 'b', 1, 'c') // miku
|
|
|
467
469
|
|
|
468
470
|
### Type manipulation
|
|
469
471
|
|
|
470
|
-
- `ANotB<A, B>`: get object with properties in `A` and not in `B`, including properties with different value type.
|
|
472
|
+
- `ANotB<A, B>`: get object with properties in `A` and not in `B`, including properties with a different value type.
|
|
471
473
|
- `BNotA<A, B>`: flip of `ANotB`
|
|
472
|
-
- `as<T>(subject)`: assert `subject` as `T`. Avoid ASI
|
|
474
|
+
- `as<T>(subject)`: assert `subject` as `T`. Avoid ASI issues such as `;(x as any).abc`
|
|
473
475
|
- `asAny(subject)`: assert `subject` as `any`. Avoid ASI issue such as `;(x as any).abc`
|
|
474
476
|
- `Except<T, K>`: Deprecated. Same as `Omit<T, K>`.
|
|
475
477
|
- `ExcludePropType<T, U>`: excludes type `U` from properties in `T`.
|
|
@@ -481,13 +483,13 @@ JSONTypes.get<string>(someJson, 'a', 'b', 1, 'c') // miku
|
|
|
481
483
|
- `PartialExcept<T, U>`: Deprecated. Same as `PartialOmit<T, U>`.
|
|
482
484
|
- `PartialOmit<T, U>`: makes the properties not specified in `U` becomes optional.
|
|
483
485
|
- `PartialPick<T, U>`: makes the properties specified in `U` becomes optional.
|
|
484
|
-
- `Pick<T, K>`: pick properties `K` from `T`. Works with
|
|
486
|
+
- `Pick<T, K>`: pick properties `K` from `T`. Works with unions.
|
|
485
487
|
- `RecursivePartial<T>`: make type `T` optional recursively.
|
|
486
488
|
- `RecursiveRequired<T>`: make type `T` required recursively.
|
|
487
489
|
- `ReplaceProperty<T, K, V>`: replace property `K` in `T` with `V`.
|
|
488
490
|
- `RequiredKeys<T>`: gets keys of required properties in `T`.
|
|
489
|
-
- `RequiredPick<T, U>`: makes the properties specified in `U`
|
|
490
|
-
- `RequiredExcept<T, U>`: makes the properties not specified in `U`
|
|
491
|
+
- `RequiredPick<T, U>`: makes the properties specified in `U` become required.
|
|
492
|
+
- `RequiredExcept<T, U>`: makes the properties not specified in `U` become required.
|
|
491
493
|
- `RecursiveIntersect<T, U>`: intersect type `U` onto `T` recursively.
|
|
492
494
|
- `ValueOf<T>`: type of the value of the properties of `T`.
|
|
493
495
|
- `Widen<T>`: widen literal types.
|
|
@@ -502,6 +504,7 @@ They can be used to compose complex types.
|
|
|
502
504
|
- `IsAny<T>`: `T === any`.
|
|
503
505
|
- `IsBoolean<T>`: check for `boolean`, but not for `true` nor `false`.
|
|
504
506
|
- `IsDisjoint<A, B>`: is `A` and `B` is a disjoint set.
|
|
507
|
+
- `IsEmptyObject<T>`: is `T === {}`.
|
|
505
508
|
- `IsLiteral<T>`: is `T` a literal type (literal string or number).
|
|
506
509
|
|
|
507
510
|
#### Logical
|
|
@@ -512,7 +515,7 @@ They can be used to compose complex types.
|
|
|
512
515
|
- `Xor<A, B>`: logical `XOR`.
|
|
513
516
|
- `Not<X>`: logical `NOT`.
|
|
514
517
|
|
|
515
|
-
Note that these types work correctly with `boolean` type.
|
|
518
|
+
Note that these types work correctly with the `boolean` type.
|
|
516
519
|
e.g.:
|
|
517
520
|
|
|
518
521
|
- `And<boolean, true> -> boolean`
|
|
@@ -532,8 +535,7 @@ So you may encounter some weird behavior if your logic is complex.
|
|
|
532
535
|
#### Arithmetics
|
|
533
536
|
|
|
534
537
|
- `Add<A, B, Fail=never>`: `A + B` for positive and whole numbers, `Fail` otherwise.
|
|
535
|
-
- `Subtract<A, B, Fail=never>`: `A - B` for positive and whole numbers, `Fail` otherwise
|
|
536
|
-
Negative result also returns `Fail`.
|
|
538
|
+
- `Subtract<A, B, Fail=never>`: `A - B` for positive and whole numbers, `Fail` otherwise.
|
|
537
539
|
- `Increment<A, Fail=never>`: alias of `Add<A, 1, Fail>`.
|
|
538
540
|
- `Decrement<A, Fail=never>`: alias of `Subtract<A, 1, Fail>`.
|
|
539
541
|
|
|
@@ -570,9 +572,9 @@ overrider(source, { foo: !!source.foo })
|
|
|
570
572
|
|
|
571
573
|
## Attribution
|
|
572
574
|
|
|
573
|
-
Some of the code in this library
|
|
574
|
-
I merely adding them in and
|
|
575
|
-
|
|
575
|
+
Some of the code in this library is created by other people in the TypeScript community.
|
|
576
|
+
I merely adding them in and maybe making some adjustments.
|
|
577
|
+
Whenever possible, I add attribution to the person who created those **codes** in the file.
|
|
576
578
|
|
|
577
579
|
## Similar projects
|
|
578
580
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types that can contain custom properties.
|
|
3
|
+
*/
|
|
4
|
+
export declare type ComposableTypes = object | Function;
|
|
5
|
+
/**
|
|
6
|
+
* Types that cannot contain custom properties.
|
|
7
|
+
*/
|
|
8
|
+
export declare type NonComposableTypes = boolean | number | string | symbol | bigint | undefined | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComposableTypes.js","sourceRoot":"","sources":["../src/ComposableTypes.ts"],"names":[],"mappings":""}
|
package/lib/JSONTypes.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
3
|
-
for (var i = 0,
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
6
10
|
};
|
|
7
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
12
|
exports.JSONTypes = void 0;
|
|
@@ -17,6 +21,7 @@ function get(obj) {
|
|
|
17
21
|
if (typeof obj !== 'object' || obj === null)
|
|
18
22
|
return undefined;
|
|
19
23
|
var p = props.shift();
|
|
20
|
-
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
return get.apply(void 0, __spreadArray([obj[p]], props, false));
|
|
21
26
|
}
|
|
22
27
|
//# sourceMappingURL=JSONTypes.js.map
|
package/lib/JSONTypes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JSONTypes.js","sourceRoot":"","sources":["../src/JSONTypes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"JSONTypes.js","sourceRoot":"","sources":["../src/JSONTypes.ts"],"names":[],"mappings":";;;;;;;;;;;;AASa,QAAA,SAAS,GAAG,EAAE,GAAG,KAAA,EAAE,CAAA;AAEhC,SAAS,GAAG,CAAsB,GAAc;IAAE,eAAgC;SAAhC,UAAgC,EAAhC,qBAAgC,EAAhC,IAAgC;QAAhC,8BAAgC;;IAChF,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,GAAQ,CAAA;IACvC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,SAAS,CAAA;IAC7D,IAAM,CAAC,GAAG,KAAK,CAAC,KAAK,EAAG,CAAA;IACxB,aAAa;IACb,OAAO,GAAG,8BAAC,GAAG,CAAC,CAAC,CAAC,GAAK,KAAK,SAAM,CAAA;AACnC,CAAC"}
|
|
@@ -5,53 +5,7 @@ import { AnyFunction } from '../function';
|
|
|
5
5
|
* @type T the type to check against.
|
|
6
6
|
*/
|
|
7
7
|
export declare function assertType<T>(subject: T): asserts subject is T;
|
|
8
|
-
export declare namespace assertType {
|
|
9
|
-
var isUndefined: (subject: undefined) => asserts subject is undefined;
|
|
10
|
-
var noUndefined: <S>(subject: Exclude<S, undefined>) => void;
|
|
11
|
-
var isNull: (subject: null) => asserts subject is null;
|
|
12
|
-
var noNull: <S>(subject: Exclude<S, null>) => void;
|
|
13
|
-
var isNumber: (subject: number) => asserts subject is number;
|
|
14
|
-
var noNumber: <S>(subject: Exclude<S, number>) => void;
|
|
15
|
-
var isBoolean: (subject: boolean) => asserts subject is boolean;
|
|
16
|
-
var noBoolean: <S>(subject: Exclude<S, boolean>) => void;
|
|
17
|
-
var isTrue: (subject: true) => asserts subject is true;
|
|
18
|
-
var noTrue: <S>(subject: Exclude<S, true>) => void;
|
|
19
|
-
var isFalse: (subject: false) => asserts subject is false;
|
|
20
|
-
var noFalse: <S>(subject: Exclude<S, false>) => void;
|
|
21
|
-
var isString: (subject: string) => asserts subject is string;
|
|
22
|
-
var noString: <S>(subject: Exclude<S, string>) => void;
|
|
23
|
-
var isFunction: (subject: AnyFunction<any[], any>) => asserts subject is AnyFunction<any[], any>;
|
|
24
|
-
var noFunction: <S>(subject: Exclude<S, AnyFunction<any[], any>>) => void;
|
|
25
|
-
var isConstructor: (subject: AnyConstructor<any[]>) => asserts subject is AnyConstructor<any[]>;
|
|
26
|
-
var isError: (subject: Error) => asserts subject is Error;
|
|
27
|
-
var noError: <S>(subject: Exclude<S, Error>) => void;
|
|
28
|
-
var isNever: (subject: never) => asserts subject is never;
|
|
29
|
-
var custom: <T>(validator: (s: T) => boolean) => (subject: unknown) => asserts subject is T;
|
|
30
|
-
}
|
|
31
8
|
export declare function assertType<T>(subject: unknown, validator: (s: T) => boolean): asserts subject is T;
|
|
32
|
-
export declare namespace assertType {
|
|
33
|
-
var isUndefined: (subject: undefined) => asserts subject is undefined;
|
|
34
|
-
var noUndefined: <S>(subject: Exclude<S, undefined>) => void;
|
|
35
|
-
var isNull: (subject: null) => asserts subject is null;
|
|
36
|
-
var noNull: <S>(subject: Exclude<S, null>) => void;
|
|
37
|
-
var isNumber: (subject: number) => asserts subject is number;
|
|
38
|
-
var noNumber: <S>(subject: Exclude<S, number>) => void;
|
|
39
|
-
var isBoolean: (subject: boolean) => asserts subject is boolean;
|
|
40
|
-
var noBoolean: <S>(subject: Exclude<S, boolean>) => void;
|
|
41
|
-
var isTrue: (subject: true) => asserts subject is true;
|
|
42
|
-
var noTrue: <S>(subject: Exclude<S, true>) => void;
|
|
43
|
-
var isFalse: (subject: false) => asserts subject is false;
|
|
44
|
-
var noFalse: <S>(subject: Exclude<S, false>) => void;
|
|
45
|
-
var isString: (subject: string) => asserts subject is string;
|
|
46
|
-
var noString: <S>(subject: Exclude<S, string>) => void;
|
|
47
|
-
var isFunction: (subject: AnyFunction<any[], any>) => asserts subject is AnyFunction<any[], any>;
|
|
48
|
-
var noFunction: <S>(subject: Exclude<S, AnyFunction<any[], any>>) => void;
|
|
49
|
-
var isConstructor: (subject: AnyConstructor<any[]>) => asserts subject is AnyConstructor<any[]>;
|
|
50
|
-
var isError: (subject: Error) => asserts subject is Error;
|
|
51
|
-
var noError: <S>(subject: Exclude<S, Error>) => void;
|
|
52
|
-
var isNever: (subject: never) => asserts subject is never;
|
|
53
|
-
var custom: <T>(validator: (s: T) => boolean) => (subject: unknown) => asserts subject is T;
|
|
54
|
-
}
|
|
55
9
|
export declare function assertType<T extends new (...args: any) => any>(subject: unknown, constructor: T): asserts subject is InstanceType<T>;
|
|
56
10
|
export declare namespace assertType {
|
|
57
11
|
var isUndefined: (subject: undefined) => asserts subject is undefined;
|
|
@@ -5,8 +5,8 @@ var tersify_1 = require("tersify");
|
|
|
5
5
|
var class_1 = require("../class");
|
|
6
6
|
function assertType(subject, validator) {
|
|
7
7
|
if (validator) {
|
|
8
|
-
if ((class_1.isConstructor(validator) && !(subject instanceof validator)) || !validator(subject))
|
|
9
|
-
throw new TypeError("subject fails to satisfy "
|
|
8
|
+
if (((0, class_1.isConstructor)(validator) && !(subject instanceof validator)) || !validator(subject))
|
|
9
|
+
throw new TypeError("subject fails to satisfy ".concat((0, tersify_1.tersify)(validator)));
|
|
10
10
|
}
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
@@ -78,7 +78,7 @@ assertType.noFunction = function (subject) {
|
|
|
78
78
|
throw TypeError("subject is function");
|
|
79
79
|
};
|
|
80
80
|
assertType.isConstructor = function (subject) {
|
|
81
|
-
if (!class_1.isConstructor(subject))
|
|
81
|
+
if (!(0, class_1.isConstructor)(subject))
|
|
82
82
|
throw TypeError("subject is not a constructor");
|
|
83
83
|
};
|
|
84
84
|
assertType.isError = function (subject) {
|
|
@@ -100,7 +100,7 @@ assertType.isNever = function (subject) {
|
|
|
100
100
|
assertType.custom = function (validator) {
|
|
101
101
|
return function (subject) {
|
|
102
102
|
if (!validator(subject))
|
|
103
|
-
throw new TypeError("subject fails to satisfy "
|
|
103
|
+
throw new TypeError("subject fails to satisfy ".concat((0, tersify_1.tersify)(validator)));
|
|
104
104
|
return;
|
|
105
105
|
};
|
|
106
106
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertType.js","sourceRoot":"","sources":["../../src/assertion/assertType.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AACjC,kCAAwD;AAUxD,SAAgB,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"assertType.js","sourceRoot":"","sources":["../../src/assertion/assertType.ts"],"names":[],"mappings":"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"}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isConstructor = void 0;
|
|
4
4
|
function isConstructor(subject) {
|
|
5
|
-
var _a;
|
|
6
5
|
try {
|
|
7
6
|
new subject();
|
|
8
7
|
}
|
|
9
8
|
catch (err) {
|
|
10
|
-
|
|
9
|
+
var msg = err === null || err === void 0 ? void 0 : err.message;
|
|
10
|
+
if (msg && msg.indexOf('is not a constructor') >= 0) {
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isConstructor.js","sourceRoot":"","sources":["../../src/class/isConstructor.ts"],"names":[],"mappings":";;;AAEA,SAAgB,aAAa,CAAC,OAAgB
|
|
1
|
+
{"version":3,"file":"isConstructor.js","sourceRoot":"","sources":["../../src/class/isConstructor.ts"],"names":[],"mappings":";;;AAEA,SAAgB,aAAa,CAAC,OAAgB;IAC5C,IAAI;QACF,IAAK,OAA0B,EAAE,CAAA;KAClC;IACD,OAAO,GAAQ,EAAE;QACf,IAAM,GAAG,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAA6B,CAAA;QAC9C,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE;YACnD,OAAO,KAAK,CAAA;SACb;KACF;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAXD,sCAWC"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -32,6 +32,7 @@ Object.defineProperty(exports, "requiredDeep", { enumerable: true, get: function
|
|
|
32
32
|
__exportStar(require("./array"), exports);
|
|
33
33
|
__exportStar(require("./assertion"), exports);
|
|
34
34
|
__exportStar(require("./class"), exports);
|
|
35
|
+
__exportStar(require("./ComposableTypes"), exports);
|
|
35
36
|
__exportStar(require("./function"), exports);
|
|
36
37
|
__exportStar(require("./functional"), exports);
|
|
37
38
|
__exportStar(require("./JSONTypes"), exports);
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAgC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAgC;AAmBvB,sBAAK;AAAW,kBAAC;AAlB1B,uCAAkD;AAAzC,qGAAA,QAAQ,OAAA;AAAE,yGAAA,YAAY,OAAA;AAC/B,0CAAuB;AACvB,8CAA2B;AAC3B,0CAAuB;AACvB,oDAAiC;AACjC,6CAA0B;AAC1B,+CAA4B;AAC5B,8CAA2B;AAC3B,yCAAsB;AACtB,kDAA+B;AAC/B,2CAAwB;AACxB,+CAA4B;AAC5B,mDAAgC;AAChC,4CAAyB;AACzB,mDAAgC;AAChC,mDAAgC;AAChC,8CAA2B;AAC3B,0CAAuB"}
|
package/lib/math/Subtract.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Digit, DigitArray } from './Digit';
|
|
|
4
4
|
import { IsPositive } from './IsPositive';
|
|
5
5
|
import { IsWhole } from './IsWhole';
|
|
6
6
|
import { Max } from './Max';
|
|
7
|
-
export declare type Subtract<A extends number, B extends number, Fail = never> = And<And<IsPositive<A>, IsWhole<A>>, And<IsPositive<B>, IsWhole<B>>> extends true ? (DigitArray.Shift10<DigitArray.FromNumber<A>> extends infer DA ? DA extends number[] ? DigitArray.FromNumber<B> extends infer DB ? DB extends number[] ? Max<DA['length'], DB['length']> extends infer M ? M extends number ? PadLeft<DA, M, 0> extends infer PDA ? PDA extends number[] ? PadLeft<DB, M, 0> extends infer PDB ? PDB extends number[] ? SubtractDigitArray<[], PDA, PDB> extends infer Result ? Result extends number[] ? Some<Result,
|
|
7
|
+
export declare type Subtract<A extends number, B extends number, Fail = never> = And<And<IsPositive<A>, IsWhole<A>>, And<IsPositive<B>, IsWhole<B>>> extends true ? (DigitArray.Shift10<DigitArray.FromNumber<A>> extends infer DA ? DA extends number[] ? DigitArray.FromNumber<B> extends infer DB ? DB extends number[] ? Max<DA['length'], DB['length']> extends infer M ? M extends number ? PadLeft<DA, M, 0> extends infer PDA ? PDA extends number[] ? PadLeft<DB, M, 0> extends infer PDB ? PDB extends number[] ? SubtractDigitArray<[], PDA, PDB> extends infer Result ? Result extends number[] ? Some<Result, never, 'strict'> extends true ? Fail : DigitArray.ToNumber<Result> : Fail : Fail : Fail : Fail : Fail : Fail : Fail : Fail : Fail : Fail : Fail : Fail) : Fail;
|
|
8
8
|
declare type SubtractDigitArray<R extends number[], A extends number[], B extends number[]> = A['length'] extends 0 ? R : SubtractDigitArray<[...R, SubtractDigit<A[0], B[0]>], Tail<A>, Tail<B>>;
|
|
9
9
|
declare type SubtractDigit<A extends number, B extends number> = Digit.ToTuple[A] extends [...(infer U), ...Digit.ToTuple[B]] ? U['length'] : never;
|
|
10
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Brand.js","sourceRoot":"","sources":["../../src/nominal-types/Brand.ts"],"names":[],"mappings":";AAAA,kHAAkH;AAClH,uEAAuE;;;AAGvE,iCAA2C;AAmB3C,SAAgB,KAAK,CAAC,IAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"Brand.js","sourceRoot":"","sources":["../../src/nominal-types/Brand.ts"],"names":[],"mappings":";AAAA,kHAAkH;AAClH,uEAAuE;;;AAGvE,iCAA2C;AAmB3C,SAAgB,KAAK,CAAC,IAAY,EAAE,OAAiB;IACnD,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,UAAa,OAAU,IAAI,OAAO,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA,CAAC,CAAC,CAAA;IAE1F,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE;QACnD,2EAA2E;QAC1E,OAAiC,CAAC,eAAO,CAAC,GAAG,IAAI,CAAA;KACnD;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AARD,sBAQC"}
|
|
@@ -5,9 +5,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
exports.flavor = void 0;
|
|
6
6
|
var types_1 = require("./types");
|
|
7
7
|
function flavor(type, subject) {
|
|
8
|
-
if (subject === undefined)
|
|
8
|
+
if (subject === undefined)
|
|
9
9
|
return function (subject) { return flavor(type, subject); };
|
|
10
|
-
}
|
|
11
10
|
if (typeof subject === 'object' && subject !== null) {
|
|
12
11
|
// if subject is not an object, the branding will exist only in type-level.
|
|
13
12
|
subject[types_1.typeSym] = type;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Flavor.js","sourceRoot":"","sources":["../../src/nominal-types/Flavor.ts"],"names":[],"mappings":";AAAA,kHAAkH;AAClH,uEAAuE;;;AAGvE,iCAAiC;AAoBjC,SAAgB,MAAM,CAAC,IAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"Flavor.js","sourceRoot":"","sources":["../../src/nominal-types/Flavor.ts"],"names":[],"mappings":";AAAA,kHAAkH;AAClH,uEAAuE;;;AAGvE,iCAAiC;AAoBjC,SAAgB,MAAM,CAAC,IAAY,EAAE,OAAiB;IACpD,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,UAAa,OAAU,IAAI,OAAO,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA,CAAC,CAAC,CAAA;IAC3F,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE;QACnD,2EAA2E;QAC1E,OAAiC,CAAC,eAAO,CAAC,GAAG,IAAI,CAAA;KACnD;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAPD,wBAOC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { PrimitiveTypes } from '../PrimitiveTypes';
|
|
2
|
+
export declare type KnownKeys<T> = T extends PrimitiveTypes ? never : {
|
|
2
3
|
[K in keyof T]: string extends K ? never : number extends K ? never : K;
|
|
3
4
|
} extends {
|
|
4
5
|
[_ in keyof T]: infer U;
|
package/lib/object/KnownKeys.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Original by Klaus Meinhardt @ajafff
|
|
3
|
+
// known from Gerrit Birkeland @Gerrit0
|
|
4
|
+
// https://github.com/Microsoft/TypeScript/issues/25987#issuecomment-408339599
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
//# sourceMappingURL=KnownKeys.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnownKeys.js","sourceRoot":"","sources":["../../src/object/KnownKeys.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"KnownKeys.js","sourceRoot":"","sources":["../../src/object/KnownKeys.ts"],"names":[],"mappings":";AAAA,sCAAsC;AACtC,uCAAuC;AACvC,8EAA8E"}
|
package/lib/object/facade.js
CHANGED
|
@@ -9,14 +9,17 @@ function facade(subject) {
|
|
|
9
9
|
return props.reduce(function (p, k) {
|
|
10
10
|
var prop = subject[k];
|
|
11
11
|
if (typeof prop === 'function') {
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
12
13
|
p[k] = prop.bind(subject);
|
|
13
14
|
}
|
|
14
15
|
else {
|
|
15
16
|
Object.defineProperty(p, k, {
|
|
16
17
|
get: function () {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
17
19
|
return subject[k];
|
|
18
20
|
},
|
|
19
21
|
set: function (value) {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-assignment
|
|
20
23
|
return subject[k] = value;
|
|
21
24
|
},
|
|
22
25
|
});
|
package/lib/object/facade.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facade.js","sourceRoot":"","sources":["../../src/object/facade.ts"],"names":[],"mappings":";;;AAiBA,SAAgB,MAAM,CAAsB,OAAU;IAAE,eAAqB;SAArB,UAAqB,EAArB,qBAAqB,EAArB,IAAqB;QAArB,8BAAqB;;IAC3E,OAAO,KAAK,CAAC,MAAM,CAAC,UAAC,CAAC,EAAE,CAAC;QACvB,IAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;QACvB,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;YAC9B,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SAC1B;aACI;YACH,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE;gBAC1B,GAAG;oBACD,OAAO,OAAO,CAAC,CAAC,CAAC,CAAA;gBACnB,CAAC;gBACD,GAAG,EAAH,UAAI,KAAU;oBACZ,OAAO,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA;gBAC3B,CAAC;aACF,CAAC,CAAA;SACH;QACD,OAAO,CAAC,CAAA;IACV,CAAC,EAAE,EAAO,CAAC,CAAA;AACb,CAAC;
|
|
1
|
+
{"version":3,"file":"facade.js","sourceRoot":"","sources":["../../src/object/facade.ts"],"names":[],"mappings":";;;AAiBA,SAAgB,MAAM,CAAsB,OAAU;IAAE,eAAqB;SAArB,UAAqB,EAArB,qBAAqB,EAArB,IAAqB;QAArB,8BAAqB;;IAC3E,OAAO,KAAK,CAAC,MAAM,CAAC,UAAC,CAAC,EAAE,CAAC;QACvB,IAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;QACvB,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;YAC9B,sGAAsG;YACtG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SAC1B;aACI;YACH,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE;gBAC1B,GAAG;oBACD,+DAA+D;oBAC/D,OAAO,OAAO,CAAC,CAAC,CAAC,CAAA;gBACnB,CAAC;gBACD,GAAG,EAAH,UAAI,KAAU;oBACZ,wGAAwG;oBACxG,OAAO,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA;gBAC3B,CAAC;aACF,CAAC,CAAA;SACH;QACD,OAAO,CAAC,CAAA;IACV,CAAC,EAAE,EAAO,CAAC,CAAA;AACb,CAAC;AArBD,wBAqBC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getField.js","sourceRoot":"","sources":["../../src/object/getField.ts"],"names":[],"mappings":";;;AAaA,SAAgB,QAAQ,CAKtB,OAAU,EAAE,GAAM,EAAE,YAAiB;IACrC,OAAO,OAAO,IAAK,
|
|
1
|
+
{"version":3,"file":"getField.js","sourceRoot":"","sources":["../../src/object/getField.ts"],"names":[],"mappings":";;;AAaA,SAAgB,QAAQ,CAKtB,OAAU,EAAE,GAAM,EAAE,YAAiB;IACrC,OAAO,OAAO,IAAK,OAA+C,CAAC,GAAG,CAAC,IAAI,YAAY,CAAA;AACzF,CAAC;AAPD,4BAOC"}
|
package/lib/object/hasKey.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hasKey.js","sourceRoot":"","sources":["../../src/object/hasKey.ts"],"names":[],"mappings":";;;AAIA,SAAgB,MAAM,CAAwC,OAAU;IAAE,cAAY;SAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;QAAZ,6BAAY;;IACpF,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,UAAA,GAAG,IAAI,OAAA,CAAC,OAAO,CAAC,GAAG,CAAC,EAAb,CAAa,
|
|
1
|
+
{"version":3,"file":"hasKey.js","sourceRoot":"","sources":["../../src/object/hasKey.ts"],"names":[],"mappings":";;;AAIA,SAAgB,MAAM,CAAwC,OAAU;IAAE,cAAY;SAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;QAAZ,6BAAY;;IACpF,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,UAAA,GAAG,IAAI,OAAA,CAAC,OAAO,CAAC,GAAG,CAAC,EAAb,CAAa,CAA4B,CAAA;AACpE,CAAC;AAFD,wBAEC"}
|
|
@@ -11,7 +11,7 @@ var reduceKey_1 = require("./reduceKey");
|
|
|
11
11
|
* I keep this parameter order because this parameter order provides better type inference.
|
|
12
12
|
*/
|
|
13
13
|
function mapProperties(subject, callbackfn) {
|
|
14
|
-
return reduceKey_1.reduceByKey(subject, function (p, key) { return (p[key] = callbackfn(subject[key], key, subject),
|
|
14
|
+
return (0, reduceKey_1.reduceByKey)(subject, function (p, key) { return (p[key] = callbackfn(subject[key], key, subject),
|
|
15
15
|
p); }, {});
|
|
16
16
|
}
|
|
17
17
|
exports.mapProperties = mapProperties;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapProperties.js","sourceRoot":"","sources":["../../src/object/mapProperties.ts"],"names":[],"mappings":";;;AACA,yCAAyC;AAGzC;;;;;;;GAOG;AACH,SAAgB,aAAa,CAI3B,OAAgB,EAChB,UAAqF;IAErF,OAAO,uBAAW,
|
|
1
|
+
{"version":3,"file":"mapProperties.js","sourceRoot":"","sources":["../../src/object/mapProperties.ts"],"names":[],"mappings":";;;AACA,yCAAyC;AAGzC;;;;;;;GAOG;AACH,SAAgB,aAAa,CAI3B,OAAgB,EAChB,UAAqF;IAErF,OAAO,IAAA,uBAAW,EAAC,OAAO,EAAE,UAAC,CAAC,EAAE,GAAG,IAAK,OAAA,CACtC,CAAC,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC;QAC/C,CAAC,CAAC,EAFoC,CAEpC,EAAE,EAA0C,CAAC,CAAA;AACnD,CAAC;AAVD,sCAUC"}
|
package/lib/object/omit.js
CHANGED
|
@@ -7,7 +7,7 @@ function omit(subject) {
|
|
|
7
7
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
8
8
|
props[_i - 1] = arguments[_i];
|
|
9
9
|
}
|
|
10
|
-
return object_1.reduceByKey(subject, function (p, k) {
|
|
10
|
+
return (0, object_1.reduceByKey)(subject, function (p, k) {
|
|
11
11
|
if (props.indexOf(k) === -1)
|
|
12
12
|
p[k] = subject[k];
|
|
13
13
|
return p;
|
package/lib/object/omit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"omit.js","sourceRoot":"","sources":["../../src/object/omit.ts"],"names":[],"mappings":";;;AAAA,oCAAkD;AA8BlD,SAAgB,IAAI,CAAsB,OAAU;IAAE,eAA6B;SAA7B,UAA6B,EAA7B,qBAA6B,EAA7B,IAA6B;QAA7B,8BAA6B;;IACjF,OAAO,oBAAW,
|
|
1
|
+
{"version":3,"file":"omit.js","sourceRoot":"","sources":["../../src/object/omit.ts"],"names":[],"mappings":";;;AAAA,oCAAkD;AA8BlD,SAAgB,IAAI,CAAsB,OAAU;IAAE,eAA6B;SAA7B,UAA6B,EAA7B,qBAA6B,EAA7B,IAA6B;QAA7B,8BAA6B;;IACjF,OAAO,IAAA,oBAAW,EAAC,OAAO,EAAE,UAAC,CAAC,EAAE,CAAC;QAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YAAE,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;QAC9C,OAAO,CAAC,CAAA;IACV,CAAC,EAAE,EAAe,CAAC,CAAA;AACrB,CAAC;AALD,oBAKC"}
|
package/lib/object/pick.js
CHANGED
|
@@ -7,7 +7,7 @@ function pick(subject) {
|
|
|
7
7
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
8
8
|
props[_i - 1] = arguments[_i];
|
|
9
9
|
}
|
|
10
|
-
return reduceKey_1.reduceByKey(subject, function (p, k) {
|
|
10
|
+
return (0, reduceKey_1.reduceByKey)(subject, function (p, k) {
|
|
11
11
|
if (props.indexOf(k) >= 0)
|
|
12
12
|
p[k] = subject[k];
|
|
13
13
|
return p;
|
package/lib/object/pick.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pick.js","sourceRoot":"","sources":["../../src/object/pick.ts"],"names":[],"mappings":";;;AAEA,yCAAyC;AAczC,SAAgB,IAAI,CAAsB,OAAU;IAAE,eAA6B;SAA7B,UAA6B,EAA7B,qBAA6B,EAA7B,IAA6B;QAA7B,8BAA6B;;IACjF,OAAO,uBAAW,
|
|
1
|
+
{"version":3,"file":"pick.js","sourceRoot":"","sources":["../../src/object/pick.ts"],"names":[],"mappings":";;;AAEA,yCAAyC;AAczC,SAAgB,IAAI,CAAsB,OAAU;IAAE,eAA6B;SAA7B,UAA6B,EAA7B,qBAA6B,EAA7B,IAA6B;QAA7B,8BAA6B;;IACjF,OAAO,IAAA,uBAAW,EAAC,OAAO,EAAE,UAAC,CAAC,EAAE,CAAC;QAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;YAAE,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;QAC5C,OAAO,CAAC,CAAA;IACV,CAAC,EAAE,EAAO,CAAC,CAAA;AACb,CAAC;AALD,oBAKC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeOverrideIncompatible.js","sourceRoot":"","sources":["../../src/object/typeOverrideIncompatible.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,SAAgB,wBAAwB;IACtC,OAAO,UAA+B,MAAS,EAAE,QAAqB;QACpE,
|
|
1
|
+
{"version":3,"file":"typeOverrideIncompatible.js","sourceRoot":"","sources":["../../src/object/typeOverrideIncompatible.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA,SAAgB,wBAAwB;IACtC,OAAO,UAA+B,MAAS,EAAE,QAAqB;QACpE,6BACK,MAAM,GACN,QAAQ,EACZ;IACH,CAAC,CAAA;AACH,CAAC;AAPD,4DAOC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { NotExtendable } from './Extends';
|
|
2
|
+
import { IsEmptyObject } from './isEmptyObject';
|
|
2
3
|
/**
|
|
3
4
|
* Can `A` assign to `B`
|
|
4
5
|
*/
|
|
5
|
-
export declare type CanAssign<A, B, Then = true, Else = false> = boolean extends A ? boolean extends B ? Then : Else : A extends B ? Then : Else;
|
|
6
|
+
export declare type CanAssign<A, B, Then = true, Else = false> = IsEmptyObject<A> extends true ? Record<string, unknown> extends B ? Then : Else : boolean extends A ? (boolean extends B ? Then : Else) : A extends B ? Then : Else;
|
|
6
7
|
export declare type IsAssign<A, B, Then = true, Else = false> = CanAssign<A, B, Then, Else>;
|
|
7
8
|
export declare function canAssign<T>(canAssign: false): <S>(subject: NotExtendable<S, T>) => true;
|
|
8
9
|
export declare function canAssign<T>(): <S extends T>(subject: S) => CanAssign<S, T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CanAssign.js","sourceRoot":"","sources":["../../src/predicates/CanAssign.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"CanAssign.js","sourceRoot":"","sources":["../../src/predicates/CanAssign.ts"],"names":[],"mappings":";;;AAkBA,SAAgB,SAAS;IACvB,OAAO,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAA;AACnB,CAAC;AAFD,8BAEC"}
|
|
@@ -4,6 +4,7 @@ export * from './Extends';
|
|
|
4
4
|
export * from './If';
|
|
5
5
|
export * from './isType';
|
|
6
6
|
export * from './logical';
|
|
7
|
+
export * from './isEmptyObject';
|
|
7
8
|
import { IsExtend } from './Extends';
|
|
8
9
|
export declare type IsLiteral<T extends number | string, Then = true, Else = false> = number extends T ? Else : string extends T ? Else : Then;
|
|
9
10
|
export declare type IsBoolean<T, Then = true, Else = false> = boolean extends T ? Then : Else;
|
package/lib/predicates/index.js
CHANGED
|
@@ -16,4 +16,5 @@ __exportStar(require("./Extends"), exports);
|
|
|
16
16
|
__exportStar(require("./If"), exports);
|
|
17
17
|
__exportStar(require("./isType"), exports);
|
|
18
18
|
__exportStar(require("./logical"), exports);
|
|
19
|
+
__exportStar(require("./isEmptyObject"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/predicates/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA2B;AAC3B,0CAAuB;AACvB,4CAAyB;AACzB,uCAAoB;AACpB,2CAAwB;AACxB,4CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/predicates/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA2B;AAC3B,0CAAuB;AACvB,4CAAyB;AACzB,uCAAoB;AACpB,2CAAwB;AACxB,4CAAyB;AACzB,kDAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare type IsEmptyObject<T> = T extends {} ? {} extends T ? true : false : false;
|