type-plus 6.7.1 → 6.8.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.
@@ -1,15 +1,28 @@
1
1
  import type { AnyFunction } from '../function/any_function.js';
2
2
  import type { RecursivePartial } from '../object/RecursivePartial.js';
3
3
  import type { NoInfer } from '../type/no_infer.js';
4
- export declare namespace stub {
5
- type Param<T> = T extends AnyFunction ? T : RecursivePartial<NoInfer<T>>;
6
- }
4
+ /**
5
+ * stub a value.
6
+ * If the value is a function, it will be passed through as-is.
7
+ */
7
8
  export declare function stub<T extends AnyFunction>(stub: T): T;
8
9
  export declare function stub<T>(stub: RecursivePartial<NoInfer<T>>): T;
9
10
  export declare namespace stub {
10
- var build: {
11
- <T>(): (stub?: Param<T> | undefined) => T;
12
- <T_1>(init: RecursivePartial<T_1> | ((stub?: Param<T_1> | undefined) => RecursivePartial<T_1>)): (stub?: Param<T_1> | undefined) => T_1;
11
+ var build: <T>(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)) => (stub?: RecursivePartial<T> | undefined) => T;
12
+ var builder: <T>(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)) => {
13
+ /**
14
+ * Adds an init object or handler to the builder.
15
+ *
16
+ * If `init` is an object, it will be merged with the stub object.
17
+ * If `init` is a function, it will be called with the stub object.
18
+ *
19
+ * @return {Builder<T>} The builder instance.
20
+ */
21
+ with(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)): any;
22
+ /**
23
+ * Creates the resulting stub function.
24
+ */
25
+ create(): (stub?: RecursivePartial<T> | undefined) => T;
13
26
  };
14
27
  }
15
28
  //# sourceMappingURL=stub.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stub.d.ts","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,yBAAiB,IAAI,CAAC;IACrB,KAAY,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,WAAW,GAAG,CAAC,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;CAC/E;AAED,wBAAgB,IAAI,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAAA;AACvD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;yBAA9C,IAAI"}
1
+ {"version":3,"file":"stub.d.ts","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAAA;AACvD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;yBAA9C,IAAI;;;QAgClB;;;;;;;WAOG;;QAKH;;WAEG"}
@@ -7,15 +7,53 @@ function stub(stub) {
7
7
  }
8
8
  exports.stub = stub;
