ts-data-forge 5.1.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/README.md +46 -44
  2. package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
  3. package/dist/array/impl/array-utils-modification.mjs.map +1 -1
  4. package/dist/array/impl/array-utils-reducing-value.d.mts +8 -8
  5. package/dist/array/impl/array-utils-search.d.mts +4 -4
  6. package/dist/array/impl/array-utils-set-op.d.mts +7 -7
  7. package/dist/array/impl/array-utils-set-op.mjs +7 -7
  8. package/dist/array/impl/array-utils-size.d.mts +2 -2
  9. package/dist/array/impl/array-utils-size.mjs +2 -2
  10. package/dist/array/impl/array-utils-slicing.d.mts +2 -2
  11. package/dist/array/impl/array-utils-slicing.mjs +2 -2
  12. package/dist/array/impl/array-utils-validation.d.mts +18 -18
  13. package/dist/array/impl/array-utils-validation.mjs +14 -14
  14. package/dist/collections/imap.d.mts +15 -15
  15. package/dist/collections/imap.mjs +3 -3
  16. package/dist/collections/iset-mapped.d.mts +19 -19
  17. package/dist/collections/iset-mapped.mjs +2 -2
  18. package/dist/collections/iset.d.mts +19 -19
  19. package/dist/collections/iset.mjs +2 -2
  20. package/dist/collections/queue.d.mts +25 -25
  21. package/dist/collections/queue.mjs +5 -5
  22. package/dist/collections/stack.d.mts +25 -25
  23. package/dist/collections/stack.mjs +5 -5
  24. package/dist/functional/match.d.mts +1 -1
  25. package/dist/functional/optional/impl/optional-expect-to-be.d.mts +2 -2
  26. package/dist/functional/optional/impl/optional-is-none.d.mts +1 -1
  27. package/dist/functional/optional/impl/optional-is-none.mjs +1 -1
  28. package/dist/functional/optional/impl/optional-is-optional.d.mts +2 -2
  29. package/dist/functional/optional/impl/optional-is-optional.mjs +2 -2
  30. package/dist/functional/optional/impl/optional-is-some.d.mts +1 -1
  31. package/dist/functional/optional/impl/optional-is-some.mjs +1 -1
  32. package/dist/functional/optional/impl/optional-none.d.mts +2 -2
  33. package/dist/functional/optional/impl/optional-none.mjs +2 -2
  34. package/dist/functional/optional/impl/optional-some.d.mts +2 -2
  35. package/dist/functional/optional/impl/optional-some.mjs +2 -2
  36. package/dist/functional/optional/impl/optional-to-nullable.d.mts +2 -2
  37. package/dist/functional/optional/impl/optional-to-nullable.mjs +2 -2
  38. package/dist/functional/optional/impl/optional-unwrap-or.d.mts +4 -4
  39. package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +1 -1
  40. package/dist/functional/optional/impl/optional-unwrap-throw.mjs +1 -1
  41. package/dist/functional/optional/impl/optional-unwrap.d.mts +2 -2
  42. package/dist/functional/optional/impl/optional-zip.d.mts +1 -1
  43. package/dist/functional/optional/impl/optional-zip.mjs +1 -1
  44. package/dist/functional/pipe.d.mts +2 -2
  45. package/dist/functional/result/impl/result-err.d.mts +1 -1
  46. package/dist/functional/result/impl/result-err.mjs +1 -1
  47. package/dist/functional/result/impl/result-expect-to-be.d.mts +2 -2
  48. package/dist/functional/result/impl/result-from-promise.d.mts +1 -1
  49. package/dist/functional/result/impl/result-from-promise.mjs +1 -1
  50. package/dist/functional/result/impl/result-from-throwable.d.mts +1 -1
  51. package/dist/functional/result/impl/result-from-throwable.mjs +1 -1
  52. package/dist/functional/result/impl/result-is-err.d.mts +2 -2
  53. package/dist/functional/result/impl/result-is-err.mjs +2 -2
  54. package/dist/functional/result/impl/result-is-ok.d.mts +2 -2
  55. package/dist/functional/result/impl/result-is-ok.mjs +2 -2
  56. package/dist/functional/result/impl/result-is-result.d.mts +3 -3
  57. package/dist/functional/result/impl/result-is-result.mjs +3 -3
  58. package/dist/functional/result/impl/result-ok.d.mts +1 -1
  59. package/dist/functional/result/impl/result-ok.mjs +1 -1
  60. package/dist/functional/result/impl/result-unwrap-err-or.d.mts +4 -4
  61. package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +1 -1
  62. package/dist/functional/result/impl/result-unwrap-err-throw.mjs +1 -1
  63. package/dist/functional/result/impl/result-unwrap-err.d.mts +2 -2
  64. package/dist/functional/result/impl/result-unwrap-err.mjs +2 -2
  65. package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +4 -4
  66. package/dist/functional/result/impl/result-unwrap-ok.d.mts +2 -2
  67. package/dist/functional/result/impl/result-unwrap-throw.d.mts +1 -1
  68. package/dist/functional/result/impl/result-unwrap-throw.mjs +1 -1
  69. package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +1 -1
  70. package/dist/functional/ternary-result/impl/ternary-result-err.mjs +1 -1
  71. package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +1 -1
  72. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +1 -1
  73. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +1 -1
  74. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +1 -1
  75. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +3 -3
  76. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +3 -3
  77. package/dist/globals.d.mts +2 -1
  78. package/dist/guard/has-key.d.mts +6 -3
  79. package/dist/guard/has-key.d.mts.map +1 -1
  80. package/dist/guard/has-key.mjs +2 -2
  81. package/dist/guard/is-record.d.mts.map +1 -1
  82. package/dist/guard/is-record.mjs +1 -1
  83. package/dist/guard/is-record.mjs.map +1 -1
  84. package/dist/guard/key-is-in.d.mts +2 -2
  85. package/dist/guard/key-is-in.mjs +2 -2
  86. package/dist/json/json.d.mts +21 -21
  87. package/dist/json/json.mjs +21 -21
  88. package/dist/number/branded-types/int.d.mts +19 -19
  89. package/dist/number/branded-types/int.mjs +19 -19
  90. package/dist/number/branded-types/positive-int.d.mts +20 -20
  91. package/dist/number/branded-types/positive-int.mjs +20 -20
  92. package/dist/number/branded-types/positive-safe-int.d.mts +26 -26
  93. package/dist/number/branded-types/positive-safe-int.mjs +26 -26
  94. package/dist/number/branded-types/safe-int.d.mts +27 -27
  95. package/dist/number/branded-types/safe-int.mjs +27 -27
  96. package/dist/number/branded-types/uint.d.mts +19 -19
  97. package/dist/number/branded-types/uint.mjs +19 -19
  98. package/dist/number/num.d.mts +20 -20
  99. package/dist/number/num.mjs +16 -16
  100. package/dist/number/refined-number-utils.d.mts +11 -11
  101. package/dist/number/refined-number-utils.d.mts.map +1 -1
  102. package/dist/number/refined-number-utils.mjs +11 -11
  103. package/dist/object/object.d.mts +3 -3
  104. package/dist/object/object.d.mts.map +1 -1
  105. package/dist/object/object.mjs +3 -3
  106. package/dist/object/object.mjs.map +1 -1
  107. package/dist/others/tuple.d.mts +3 -3
  108. package/dist/others/tuple.mjs +3 -3
  109. package/dist/promise/promise.d.mts +4 -4
  110. package/dist/promise/promise.mjs +4 -4
  111. package/package.json +15 -13
  112. package/src/array/impl/array-utils-creation.test.mts +1 -1
  113. package/src/array/impl/array-utils-element-access.test.mts +16 -16
  114. package/src/array/impl/array-utils-modification.mts +38 -19
  115. package/src/array/impl/array-utils-reducing-value.mts +8 -8
  116. package/src/array/impl/array-utils-reducing-value.test.mts +23 -31
  117. package/src/array/impl/array-utils-search.mts +4 -4
  118. package/src/array/impl/array-utils-search.test.mts +10 -10
  119. package/src/array/impl/array-utils-set-op.mts +7 -7
  120. package/src/array/impl/array-utils-set-op.test.mts +13 -13
  121. package/src/array/impl/array-utils-size.mts +2 -2
  122. package/src/array/impl/array-utils-slicing.mts +2 -2
  123. package/src/array/impl/array-utils-transformation.test.mts +2 -2
  124. package/src/array/impl/array-utils-validation.mts +18 -18
  125. package/src/array/impl/array-utils-validation.test.mts +80 -78
  126. package/src/array/impl/array.test.mts +6 -6
  127. package/src/collections/imap-mapped.test.mts +16 -18
  128. package/src/collections/imap.mts +15 -15
  129. package/src/collections/imap.test.mts +31 -31
  130. package/src/collections/iset-mapped.mts +19 -19
  131. package/src/collections/iset-mapped.test.mts +52 -52
  132. package/src/collections/iset.mts +19 -19
  133. package/src/collections/iset.test.mts +130 -130
  134. package/src/collections/queue.mts +25 -25
  135. package/src/collections/queue.test.mts +33 -35
  136. package/src/collections/stack.mts +25 -25
  137. package/src/collections/stack.test.mts +15 -15
  138. package/src/functional/match.mts +1 -1
  139. package/src/functional/optional/impl/optional-expect-to-be.mts +2 -2
  140. package/src/functional/optional/impl/optional-is-none.mts +1 -1
  141. package/src/functional/optional/impl/optional-is-optional.mts +2 -2
  142. package/src/functional/optional/impl/optional-is-some.mts +1 -1
  143. package/src/functional/optional/impl/optional-none.mts +2 -2
  144. package/src/functional/optional/impl/optional-some.mts +2 -2
  145. package/src/functional/optional/impl/optional-to-nullable.mts +2 -2
  146. package/src/functional/optional/impl/optional-unwrap-or.mts +4 -4
  147. package/src/functional/optional/impl/optional-unwrap-throw.mts +1 -1
  148. package/src/functional/optional/impl/optional-unwrap.mts +2 -2
  149. package/src/functional/optional/impl/optional-zip.mts +1 -1
  150. package/src/functional/optional.test.mts +53 -54
  151. package/src/functional/pipe.mts +2 -2
  152. package/src/functional/pipe.test.mts +4 -4
  153. package/src/functional/result/impl/result-err.mts +1 -1
  154. package/src/functional/result/impl/result-expect-to-be.mts +2 -2
  155. package/src/functional/result/impl/result-from-promise.mts +1 -1
  156. package/src/functional/result/impl/result-from-throwable.mts +1 -1
  157. package/src/functional/result/impl/result-is-err.mts +2 -2
  158. package/src/functional/result/impl/result-is-ok.mts +2 -2
  159. package/src/functional/result/impl/result-is-result.mts +3 -3
  160. package/src/functional/result/impl/result-ok.mts +1 -1
  161. package/src/functional/result/impl/result-unwrap-err-or.mts +4 -4
  162. package/src/functional/result/impl/result-unwrap-err-throw.mts +1 -1
  163. package/src/functional/result/impl/result-unwrap-err.mts +2 -2
  164. package/src/functional/result/impl/result-unwrap-ok-or.mts +4 -4
  165. package/src/functional/result/impl/result-unwrap-ok.mts +2 -2
  166. package/src/functional/result/impl/result-unwrap-throw.mts +1 -1
  167. package/src/functional/result.test.mts +94 -152
  168. package/src/functional/ternary-result/impl/ternary-result-err.mts +1 -1
  169. package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +1 -1
  170. package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +1 -1
  171. package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +3 -3
  172. package/src/functional/ternary-result.test.mts +8 -8
  173. package/src/globals.d.mts +2 -1
  174. package/src/guard/has-key.mts +8 -5
  175. package/src/guard/has-key.test.mts +0 -5
  176. package/src/guard/is-error.test.mts +143 -0
  177. package/src/guard/is-non-empty-string.test.mts +24 -24
  178. package/src/guard/is-non-null-object.test.mts +26 -26
  179. package/src/guard/is-primitive.test.mts +28 -28
  180. package/src/guard/is-record.mts +1 -2
  181. package/src/guard/is-record.test.mts +57 -67
  182. package/src/guard/is-type.test.mts +151 -155
  183. package/src/guard/key-is-in.mts +2 -2
  184. package/src/guard/key-is-in.test.mts +2 -2
  185. package/src/json/json.mts +21 -21
  186. package/src/json/json.test.mts +135 -174
  187. package/src/number/branded-types/finite-number.test.mts +13 -11
  188. package/src/number/branded-types/int.mts +19 -19
  189. package/src/number/branded-types/int.test.mts +14 -14
  190. package/src/number/branded-types/int16.test.mts +16 -16
  191. package/src/number/branded-types/int32.test.mts +16 -16
  192. package/src/number/branded-types/non-negative-finite-number.test.mts +12 -12
  193. package/src/number/branded-types/non-negative-int16.test.mts +16 -16
  194. package/src/number/branded-types/non-negative-int32.test.mts +16 -16
  195. package/src/number/branded-types/non-zero-finite-number.test.mts +14 -14
  196. package/src/number/branded-types/non-zero-int.test.mts +19 -19
  197. package/src/number/branded-types/non-zero-int16.test.mts +16 -16
  198. package/src/number/branded-types/non-zero-int32.test.mts +16 -16
  199. package/src/number/branded-types/non-zero-safe-int.test.mts +23 -23
  200. package/src/number/branded-types/non-zero-uint16.test.mts +16 -16
  201. package/src/number/branded-types/non-zero-uint32.test.mts +16 -16
  202. package/src/number/branded-types/positive-finite-number.test.mts +14 -14
  203. package/src/number/branded-types/positive-int.mts +20 -20
  204. package/src/number/branded-types/positive-int.test.mts +17 -17
  205. package/src/number/branded-types/positive-int16.test.mts +15 -15
  206. package/src/number/branded-types/positive-int32.test.mts +15 -15
  207. package/src/number/branded-types/positive-safe-int.mts +26 -26
  208. package/src/number/branded-types/positive-safe-int.test.mts +19 -19
  209. package/src/number/branded-types/positive-uint16.test.mts +16 -16
  210. package/src/number/branded-types/positive-uint32.test.mts +16 -16
  211. package/src/number/branded-types/safe-int.mts +27 -27
  212. package/src/number/branded-types/safe-int.test.mts +18 -18
  213. package/src/number/branded-types/safe-uint.test.mts +17 -17
  214. package/src/number/branded-types/uint.mts +19 -19
  215. package/src/number/branded-types/uint.test.mts +15 -15
  216. package/src/number/branded-types/uint16.test.mts +15 -15
  217. package/src/number/branded-types/uint32.test.mts +15 -15
  218. package/src/number/enum/int8.test.mts +1 -1
  219. package/src/number/enum/uint8.test.mts +1 -1
  220. package/src/number/num.mts +20 -20
  221. package/src/number/num.test.mts +26 -26
  222. package/src/number/refined-number-utils.mts +13 -13
  223. package/src/object/object.mts +4 -3
  224. package/src/object/object.test.mts +6 -6
  225. package/src/others/cast-mutable.test.mts +1 -1
  226. package/src/others/cast-readonly.test.mts +4 -4
  227. package/src/others/if-then.test.mts +24 -24
  228. package/src/others/tuple.mts +3 -3
  229. package/src/promise/promise.mts +4 -4
  230. package/src/promise/promise.test.mts +7 -13
