type-plus 4.3.2 → 4.4.2
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 +1 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +1 -0
- package/cjs/index.js.map +1 -1
- package/cjs/testing/index.d.ts +1 -0
- package/cjs/testing/index.js +18 -0
- package/cjs/testing/index.js.map +1 -0
- package/cjs/testing/stub.d.ts +6 -0
- package/cjs/testing/stub.js +8 -0
- package/cjs/testing/stub.js.map +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/testing/index.js +2 -0
- package/esm/testing/index.js.map +1 -0
- package/esm/testing/stub.js +4 -0
- package/esm/testing/stub.js.map +1 -0
- package/package.json +1 -1
- package/ts/index.ts +1 -0
- package/ts/object/run.ts +0 -0
- package/ts/testing/index.ts +1 -0
- package/ts/testing/stub.spec.ts +38 -0
- package/ts/testing/stub.ts +10 -0
package/README.md
CHANGED
|
@@ -432,6 +432,7 @@ So you may encounter some weird behavior if your logic is complex.
|
|
|
432
432
|
- `required(...)`: merge options and removing `Partial<T>`. From [`unpartial`](https://github.com/unional/unpartial)
|
|
433
433
|
- `requiredDeep(...)`: merge options deeply and removing `Partial<T>`. From [`unpartial`](https://github.com/unional/unpartial)
|
|
434
434
|
- `split(target, ...splitters)`: split one object into multiple objects.
|
|
435
|
+
- `stub<T>(value)`: stub a particular type `T`.
|
|
435
436
|
- `typeOverrideIncompatible<T>()`: override only the incompatible portion between two types.
|
|
436
437
|
|
|
437
438
|
```ts
|
package/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __exportStar(require("./nominal-types"), exports);
|
|
|
31
31
|
__exportStar(require("./object"), exports);
|
|
32
32
|
__exportStar(require("./predicates"), exports);
|
|
33
33
|
__exportStar(require("./promise"), exports);
|
|
34
|
+
__exportStar(require("./testing"), exports);
|
|
34
35
|
__exportStar(require("./utils"), exports);
|
|
35
36
|
// export { types, types as T }
|
|
36
37
|
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAmC;AACnC,uCAAkD;AAAzC,qGAAA,QAAQ,OAAA;AAAE,yGAAA,YAAY,OAAA;AAC/B,0CAAuB;AACvB,8CAA2B;AAC3B,0CAAuB;AAEvB,6CAA0B;AAC1B,+CAA4B;AAC5B,8CAA2B;AAC3B,yCAAsB;AACtB,2CAAwB;AACxB,kDAA+B;AAC/B,2CAAwB;AACxB,+CAA4B;AAE5B,4CAAyB;AAIzB,0CAAuB;AACvB,+BAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAmC;AACnC,uCAAkD;AAAzC,qGAAA,QAAQ,OAAA;AAAE,yGAAA,YAAY,OAAA;AAC/B,0CAAuB;AACvB,8CAA2B;AAC3B,0CAAuB;AAEvB,6CAA0B;AAC1B,+CAA4B;AAC5B,8CAA2B;AAC3B,yCAAsB;AACtB,2CAAwB;AACxB,kDAA+B;AAC/B,2CAAwB;AACxB,+CAA4B;AAE5B,4CAAyB;AACzB,4CAAyB;AAIzB,0CAAuB;AACvB,+BAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './stub';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./stub"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/testing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAsB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stub.js","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":";;;AAOA,SAAgB,IAAI,CAAI,IAAoB;IAC1C,OAAO,IAAS,CAAA;AAClB,CAAC;AAFD,oBAEC"}
|
package/esm/index.js
CHANGED
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAClD,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AAEvB,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAE5B,cAAc,WAAW,CAAA;AAIzB,cAAc,SAAS,CAAA;AACvB,+BAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAClD,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AAEvB,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAE5B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AAIzB,cAAc,SAAS,CAAA;AACvB,+BAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/testing/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stub.js","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,IAAI,CAAI,IAAoB;IAC1C,OAAO,IAAS,CAAA;AAClB,CAAC"}
|
package/package.json
CHANGED
package/ts/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from './object'
|
|
|
14
14
|
export * from './predicates'
|
|
15
15
|
export type { PrimitiveTypes } from './PrimitiveTypes'
|
|
16
16
|
export * from './promise'
|
|
17
|
+
export * from './testing'
|
|
17
18
|
// export * from './types/optional'
|
|
18
19
|
// export * from './types/required'
|
|
19
20
|
export type { UnionKeys } from './UnionKeys'
|
package/ts/object/run.ts
ADDED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './stub'
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isType, stub } from '..'
|
|
2
|
+
|
|
3
|
+
test('stub is a partial of the actual object', () => {
|
|
4
|
+
const real = { a: 1, b: { c: 2 }, d: 3 }
|
|
5
|
+
|
|
6
|
+
const a = stub<typeof real>({ a: 2 })
|
|
7
|
+
expect(a.a).toBe(2)
|
|
8
|
+
isType.equal<true, typeof a, typeof real>()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
test('stub function retains param types', () => {
|
|
12
|
+
function real(a: string, b: number): boolean { return a === String(b) }
|
|
13
|
+
|
|
14
|
+
const a = stub<typeof real>((_a, _b) => {
|
|
15
|
+
isType.equal<true, string, typeof _a>()
|
|
16
|
+
isType.equal<true, number, typeof _b>()
|
|
17
|
+
return false
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
expect(a('1', 1)).toBe(false)
|
|
21
|
+
isType.equal<true, typeof a, typeof real>()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('stub function params can be omitted', () => {
|
|
25
|
+
function real(a: string, b: number): boolean { return a === String(b) }
|
|
26
|
+
|
|
27
|
+
const a = stub<typeof real>(() => false)
|
|
28
|
+
|
|
29
|
+
expect(a('1', 1)).toBe(false)
|
|
30
|
+
isType.equal<true, typeof a, typeof real>()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('stub input can be omitted', () => {
|
|
34
|
+
const real = { a: 1, b: { c: 2 }, d: 3 }
|
|
35
|
+
|
|
36
|
+
const a = stub<typeof real>()
|
|
37
|
+
isType.equal<true, typeof a, typeof real>()
|
|
38
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AnyFunction } from '../function'
|
|
2
|
+
import { RecursivePartial } from '../object'
|
|
3
|
+
|
|
4
|
+
export namespace stub {
|
|
5
|
+
export type Param<T> = T extends AnyFunction ? T : RecursivePartial<T>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function stub<T>(stub?: stub.Param<T>) {
|
|
9
|
+
return stub as T
|
|
10
|
+
}
|