9
9
  function build(init) {
10
- return function (value) {
11
- if (typeof init === 'function') {
12
- return init(value);
13
- }
14
- if (init) {
15
- return (0, unpartial_1.requiredDeep)(init, value);
10
+ return builder(init).create();
11
+ }
12
+ /**
13
+ * Create a builder for a stub function of type T.
14
+ *
15
+ * The builder contains two methods:
16
+ *
17
+ * `.with()`: adds additional handler or partial stub.
18
+ * `.create()`: creates the final stub function.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const b = stub.builder<{ a: number; b: string }>({ a: 1 }).with({ b: 'b' }).create()
23
+ * b({ a: 2 }) // { a: 2, b: 'b' }
24
+ * ```
25
+ */
26
+ function builder(init) {
27
+ const initializers = [init];
28
+ const builder = {
29
+ /**
30
+ * Adds an init object or handler to the builder.
31
+ *
32
+ * If `init` is an object, it will be merged with the stub object.
33
+ * If `init` is a function, it will be called with the stub object.
34
+ *
35
+ * @return {Builder<T>} The builder instance.
36
+ */
37
+ with(init) {
38
+ initializers.push(init);
39
+ return builder;
40
+ },
41
+ /**
42
+ * Creates the resulting stub function.
43
+ */
44
+ create() {
45
+ return (stub) => {
46
+ return initializers.reduce((acc, init) => {
47
+ if (typeof init === 'function') {
48
+ return init(acc);
49
+ }
50
+ return (0, unpartial_1.requiredDeep)(init, acc);
51
+ }, stub);
52
+ };
16
53
  }
17
- return value;
18
54
  };
55
+ return builder;
19
56
  }
20
57
  stub.build = build;
58
+ stub.builder = builder;
21
59
  //# sourceMappingURL=stub.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stub.js","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AAWxC,SAAgB,IAAI,CAAI,IAAa;IACpC,OAAO,IAAS,CAAA;AACjB,CAAC;AAFD,oBAEC;AASD,SAAS,KAAK,CAAI,IAA4E;IAC7F,OAAO,UAAU,KAAqB;QACrC,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;YAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA;SAClB;QACD,IAAI,IAAI,EAAE;YACT,OAAO,IAAA,wBAAY,EAAC,IAAI,EAAE,KAAK,CAAC,CAAA;SAChC;QACD,OAAO,KAAK,CAAA;IACb,CAAC,CAAA;AACF,CAAC;AAED,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA"}
1
+ {"version":3,"file":"stub.js","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AAWxC,SAAgB,IAAI,CAAI,IAAa;IACpC,OAAO,IAAS,CAAA;AACjB,CAAC;AAFD,oBAEC;AAQD,SAAS,KAAK,CAAI,IAAiF;IAClG,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAA;AAC9B,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAS,OAAO,CAAI,IAAiF;IACpG,MAAM,YAAY,GAAG,CAAC,IAAI,CAAC,CAAA;IAC3B,MAAM,OAAO,GAAG;QACf;;;;;;;WAOG;QACH,IAAI,CAAC,IAAiF;YACrF,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACvB,OAAO,OAAO,CAAA;QACf,CAAC;QACD;;WAEG;QAEH,MAAM;YACL,OAAO,CAAC,IAA0B,EAAE,EAAE;gBACrC,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;oBACxC,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;wBAC/B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;qBAChB;oBACD,OAAO,IAAA,wBAAY,EAAsB,IAAI,EAAE,GAAG,CAAC,CAAA;gBACpD,CAAC,EAAE,IAAI,CAAM,CAAA;YACd,CAAC,CAAA;QACF,CAAC;KACD,CAAA;IACD,OAAO,OAAO,CAAA;AACf,CAAC;AAED,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;AAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA"}
@@ -1,13 +1,19 @@
1
1
  import type { IsAny } from '../any/any_type.js';
2
+ import type { IsBigint } from '../bigint/bigint_type.js';
3
+ import type { IsStrictBigint } from '../bigint/strict_bigint_type.js';
2
4
  import type { IsBoolean } from '../boolean/boolean_type.js';
3
5
  import type { IsFalse } from '../boolean/false_type.js';
4
6
  import type { IsStrictBoolean } from '../boolean/strict_boolean_type.js';
5
7
  import type { IsTrue } from '../boolean/true_type.js';
6
8
  import type { Equal } from '../equal/equal.js';
7
9
  import type { IsNever } from '../never/never_type.js';
8
- import { IsNumber } from '../number/number_type.js';
10
+ import type { IsNull } from '../null/null_type.js';
11
+ import type { IsNumber } from '../number/number_type.js';
9
12
  import type { IsStrictNumber } from '../number/strict_number_type.js';
10
13
  import type { CanAssign } from '../predicates/CanAssign.js';
14
+ import type { IsStrictString } from '../string/strict_string_type.js';
15
+ import type { IsString } from '../string/string_type.js';
16
+ import type { IsUndefined } from '../undefined/undefined_type.js';
11
17
  import type { IsUnknown } from '../unknown/unknown_type.js';
12
18
  import type { IsVoid } from '../void/void_type.js';
13
19
  /**
@@ -97,6 +103,42 @@ export declare const testType: {
97
103
  * @return `expected` as `T` for type inspection.
98
104
  */
99
105
  number<T_9>(expected: IsNumber<T_9>): T_9;
106
+ /**
107
+ * Check if type `T` is exactly `string`.
108
+ *
109
+ * @return `expected` as `T` for type inspection.
110
+ */
111
+ strictString<T_10>(expected: IsStrictString<T_10>): T_10;
112
+ /**
113
+ * Check if type `T` is `string` or string literals.
114
+ *
115
+ * @return `expected` as `T` for type inspection.
116
+ */
117
+ string<T_11>(expected: IsString<T_11>): T_11;
118
+ /**
119
+ * Check if type `T` is exactly `bigint`.
120
+ *
121
+ * @return `expected` as `T` for type inspection.
122
+ */
123
+ strictBigint<T_12>(expected: IsStrictBigint<T_12>): T_12;
124
+ /**
125
+ * Check if type `T` is `bigint` or bigint literals.
126
+ *
127
+ * @return `expected` as `T` for type inspection.
128
+ */
129
+ bigint<T_13>(expected: IsBigint<T_13>): T_13;
130
+ /**
131
+ * Check if type `T` is exactly `undefined`.
132
+ *
133
+ * @return `expected` as `T` for type inspection.
134
+ */
135
+ undefined<T_14>(expected: IsUndefined<T_14>): T_14;
136
+ /**
137
+ * Check if type `T` is exactly `null`.
138
+ *
139
+ * @return `expected` as `T` for type inspection.
140
+ */
141
+ null<T_15>(expected: IsNull<T_15>): T_15;
100
142
  };
101
143
  export {};
102
144
  //# sourceMappingURL=test_type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"test_type.d.ts","sourceRoot":"","sources":["../../ts/testing/test_type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAElD;;;;GAIG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;AAC/D;;;;GAIG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;AAK9C;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ;IACpB;;;;OAIG;;IA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D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAElD;;;;GAIG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;AAC/D;;;;GAIG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;AAK9C;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ;IACpB;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;;IAKH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;CAIH,CAAA"}
@@ -100,6 +100,54 @@ exports.testType = {
100
100
  */
101
101
  number(expected) {
102
102
  return expected;
103
+ },
104
+ /**
105
+ * Check if type `T` is exactly `string`.
106
+ *
107
+ * @return `expected` as `T` for type inspection.
108
+ */
109
+ strictString(expected) {
110
+ return expected;
111
+ },
112
+ /**
113
+ * Check if type `T` is `string` or string literals.
114
+ *
115
+ * @return `expected` as `T` for type inspection.
116
+ */
117
+ string(expected) {
118
+ return expected;
119
+ },
120
+ /**
121
+ * Check if type `T` is exactly `bigint`.
122
+ *
123
+ * @return `expected` as `T` for type inspection.
124
+ */
125
+ strictBigint(expected) {
126
+ return expected;
127
+ },
128
+ /**
129
+ * Check if type `T` is `bigint` or bigint literals.
130
+ *
131
+ * @return `expected` as `T` for type inspection.
132
+ */
133
+ bigint(expected) {
134
+ return expected;
135
+ },
136
+ /**
137
+ * Check if type `T` is exactly `undefined`.
138
+ *
139
+ * @return `expected` as `T` for type inspection.
140
+ */
141
+ undefined(expected) {
142
+ return expected;
143
+ },
144
+ /**
145
+ * Check if type `T` is exactly `null`.
146
+ *
147
+ * @return `expected` as `T` for type inspection.
148
+ */
149
+ null(expected) {
150
+ return expected;
103
151
  }
104
152
  };
105
153
  //# sourceMappingURL=test_type.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"test_type.js","sourceRoot":"","sources":["../../ts/testing/test_type.ts"],"names":[],"mappings":";;;AAyBA,SAAS,KAAK,CAAC,QAAiB;IAC/B,OAAO,QAAQ,CAAA;AAChB,CAAC;AAED;;;;;;GAMG;AACU,QAAA,QAAQ,GAAG;IACvB;;;;OAIG;IACH,GAAG,CAAI,QAAkB;QACxB,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD,KAAK;IACL;;;;OAIG;IACH,SAAS,CAAO,QAAyB;QACxC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,aAAa,CAAI,QAA4B;QAC5C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;CACD,CAAA"}
1
+ {"version":3,"file":"test_type.js","sourceRoot":"","sources":["../../ts/testing/test_type.ts"],"names":[],"mappings":";;;AA+BA,SAAS,KAAK,CAAC,QAAiB;IAC/B,OAAO,QAAQ,CAAA;AAChB,CAAC;AAED;;;;;;GAMG;AACU,QAAA,QAAQ,GAAG;IACvB;;;;OAIG;IACH,GAAG,CAAI,QAAkB;QACxB,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD,KAAK;IACL;;;;OAIG;IACH,SAAS,CAAO,QAAyB;QACxC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,aAAa,CAAI,QAA4B;QAC5C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,SAAS,CAAI,QAAwB;QACpC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;CACD,CAAA"}
@@ -1,15 +1,28 @@
1
1
  import type { AnyFunction } from '../function/any_function.js';
2
2
  import type { RecursivePartial } from '../object/RecursivePartial.js';
3
3
  import type { NoInfer } from '../type/no_infer.js';
4
- export declare namespace stub {
5
- type Param<T> = T extends AnyFunction ? T : RecursivePartial<NoInfer<T>>;
6
- }
4
+ /**
5
+ * stub a value.
6
+ * If the value is a function, it will be passed through as-is.
7
+ */
7
8
  export declare function stub<T extends AnyFunction>(stub: T): T;
8
9
  export declare function stub<T>(stub: RecursivePartial<NoInfer<T>>): T;
9
10
  export declare namespace stub {
10
- var build: {
11
- <T>(): (stub?: Param<T> | undefined) => T;
12
- <T_1>(init: RecursivePartial<T_1> | ((stub?: Param<T_1> | undefined) => RecursivePartial<T_1>)): (stub?: Param<T_1> | undefined) => T_1;
11
+ var build: <T>(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)) => (stub?: RecursivePartial<T> | undefined) => T;
12
+ var builder: <T>(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)) => {
13
+ /**
14
+ * Adds an init object or handler to the builder.
15
+ *
16
+ * If `init` is an object, it will be merged with the stub object.
17
+ * If `init` is a function, it will be called with the stub object.
18
+ *
19
+ * @return {Builder<T>} The builder instance.
20
+ */
21
+ with(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)): any;
22
+ /**
23
+ * Creates the resulting stub function.
24
+ */
25
+ create(): (stub?: RecursivePartial<T> | undefined) => T;
13
26
  };