@@ -13,11 +13,11 @@ import { ErrTypeTagName, OkTypeTagName, WarnTypeTagName } from './tag.mjs';
13
13
  *
14
14
  * const notResult = { $$tag: 'ts-data-forge::Result.ok' };
15
15
  *
16
- * assert.ok(TernaryResult.isTernaryResult(okValue));
16
+ * assert.isTrue(TernaryResult.isTernaryResult(okValue));
17
17
  *
18
- * assert.ok(TernaryResult.isTernaryResult(warnValue));
18
+ * assert.isTrue(TernaryResult.isTernaryResult(warnValue));
19
19
  *
20
- * assert.ok(!TernaryResult.isTernaryResult(notResult));
20
+ * assert.isFalse(TernaryResult.isTernaryResult(notResult));
21
21
  * ```
22
22
  */
23
23
  export const isTernaryResult = (
@@ -10,15 +10,15 @@ describe('TernaryResult test', () => {
10
10
 
11
11
  const err = TernaryResult.err(new Error('boom'));
12
12
 
13
- expect(TernaryResult.isOk(ok)).toBe(true);
13
+ assert.isTrue(TernaryResult.isOk(ok));
14
14
 
15
- expect(TernaryResult.isWarn(warn)).toBe(true);
15
+ assert.isTrue(TernaryResult.isWarn(warn));
16
16
 
17
- expect(TernaryResult.isErr(err)).toBe(true);
17
+ assert.isTrue(TernaryResult.isErr(err));
18
18
 
19
- expect(TernaryResult.isTernaryResult(ok)).toBe(true);
19
+ assert.isTrue(TernaryResult.isTernaryResult(ok));
20
20
 
21
- expect(TernaryResult.isTernaryResult({})).toBe(false);
21
+ assert.isFalse(TernaryResult.isTernaryResult({}));
22
22
 
23
23
  expectType<typeof ok, TernaryResult<number, never, never>>('<=');
24
24
 
@@ -85,7 +85,7 @@ describe('TernaryResult test', () => {
85
85
 
86
86
  expect(TernaryResult.unwrapOk(okResult)).toBe(3);
87
87
 
88
- expect(TernaryResult.isWarn(warnResult)).toBe(true);
88
+ assert.isTrue(TernaryResult.isWarn(warnResult));
89
89
 
90
90
  if (TernaryResult.isWarn(warnResult)) {
91
91
  expect(warnResult.value).toBe(3);
@@ -242,7 +242,7 @@ describe('TernaryResult test', () => {
242
242
  Promise.reject(new Error('bad')),
243
243
  );
244
244
 
245
- expect(TernaryResult.isErr(rejected)).toBe(true);
245
+ assert.isTrue(TernaryResult.isErr(rejected));
246
246
  });
247
247
 
248
248
  test('fromThrowable converts thrown values', () => {
@@ -255,7 +255,7 @@ describe('TernaryResult test', () => {
255
255
  throw new Error('boom');
256
256
  });
257
257
 
258
- expect(TernaryResult.isErr(errorResult)).toBe(true);
258
+ assert.isTrue(TernaryResult.isErr(errorResult));
259
259
  });
260
260
 
261
261
  test('unwrapOkOr curried version', () => {
package/src/globals.d.mts CHANGED
@@ -13,7 +13,8 @@ type ArgArrayIndex<Ar extends readonly unknown[]> =
13
13
 
14
14
  type ArgArrayIndexWithNegative<Ar extends readonly unknown[]> =
15
15
  IsFixedLengthList<Ar> extends true
16
- ? IndexOfTuple<[...Ar, 0]> | NegativeIndexOfTuple<Ar>
16
+ ? // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
17
+ IndexOfTuple<[...Ar, 0]> | NegativeIndexOfTuple<Ar>
17
18
  : SizeType.ArgArrWithNegative;
18
19
 
19
20
  // https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/length
@@ -21,9 +21,9 @@
21
21
  *
22
22
  * if (hasKey(maybeUser, 'id')) {
23
23
  * // `maybeUser` is now known to have an `id` property.
24
- * assert(maybeUser.id === 42);
24
+ * assert.isTrue(maybeUser.id === 42);
25
25
  * } else {
26
- * assert.fail('Expected the object to contain the id key.');
26
+ * assert.fail();
27
27
  * }
28
28
  * ```
29
29
  *
@@ -58,11 +58,14 @@ export type HasKeyReturnType<
58
58
  > = R extends R // union distribution
59
59
  ? K extends keyof R
60
60
  ? string extends keyof R
61
- ? ReadonlyRecord<K, R[keyof R]> & R
61
+ ? // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
62
+ ReadonlyRecord<K, R[keyof R]> & R
62
63
  : number extends keyof R
63
- ? ReadonlyRecord<K, R[keyof R]> & R
64
+ ? // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
65
+ ReadonlyRecord<K, R[keyof R]> & R
64
66
  : symbol extends keyof R
65
- ? ReadonlyRecord<K, R[keyof R]> & R
67
+ ? // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
68
+ ReadonlyRecord<K, R[keyof R]> & R
66
69
  : R
67
70
  : never // omit union member that does not have key K
68
71
  : never; // dummy case for union distribution
@@ -61,7 +61,6 @@ import { hasKey, type HasKeyReturnType } from './has-key.mjs';
61
61
  {
62
62
  type R = Readonly<{ a: 0 }> | Readonly<{ b: 1 }>;
63
63
 
64
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
65
64
  const obj: R = { a: 0 } as R;
66
65
 
67
66
  if (hasKey(obj, 'a')) {
@@ -82,7 +81,6 @@ import { hasKey, type HasKeyReturnType } from './has-key.mjs';
82
81
  | Readonly<{ b: 2 }>
83
82
  | Readonly<{ c: 3 }>;
84
83
 
85
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
86
84
  const obj: R = { a: 0 } as R;
87
85
 
88
86
  if (hasKey(obj, 'a') && hasKey(obj, 'b')) {
@@ -101,7 +99,6 @@ import { hasKey, type HasKeyReturnType } from './has-key.mjs';
101
99
  | Readonly<{ a: 1; b: 1 }>
102
100
  | Readonly<{ b: 2 }>;
103
101
 
104
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
105
102
  const obj: R = { a: 0 } as R;
106
103
 
107
104
  expectType<
@@ -193,7 +190,6 @@ import { hasKey, type HasKeyReturnType } from './has-key.mjs';
193
190
  | Readonly<{ b: 2 }>
194
191
  | Record<string, number>;
195
192
 
196
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
197
193
  const o2 = { b: 2 } as O;
198
194
 
199
195
  if (hasOwnNaive(o2, 'a')) {
@@ -212,7 +208,6 @@ import { hasKey, type HasKeyReturnType } from './has-key.mjs';
212
208
  | Readonly<{ a: 1; b: 1 }>
213
209
  | Readonly<{ b: 2 }>;
214
210
 
215
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
216
211
  const o2 = { b: 2 } as O;
217
212
 
218
213
  if (hasOwnNaive(o2, 'a')) {
@@ -0,0 +1,143 @@
1
+ /* eslint-disable functional/immutable-data */
2
+ /* eslint-disable functional/no-class-inheritance */
3
+ /* eslint-disable unicorn/error-message */
4
+ import { isError as isErrorBySindreSorhus } from '@sindresorhus/is';
5
+ import { expectType } from '../expect-type.mjs';
6
+
7
+ describe('isError from @sindresorhus/is', () => {
8
+ test('should return true for native Error instances', () => {
9
+ assert.isTrue(isErrorBySindreSorhus(new Error()));
10
+
11
+ assert.isTrue(isErrorBySindreSorhus(new Error('test message')));
12
+ });
13
+
14
+ test('should return true for native Error subclasses', () => {
15
+ assert.isTrue(isErrorBySindreSorhus(new TypeError()));
16
+
17
+ assert.isTrue(isErrorBySindreSorhus(new RangeError()));
18
+
19
+ assert.isTrue(isErrorBySindreSorhus(new ReferenceError()));
20
+
21
+ assert.isTrue(isErrorBySindreSorhus(new SyntaxError()));
22
+
23
+ assert.isTrue(isErrorBySindreSorhus(new EvalError()));
24
+
25
+ assert.isTrue(isErrorBySindreSorhus(new URIError()));
26
+ });
27
+
28
+ test('should return true for custom Error subclasses', () => {
29
+ class CustomError extends Error {
30
+ constructor(message?: string) {
31
+ super(message);
32
+
33
+ this.name = 'CustomError';
34
+ }
35
+ }
36
+
37
+ assert.isTrue(isErrorBySindreSorhus(new CustomError()));
38
+
39
+ assert.isTrue(
40
+ isErrorBySindreSorhus(new CustomError('custom error message')),
41
+ );
42
+ });
43
+
44
+ test('should return true for Error subclass with additional properties', () => {
45
+ class ExtendedError extends Error {
46
+ code: number;
47
+
48
+ constructor(message: string, code: number) {
49
+ super(message);
50
+
51
+ this.name = 'ExtendedError';
52
+
53
+ this.code = code;
54
+ }
55
+ }
56
+
57
+ assert.isTrue(
58
+ isErrorBySindreSorhus(new ExtendedError('error with code', 404)),
59
+ );
60
+ });
61
+
62
+ test('should return true for deeply nested Error subclass', () => {
63
+ class BaseCustomError extends Error {
64
+ constructor(message?: string) {
65
+ super(message);
66
+
67
+ this.name = 'BaseCustomError';
68
+ }
69
+ }
70
+
71
+ class DerivedCustomError extends BaseCustomError {
72
+ constructor(message?: string) {
73
+ super(message);
74
+
75
+ this.name = 'DerivedCustomError';
76
+ }
77
+ }
78
+
79
+ assert.isTrue(isErrorBySindreSorhus(new DerivedCustomError()));
80
+ });
81
+
82
+ test('should return false for Error-like objects', () => {
83
+ const errorLikeObject = {
84
+ name: 'Error',
85
+ message: 'This is not a real error',
86
+ stack: 'fake stack trace',
87
+ };
88
+
89
+ assert.isFalse(isErrorBySindreSorhus(errorLikeObject));
90
+ });
91
+
92
+ test('should return false for non-Error values', () => {
93
+ assert.isFalse(isErrorBySindreSorhus(null));
94
+
95
+ assert.isFalse(isErrorBySindreSorhus(undefined));
96
+
97
+ assert.isFalse(isErrorBySindreSorhus(0));
98
+
99
+ assert.isFalse(isErrorBySindreSorhus(''));
100
+
101
+ assert.isFalse(isErrorBySindreSorhus('Error'));
102
+
103
+ assert.isFalse(isErrorBySindreSorhus(true));
104
+
105
+ assert.isFalse(isErrorBySindreSorhus({}));
106
+
107
+ assert.isFalse(isErrorBySindreSorhus([]));
108
+
109
+ assert.isFalse(isErrorBySindreSorhus(() => {}));
110
+ });
111
+
112
+ test('should act as a type guard', () => {
113
+ const value: Error | string = new Error('test');
114
+
115
+ if (isErrorBySindreSorhus(value)) {
116
+ expectType<typeof value, Error>('=');
117
+
118
+ expect(value.message).toBe('test');
119
+ }
120
+ });
121
+
122
+ test('should work with AggregateError', () => {
123
+ const aggregateError = new AggregateError(
124
+ [new Error('error 1'), new Error('error 2')],
125
+ 'Multiple errors occurred',
126
+ );
127
+
128
+ assert.isTrue(isErrorBySindreSorhus(aggregateError));
129
+ });
130
+
131
+ test('should return false for errors created with Object.create', () => {
132
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
133
+ const protoError = Object.create(Error.prototype);
134
+
135
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
136
+ protoError.message = 'proto error';
137
+
138
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
139
+ protoError.name = 'ProtoError';
140
+
141
+ assert.isFalse(isErrorBySindreSorhus(protoError));
142
+ });
143
+ });
@@ -3,51 +3,51 @@ import { isNonEmptyString } from './is-non-empty-string.mjs';
3
3
 
4
4
  describe(isNonEmptyString, () => {
5
5
  test('should return true for non-empty strings', () => {
6
- expect(isNonEmptyString('hello')).toBe(true);
6
+ assert.isTrue(isNonEmptyString('hello'));
7
7
 
8
- expect(isNonEmptyString('a')).toBe(true);
8
+ assert.isTrue(isNonEmptyString('a'));
9
9
 
10
- expect(isNonEmptyString(' ')).toBe(true); // Space is not empty
10
+ assert.isTrue(isNonEmptyString(' ')); // Space is not empty
11
11
 
12
- expect(isNonEmptyString(' multiple spaces ')).toBe(true);
12
+ assert.isTrue(isNonEmptyString(' multiple spaces '));
13
13
 
14
- expect(isNonEmptyString('123')).toBe(true);
14
+ assert.isTrue(isNonEmptyString('123'));
15
15
 
16
- expect(isNonEmptyString('special!@#$%')).toBe(true);
16
+ assert.isTrue(isNonEmptyString('special!@#$%'));
17
17
  });
18
18
 
19
19
  test('should return false for empty string', () => {
20
- expect(isNonEmptyString('')).toBe(false);
20
+ assert.isFalse(isNonEmptyString(''));
21
21
  });
22
22
 
23
23
  test('should return false for non-string values', () => {
24
- expect(isNonEmptyString(null)).toBe(false);
24
+ assert.isFalse(isNonEmptyString(null));
25
25
 
26
- expect(isNonEmptyString(undefined)).toBe(false);
26
+ assert.isFalse(isNonEmptyString(undefined));
27
27
 
28
28
  // @ts-expect-error Testing non-string types
29
- expect(isNonEmptyString(42)).toBe(false);
29
+ assert.isFalse(isNonEmptyString(42));
30
30
 
31
31
  // @ts-expect-error Testing non-string types
32
- expect(isNonEmptyString(0)).toBe(false);
32
+ assert.isFalse(isNonEmptyString(0));
33
33
 
34
34
  // @ts-expect-error Testing non-string types
35
- expect(isNonEmptyString(true)).toBe(false);
35
+ assert.isFalse(isNonEmptyString(true));
36
36
 
37
37
  // @ts-expect-error Testing non-string types
38
- expect(isNonEmptyString(false)).toBe(false);
38
+ assert.isFalse(isNonEmptyString(false));
39
39
 
40
40
  // @ts-expect-error Testing non-string types
41
- expect(isNonEmptyString({})).toBe(false);
41
+ assert.isFalse(isNonEmptyString({}));
42
42
 
43
43
  // @ts-expect-error Testing non-string types
44
- expect(isNonEmptyString([])).toBe(false);
44
+ assert.isFalse(isNonEmptyString([]));
45
45
 
46
46
  // @ts-expect-error Testing non-string types
47
- expect(isNonEmptyString(['string'])).toBe(false);
47
+ assert.isFalse(isNonEmptyString(['string']));
48
48
 
49
49
  // @ts-expect-error Testing non-string types
50
- expect(isNonEmptyString(() => 'string')).toBe(false);
50
+ assert.isFalse(isNonEmptyString(() => 'string'));
51
51
  });
52
52
 
53
53
  test('should act as a type guard', () => {
@@ -93,22 +93,22 @@ describe(isNonEmptyString, () => {
93
93
  });
94
94
 
95
95
  test('should handle string edge cases', () => {
96
- expect(isNonEmptyString('\n')).toBe(true); // Newline
96
+ assert.isTrue(isNonEmptyString('\n')); // Newline
97
97
 
98
- expect(isNonEmptyString('\t')).toBe(true); // Tab
98
+ assert.isTrue(isNonEmptyString('\t')); // Tab
99
99
 
100
- expect(isNonEmptyString('\r')).toBe(true); // Carriage return
100
+ assert.isTrue(isNonEmptyString('\r')); // Carriage return
101
101
 
102
- expect(isNonEmptyString('\0')).toBe(true); // Null character
102
+ assert.isTrue(isNonEmptyString('\0')); // Null character
103
103
 
104
- expect(isNonEmptyString('🎉')).toBe(true); // Emoji
104
+ assert.isTrue(isNonEmptyString('🎉')); // Emoji
105
105
 
106
- expect(isNonEmptyString('你好')).toBe(true); // Unicode characters
106
+ assert.isTrue(isNonEmptyString('你好')); // Unicode characters
107
107
  });
108
108
 
109
109
  test('should not accept String objects', () => {
110
110
  // @ts-expect-error Testing non-string types
111
111
  // eslint-disable-next-line unicorn/new-for-builtins
112
- expect(isNonEmptyString(new String('hello') as unknown)).toBe(false);
112
+ assert.isFalse(isNonEmptyString(new String('hello') as unknown));
113
113
  });
114
114
  });
@@ -3,73 +3,73 @@ import { isNonNullObject } from './is-non-null-object.mjs';
3
3
 
4
4
  describe(isNonNullObject, () => {
5
5
  test('should return true for plain objects', () => {
6
- expect(isNonNullObject({})).toBe(true);
6
+ assert.isTrue(isNonNullObject({}));
7
7
 
8
- expect(isNonNullObject({ a: 1, b: 'test' })).toBe(true);
8
+ assert.isTrue(isNonNullObject({ a: 1, b: 'test' }));
9
9
 
10
- expect(isNonNullObject({ nested: { value: true } })).toBe(true);
10
+ assert.isTrue(isNonNullObject({ nested: { value: true } }));
11
11
  });
12
12
 
13
13
  test('should return true for arrays', () => {
14
- expect(isNonNullObject([])).toBe(true);
14
+ assert.isTrue(isNonNullObject([]));
15
15
 
16
- expect(isNonNullObject([1, 2, 3])).toBe(true);
16
+ assert.isTrue(isNonNullObject([1, 2, 3]));
17
17
 
18
- expect(isNonNullObject(['a', 'b', 'c'])).toBe(true);
18
+ assert.isTrue(isNonNullObject(['a', 'b', 'c']));
19
19
  });
20
20
 
21
21
  test('should return true for functions', () => {
22
- expect(isNonNullObject(() => {})).toBe(false);
22
+ assert.isFalse(isNonNullObject(() => {}));
23
23
 
24
- expect(isNonNullObject(async () => {})).toBe(false);
24
+ assert.isFalse(isNonNullObject(async () => {}));
25
25
 
26
26
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
27
- expect(isNonNullObject(class MyClass {})).toBe(false);
27
+ assert.isFalse(isNonNullObject(class MyClass {}));
28
28
  });
29
29
 
30
30
  test('should return true for built-in objects', () => {
31
- expect(isNonNullObject(new Date())).toBe(true);
31
+ assert.isTrue(isNonNullObject(new Date()));
32
32
 
33
- expect(isNonNullObject(/test/u)).toBe(true);
33
+ assert.isTrue(isNonNullObject(/test/u));
34
34
 
35
- expect(isNonNullObject(/regex/u)).toBe(true);
35
+ assert.isTrue(isNonNullObject(/regex/u));
36
36
 
37
- expect(isNonNullObject(new Map())).toBe(true);
37
+ assert.isTrue(isNonNullObject(new Map()));
38
38
 
39
- expect(isNonNullObject(new Set())).toBe(true);
39
+ assert.isTrue(isNonNullObject(new Set()));
40
40
 
41
- expect(isNonNullObject(new Error('test'))).toBe(true);
41
+ assert.isTrue(isNonNullObject(new Error('test')));
42
42
  });
43
43
 
44
44
  test('should return true for boxed primitives', () => {
45
45
  // eslint-disable-next-line unicorn/new-for-builtins
46
- expect(isNonNullObject(new String('hello'))).toBe(true);
46
+ assert.isTrue(isNonNullObject(new String('hello')));
47
47
 
48
48
  // eslint-disable-next-line unicorn/new-for-builtins
49
- expect(isNonNullObject(new Number(42))).toBe(true);
49
+ assert.isTrue(isNonNullObject(new Number(42)));
50
50
 
51
51
  // eslint-disable-next-line unicorn/new-for-builtins
52
- expect(isNonNullObject(new Boolean(true))).toBe(true);
52
+ assert.isTrue(isNonNullObject(new Boolean(true)));
53
53
  });
54
54
 
55
55
  test('should return false for null', () => {
56
- expect(isNonNullObject(null)).toBe(false);
56
+ assert.isFalse(isNonNullObject(null));
57
57
  });
58
58
 
59
59
  test('should return false for primitive values', () => {
60
- expect(isNonNullObject(undefined)).toBe(false);
60
+ assert.isFalse(isNonNullObject(undefined));
61
61
 
62
- expect(isNonNullObject('string')).toBe(false);
62
+ assert.isFalse(isNonNullObject('string'));
63
63
 
64
- expect(isNonNullObject(42)).toBe(false);
64
+ assert.isFalse(isNonNullObject(42));
65
65
 
66
- expect(isNonNullObject(true)).toBe(false);
66
+ assert.isFalse(isNonNullObject(true));
67
67
 
68
- expect(isNonNullObject(false)).toBe(false);
68
+ assert.isFalse(isNonNullObject(false));
69
69
 
70
- expect(isNonNullObject(Symbol('test'))).toBe(false);
70
+ assert.isFalse(isNonNullObject(Symbol('test')));
71
71
 
72
- expect(isNonNullObject(123n)).toBe(false);
72
+ assert.isFalse(isNonNullObject(123n));
73
73
  });
74
74
 
75
75
  test('should act as a type guard', () => {
@@ -4,9 +4,9 @@ import { isSymbol } from './is-type.mjs';
4
4
 
5
5
  describe(isPrimitive, () => {
6
6
  test('should return true for string primitives', () => {
7
- expect(isPrimitive('hello')).toBe(true);
7
+ assert.isTrue(isPrimitive('hello'));
8
8
 
9
- expect(isPrimitive('')).toBe(true);
9
+ assert.isTrue(isPrimitive(''));
10
10
 
11
11
  const value: unknown = 'test';
12
12
 
@@ -19,77 +19,77 @@ describe(isPrimitive, () => {
19
19
  });
20
20
 
21
21
  test('should return true for number primitives', () => {
22
- expect(isPrimitive(42)).toBe(true);
22
+ assert.isTrue(isPrimitive(42));
23
23
 
24
- expect(isPrimitive(0)).toBe(true);
24
+ assert.isTrue(isPrimitive(0));
25
25
 
26
- expect(isPrimitive(-3.14)).toBe(true);
26
+ assert.isTrue(isPrimitive(-3.14));
27
27
 
28
- expect(isPrimitive(Number.NaN)).toBe(true);
28
+ assert.isTrue(isPrimitive(Number.NaN));
29
29
 
30
- expect(isPrimitive(Number.POSITIVE_INFINITY)).toBe(true);
30
+ assert.isTrue(isPrimitive(Number.POSITIVE_INFINITY));
31
31
  });
32
32
 
33
33
  test('should return true for boolean primitives', () => {
34
- expect(isPrimitive(true)).toBe(true);
34
+ assert.isTrue(isPrimitive(true));
35
35
 
36
- expect(isPrimitive(false)).toBe(true);
36
+ assert.isTrue(isPrimitive(false));
37
37
  });
38
38
 
39
39
  test('should return true for symbol primitives', () => {
40
- expect(isPrimitive(Symbol('test'))).toBe(true);
40
+ assert.isTrue(isPrimitive(Symbol('test')));
41
41
 
42
- expect(isPrimitive(Symbol.iterator)).toBe(true);
42
+ assert.isTrue(isPrimitive(Symbol.iterator));
43
43
  });
44
44
 
45
45
  test('should return true for bigint primitives', () => {
46
- expect(isPrimitive(123n)).toBe(true);
46
+ assert.isTrue(isPrimitive(123n));
47
47
 
48
- expect(isPrimitive(0n)).toBe(true);
48
+ assert.isTrue(isPrimitive(0n));
49
49
 
50
- expect(isPrimitive(-123n)).toBe(true);
50
+ assert.isTrue(isPrimitive(-123n));
51
51
  });
52
52
 
53
53
  test('should return true for null', () => {
54
54
  // Note: null is considered an object by typeof, so isPrimitive returns false
55
- expect(isPrimitive(null)).toBe(true);
55
+ assert.isTrue(isPrimitive(null));
56
56
  });
57
57
 
58
58
  test('should return true for undefined', () => {
59
- expect(isPrimitive(undefined)).toBe(true);
59
+ assert.isTrue(isPrimitive(undefined));
60
60
  });
61
61
 
62
62
  test('should return false for objects', () => {
63
- expect(isPrimitive({})).toBe(false);
63
+ assert.isFalse(isPrimitive({}));
64
64
 
65
- expect(isPrimitive({ a: 1 })).toBe(false);
65
+ assert.isFalse(isPrimitive({ a: 1 }));
66
66
 
67
- expect(isPrimitive(new Date())).toBe(false);
67
+ assert.isFalse(isPrimitive(new Date()));
68
68
  });
69
69
 
70
70
  test('should return false for arrays', () => {
71
- expect(isPrimitive([])).toBe(false);
71
+ assert.isFalse(isPrimitive([]));
72
72
 
73
- expect(isPrimitive([1, 2, 3])).toBe(false);
73
+ assert.isFalse(isPrimitive([1, 2, 3]));
74
74
  });
75
75
 
76
76
  test('should return false for functions', () => {
77
- expect(isPrimitive(() => {})).toBe(false);
77
+ assert.isFalse(isPrimitive(() => {}));
78
78
 
79
- expect(isPrimitive(() => {})).toBe(false);
79
+ assert.isFalse(isPrimitive(() => {}));
80
80
 
81
- expect(isPrimitive(async () => {})).toBe(false);
81
+ assert.isFalse(isPrimitive(async () => {}));
82
82
  });
83
83
 
84
84
  test('should return false for boxed primitives', () => {
85
85
  // eslint-disable-next-line unicorn/new-for-builtins
86
- expect(isPrimitive(new String('hello'))).toBe(false);
86
+ assert.isFalse(isPrimitive(new String('hello')));
87
87
 
88
88
  // eslint-disable-next-line unicorn/new-for-builtins
89
- expect(isPrimitive(new Number(42))).toBe(false);
89
+ assert.isFalse(isPrimitive(new Number(42)));
90
90
 
91
91
  // eslint-disable-next-line unicorn/new-for-builtins
92
- expect(isPrimitive(new Boolean(true))).toBe(false);
92
+ assert.isFalse(isPrimitive(new Boolean(true)));
93
93
  });
94
94
 
95
95
  test('should narrow types correctly in conditional', () => {
@@ -120,7 +120,7 @@ describe(isPrimitive, () => {
120
120
 
121
121
  expect(primitives[4]).toBeUndefined();
122
122
 
123
- expect(isSymbol(primitives[5])).toBe(true);
123
+ assert.isTrue(isSymbol(primitives[5]));
124
124
 
125
125
  assert.deepStrictEqual(nonPrimitives, [{}, []]);
126
126
  });
@@ -38,8 +38,7 @@ import { isNonNullObject } from './is-non-null-object.mjs';
38
38
  * @see {@link isNonNullObject} - For checking any object type (includes arrays)
39
39
  * @see {@link hasKey} - For checking if a record has specific keys
40
40
  */
41
- export const isRecord = (u: unknown): u is UnknownRecord =>
42
- isNonNullObject(u) && !Array.isArray(u);
41
+ export const isRecord = (u: unknown): u is UnknownRecord => isNonNullObject(u);
43
42
 
44
43
  /**
45
44
  * Type guard that checks if a value is a mutable record (an object with mutable string keys).