14
27
  }
15
28
  //# sourceMappingURL=stub.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stub.d.ts","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,yBAAiB,IAAI,CAAC;IACrB,KAAY,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,WAAW,GAAG,CAAC,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;CAC/E;AAED,wBAAgB,IAAI,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAAA;AACvD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;yBAA9C,IAAI"}
1
+ {"version":3,"file":"stub.d.ts","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAAA;AACvD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;yBAA9C,IAAI;;;QAgClB;;;;;;;WAOG;;QAKH;;WAEG"}
@@ -3,15 +3,53 @@ export function stub(stub) {
3
3
  return stub;
4
4
  }
5
5
  function build(init) {
6
- return function (value) {
7
- if (typeof init === 'function') {
8
- return init(value);
9
- }
10
- if (init) {
11
- return requiredDeep(init, value);
6
+ return builder(init).create();
7
+ }
8
+ /**
9
+ * Create a builder for a stub function of type T.
10
+ *
11
+ * The builder contains two methods:
12
+ *
13
+ * `.with()`: adds additional handler or partial stub.
14
+ * `.create()`: creates the final stub function.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const b = stub.builder<{ a: number; b: string }>({ a: 1 }).with({ b: 'b' }).create()
19
+ * b({ a: 2 }) // { a: 2, b: 'b' }
20
+ * ```
21
+ */
22
+ function builder(init) {
23
+ const initializers = [init];
24
+ const builder = {
25
+ /**
26
+ * Adds an init object or handler to the builder.
27
+ *
28
+ * If `init` is an object, it will be merged with the stub object.
29
+ * If `init` is a function, it will be called with the stub object.
30
+ *
31
+ * @return {Builder<T>} The builder instance.
32
+ */
33
+ with(init) {
34
+ initializers.push(init);
35
+ return builder;
36
+ },
37
+ /**
38
+ * Creates the resulting stub function.
39
+ */
40
+ create() {
41
+ return (stub) => {
42
+ return initializers.reduce((acc, init) => {
43
+ if (typeof init === 'function') {
44
+ return init(acc);
45
+ }
46
+ return requiredDeep(init, acc);
47
+ }, stub);
48
+ };
12
49
  }
13
- return value;
14
50
  };
51
+ return builder;
15
52
  }
16
53
  stub.build = build;
54
+ stub.builder = builder;
17
55
  //# sourceMappingURL=stub.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stub.js","sourceRoot":"","sources":["../../ts/testing/stub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAWxC,MAAM,UAAU,IAAI,CAAI,IAAa;IACpC,OAAO,IAAS,CAAA;AACjB,CAAC;AASD,SAAS,KAAK,CAAI,IAA4E;IAC7F,OAAO,UAAU,KAAqB;QACrC,IAAI,OAAO,IAAI,KAAK,UAAU,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,OAAO,GAAG,OAAO,CAAA"}
@@ -1,13 +1,19 @@
1
1
  import type { IsAny } from '../any/any_type.js';
2
+ import type { IsBigint } from '../bigint/bigint_type.js';
3
+ import type { IsStrictBigint } from '../bigint/strict_bigint_type.js';
2
4
  import type { IsBoolean } from '../boolean/boolean_type.js';
3
5
  import type { IsFalse } from '../boolean/false_type.js';
4
6
  import type { IsStrictBoolean } from '../boolean/strict_boolean_type.js';
5
7
  import type { IsTrue } from '../boolean/true_type.js';
6
8
  import type { Equal } from '../equal/equal.js';
7
9
  import type { IsNever } from '../never/never_type.js';
8
- import { IsNumber } from '../number/number_type.js';
10
+ import type { IsNull } from '../null/null_type.js';
11
+ import type { IsNumber } from '../number/number_type.js';
9
12
  import type { IsStrictNumber } from '../number/strict_number_type.js';
10
13
  import type { CanAssign } from '../predicates/CanAssign.js';
14
+ import type { IsStrictString } from '../string/strict_string_type.js';
15
+ import type { IsString } from '../string/string_type.js';
16
+ import type { IsUndefined } from '../undefined/undefined_type.js';
11
17
  import type { IsUnknown } from '../unknown/unknown_type.js';
12
18
  import type { IsVoid } from '../void/void_type.js';
13
19
  /**
@@ -97,6 +103,42 @@ export declare const testType: {
97
103
  * @return `expected` as `T` for type inspection.
98
104
  */
99
105
  number<T_9>(expected: IsNumber<T_9>): T_9;
106
+ /**
107
+ * Check if type `T` is exactly `string`.
108
+ *
109
+ * @return `expected` as `T` for type inspection.
110
+ */
111
+ strictString<T_10>(expected: IsStrictString<T_10>): T_10;
112
+ /**
113
+ * Check if type `T` is `string` or string literals.
114
+ *
115
+ * @return `expected` as `T` for type inspection.
116
+ */
117
+ string<T_11>(expected: IsString<T_11>): T_11;
118
+ /**
119
+ * Check if type `T` is exactly `bigint`.
120
+ *
121
+ * @return `expected` as `T` for type inspection.
122
+ */
123
+ strictBigint<T_12>(expected: IsStrictBigint<T_12>): T_12;
124
+ /**
125
+ * Check if type `T` is `bigint` or bigint literals.
126
+ *
127
+ * @return `expected` as `T` for type inspection.
128
+ */
129
+ bigint<T_13>(expected: IsBigint<T_13>): T_13;
130
+ /**
131
+ * Check if type `T` is exactly `undefined`.
132
+ *
133
+ * @return `expected` as `T` for type inspection.
134
+ */
135
+ undefined<T_14>(expected: IsUndefined<T_14>): T_14;
136
+ /**
137
+ * Check if type `T` is exactly `null`.
138
+ *
139
+ * @return `expected` as `T` for type inspection.
140
+ */
141
+ null<T_15>(expected: IsNull<T_15>): T_15;
100
142
  };
101
143
  export {};
102
144
  //# sourceMappingURL=test_type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"test_type.d.ts","sourceRoot":"","sources":["../../ts/testing/test_type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAElD;;;;GAIG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,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C3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAElD;;;;GAIG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;AAC/D;;;;GAIG;AACH,iBAAS,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;AAK9C;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ;IACpB;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;;IAKH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;IAIH;;;;OAIG;;CAIH,CAAA"}
@@ -97,6 +97,54 @@ export const testType = {
97
97
  */
98
98
  number(expected) {
99
99
  return expected;
100
+ },
101
+ /**
102
+ * Check if type `T` is exactly `string`.
103
+ *
104
+ * @return `expected` as `T` for type inspection.
105
+ */
106
+ strictString(expected) {
107
+ return expected;
108
+ },
109
+ /**
110
+ * Check if type `T` is `string` or string literals.
111
+ *
112
+ * @return `expected` as `T` for type inspection.
113
+ */
114
+ string(expected) {
115
+ return expected;
116
+ },
117
+ /**
118
+ * Check if type `T` is exactly `bigint`.
119
+ *
120
+ * @return `expected` as `T` for type inspection.
121
+ */
122
+ strictBigint(expected) {
123
+ return expected;
124
+ },
125
+ /**
126
+ * Check if type `T` is `bigint` or bigint literals.
127
+ *
128
+ * @return `expected` as `T` for type inspection.
129
+ */
130
+ bigint(expected) {
131
+ return expected;
132
+ },
133
+ /**
134
+ * Check if type `T` is exactly `undefined`.
135
+ *
136
+ * @return `expected` as `T` for type inspection.
137
+ */
138
+ undefined(expected) {
139
+ return expected;
140
+ },
141
+ /**
142
+ * Check if type `T` is exactly `null`.
143
+ *
144
+ * @return `expected` as `T` for type inspection.
145
+ */
146
+ null(expected) {
147
+ return expected;
100
148
  }
101
149
  };
102
150
  //# sourceMappingURL=test_type.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"test_type.js","sourceRoot":"","sources":["../../ts/testing/test_type.ts"],"names":[],"mappings":"AAyBA,SAAS,KAAK,CAAC,QAAiB;IAC/B,OAAO,QAAQ,CAAA;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB;;;;OAIG;IACH,GAAG,CAAI,QAAkB;QACxB,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD,KAAK;IACL;;;;OAIG;IACH,SAAS,CAAO,QAAyB;QACxC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,aAAa,CAAI,QAA4B;QAC5C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;CACD,CAAA"}
1
+ {"version":3,"file":"test_type.js","sourceRoot":"","sources":["../../ts/testing/test_type.ts"],"names":[],"mappings":"AA+BA,SAAS,KAAK,CAAC,QAAiB;IAC/B,OAAO,QAAQ,CAAA;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB;;;;OAIG;IACH,GAAG,CAAI,QAAkB;QACxB,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD,KAAK;IACL;;;;OAIG;IACH,SAAS,CAAO,QAAyB;QACxC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,aAAa,CAAI,QAA4B;QAC5C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,OAAO,CAAI,QAAsB;QAChC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,KAAK,CAAI,QAAoB;QAC5B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,YAAY,CAAI,QAA2B;QAC1C,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,MAAM,CAAI,QAAqB;QAC9B,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,SAAS,CAAI,QAAwB;QACpC,OAAO,QAAa,CAAA;IACrB,CAAC;IACD;;;;OAIG;IACH,IAAI,CAAI,QAAmB;QAC1B,OAAO,QAAa,CAAA;IACrB,CAAC;CACD,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-plus",
3
- "version": "6.7.1",
3
+ "version": "6.8.0",
4
4
  "description": "Provides additional types for TypeScript.",
5
5
  "homepage": "https://github.com/unional/type-plus",
6
6
  "bugs": {
@@ -41,7 +41,7 @@
41
41
  "@commitlint/cli": "^17.0.2",
42
42
  "@commitlint/config-conventional": "^17.0.2",
43
43
  "@jest/globals": "^29.5.0",
44
- "@repobuddy/jest": "^3.1.5",
44
+ "@repobuddy/jest": "^3.4.0",
45
45
  "@size-limit/esbuild-why": "^8.2.4",
46
46
  "@size-limit/preset-small-lib": "^8.2.4",
47
47
  "@types/node": "^18.0.0",
@@ -91,6 +91,7 @@
91
91
  "test:watch": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest --watch",
92
92
  "verify": "npm-run-all clean -p build depcheck lint coverage -p size",
93
93
  "version": "changeset version",
94
- "watch": "jest --watch"
94
+ "watch": "jest --watch",
95
+ "w": "jest --watch"
95
96
  }
96
97
  }
@@ -3,10 +3,10 @@ import type { AnyFunction } from '../function/any_function.js'
3
3
  import type { RecursivePartial } from '../object/RecursivePartial.js'
4
4
  import type { NoInfer } from '../type/no_infer.js'
5
5
 
6
- export namespace stub {
7
- export type Param<T> = T extends AnyFunction ? T : RecursivePartial<NoInfer<T>>
8
- }
9
-
6
+ /**
7
+ * stub a value.
8
+ * If the value is a function, it will be passed through as-is.
9
+ */
10
10
  export function stub<T extends AnyFunction>(stub: T): T
11
11
  export function stub<T>(stub: RecursivePartial<NoInfer<T>>): T
12
12
  export function stub<T>(stub: unknown): T {
@@ -16,20 +16,59 @@ export function stub<T>(stub: unknown): T {
16
16
  /**
17
17
  * builds a stub function
18
18
  */
19
- function build<T>(): (stub?: stub.Param<T>) => T
20
19
  function build<T>(
21
- init: RecursivePartial<T> | ((stub?: stub.Param<T>) => RecursivePartial<T>)
22
- ): (stub?: stub.Param<T>) => T
23
- function build<T>(init?: RecursivePartial<T> | ((stub?: stub.Param<T>) => RecursivePartial<T>)) {
24
- return function (value?: stub.Param<T>) {
25
- if (typeof init === 'function') {
26
- return init(value)
27
- }
28
- if (init) {
29
- return requiredDeep(init, value)
20
+ init: RecursivePartial<T> | ((stub?: RecursivePartial<T>) => RecursivePartial<T>)
21
+ ): (stub?: RecursivePartial<T>) => T
22
+ function build<T>(init: RecursivePartial<T> | ((stub?: RecursivePartial<T>) => RecursivePartial<T>)) {
23
+ return builder(init).create()
24
+ }
25
+
26
+ /**
27
+ * Create a builder for a stub function of type T.
28
+ *
29
+ * The builder contains two methods:
30
+ *
31
+ * `.with()`: adds additional handler or partial stub.
32
+ * `.create()`: creates the final stub function.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * const b = stub.builder<{ a: number; b: string }>({ a: 1 }).with({ b: 'b' }).create()
37
+ * b({ a: 2 }) // { a: 2, b: 'b' }
38
+ * ```
39
+ */
40
+ function builder<T>(init: RecursivePartial<T> | ((stub?: RecursivePartial<T>) => RecursivePartial<T>)) {
41
+ const initializers = [init]
42
+ const builder = {
43
+ /**
44
+ * Adds an init object or handler to the builder.
45
+ *
46
+ * If `init` is an object, it will be merged with the stub object.
47
+ * If `init` is a function, it will be called with the stub object.
48
+ *
49
+ * @return {Builder<T>} The builder instance.
50
+ */
51
+ with(init: RecursivePartial<T> | ((stub?: RecursivePartial<T>) => RecursivePartial<T>)) {
52
+ initializers.push(init)
53
+ return builder
54
+ },
55
+ /**
56
+ * Creates the resulting stub function.
57
+ */
58
+
59
+ create() {
60
+ return (stub?: RecursivePartial<T>) => {
61
+ return initializers.reduce((acc, init) => {
62
+ if (typeof init === 'function') {
63
+ return init(acc)
64
+ }
65
+ return requiredDeep<RecursivePartial<T>>(init, acc)
66
+ }, stub) as T
67
+ }
30
68
  }
31
- return value
32
69
  }
70
+ return builder
33
71
  }
34
72
 
35
73
  stub.build = build
74
+ stub.builder = builder
@@ -1,13 +1,19 @@
1
1
  import type { IsAny } from '../any/any_type.js'
2
+ import type { IsBigint } from '../bigint/bigint_type.js'
3
+ import type { IsStrictBigint } from '../bigint/strict_bigint_type.js'
2
4
  import type { IsBoolean } from '../boolean/boolean_type.js'
3
5
  import type { IsFalse } from '../boolean/false_type.js'
4
6
  import type { IsStrictBoolean } from '../boolean/strict_boolean_type.js'
5
7
  import type { IsTrue } from '../boolean/true_type.js'
6
8
  import type { Equal } from '../equal/equal.js'
7
9
  import type { IsNever } from '../never/never_type.js'
8
- import { IsNumber } from '../number/number_type.js'
10
+ import type { IsNull } from '../null/null_type.js'
11
+ import type { IsNumber } from '../number/number_type.js'
9
12
  import type { IsStrictNumber } from '../number/strict_number_type.js'
10
13
  import type { CanAssign } from '../predicates/CanAssign.js'
14
+ import type { IsStrictString } from '../string/strict_string_type.js'
15
+ import type { IsString } from '../string/string_type.js'
16
+ import type { IsUndefined } from '../undefined/undefined_type.js'
11
17
  import type { IsUnknown } from '../unknown/unknown_type.js'
12
18
  import type { IsVoid } from '../void/void_type.js'
13
19
 
@@ -123,5 +129,53 @@ export const testType = {
123
129
  */
124
130
  number<T>(expected: IsNumber<T>) {
125
131
  return expected as T
132
+ },
133
+ /**
134
+ * Check if type `T` is exactly `string`.
135
+ *
136
+ * @return `expected` as `T` for type inspection.
137
+ */
138
+ strictString<T>(expected: IsStrictString<T>) {
139
+ return expected as T
140
+ },
141
+ /**
142
+ * Check if type `T` is `string` or string literals.
143
+ *
144
+ * @return `expected` as `T` for type inspection.
145
+ */
146
+ string<T>(expected: IsString<T>) {
147
+ return expected as T
148
+ },
149
+ /**
150
+ * Check if type `T` is exactly `bigint`.
151
+ *
152
+ * @return `expected` as `T` for type inspection.
153
+ */
154
+ strictBigint<T>(expected: IsStrictBigint<T>) {
155
+ return expected as T
156
+ },
157
+ /**
158
+ * Check if type `T` is `bigint` or bigint literals.
159
+ *
160
+ * @return `expected` as `T` for type inspection.
161
+ */
162
+ bigint<T>(expected: IsBigint<T>) {
163
+ return expected as T
164
+ },
165
+ /**
166
+ * Check if type `T` is exactly `undefined`.
167
+ *
168
+ * @return `expected` as `T` for type inspection.
169
+ */
170
+ undefined<T>(expected: IsUndefined<T>) {
171
+ return expected as T
172
+ },
173
+ /**
174
+ * Check if type `T` is exactly `null`.
175
+ *
176
+ * @return `expected` as `T` for type inspection.
177
+ */
178
+ null<T>(expected: IsNull<T>) {
179
+ return expected as T
126
180
  }
127
181
  }