ts-data-forge 14.7.1 → 14.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.
Files changed (281) hide show
  1. package/README.md +21 -34
  2. package/dist/array/impl/array-utils-creation.d.mts +3 -3
  3. package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
  4. package/dist/array/impl/array-utils-creation.mjs.map +1 -1
  5. package/dist/array/impl/array-utils-element-access.d.mts +2 -2
  6. package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
  7. package/dist/array/impl/array-utils-element-access.mjs +1 -1
  8. package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
  9. package/dist/array/impl/array-utils-iterators.d.mts +1 -1
  10. package/dist/array/impl/array-utils-iterators.d.mts.map +1 -1
  11. package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts +1 -1
  12. package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -1
  13. package/dist/array/impl/array-utils-length-bounded-array-guard.d.mts +9 -9
  14. package/dist/array/impl/array-utils-length-bounded-array-guard.d.mts.map +1 -1
  15. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs +1 -1
  16. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs.map +1 -1
  17. package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts +2 -2
  18. package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts.map +1 -1
  19. package/dist/array/impl/array-utils-length-bounded-tuple-guard.d.mts +3 -3
  20. package/dist/array/impl/array-utils-length-bounded-tuple-guard.d.mts.map +1 -1
  21. package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs +1 -1
  22. package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs.map +1 -1
  23. package/dist/array/impl/array-utils-modification.d.mts +2 -2
  24. package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
  25. package/dist/array/impl/array-utils-reducing-value.d.mts +2 -2
  26. package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
  27. package/dist/array/impl/array-utils-reducing-value.mjs +3 -4
  28. package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
  29. package/dist/array/impl/array-utils-search.d.mts +1 -1
  30. package/dist/array/impl/array-utils-search.d.mts.map +1 -1
  31. package/dist/array/impl/array-utils-set-op.d.mts +1 -1
  32. package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
  33. package/dist/array/impl/array-utils-size.d.mts +2 -2
  34. package/dist/array/impl/array-utils-size.d.mts.map +1 -1
  35. package/dist/array/impl/array-utils-slice-clamped.d.mts +1 -1
  36. package/dist/array/impl/array-utils-slice-clamped.d.mts.map +1 -1
  37. package/dist/array/impl/array-utils-slicing.d.mts +2 -2
  38. package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
  39. package/dist/array/impl/array-utils-transformation.d.mts +2 -2
  40. package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
  41. package/dist/array/impl/array-utils-transformation.mjs +6 -3
  42. package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
  43. package/dist/array/impl/array-utils-validation.d.mts +2 -2
  44. package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
  45. package/dist/collections/imap-mapped.d.mts +2 -2
  46. package/dist/collections/imap-mapped.d.mts.map +1 -1
  47. package/dist/collections/imap-mapped.mjs +10 -7
  48. package/dist/collections/imap-mapped.mjs.map +1 -1
  49. package/dist/collections/imap.d.mts +2 -2
  50. package/dist/collections/imap.d.mts.map +1 -1
  51. package/dist/collections/imap.mjs +10 -7
  52. package/dist/collections/imap.mjs.map +1 -1
  53. package/dist/collections/iset-mapped.d.mts +2 -2
  54. package/dist/collections/iset-mapped.d.mts.map +1 -1
  55. package/dist/collections/iset-mapped.mjs +6 -3
  56. package/dist/collections/iset-mapped.mjs.map +1 -1
  57. package/dist/collections/iset.d.mts +2 -2
  58. package/dist/collections/iset.d.mts.map +1 -1
  59. package/dist/collections/iset.mjs +5 -5
  60. package/dist/collections/iset.mjs.map +1 -1
  61. package/dist/collections/queue.d.mts +1 -1
  62. package/dist/collections/queue.d.mts.map +1 -1
  63. package/dist/collections/stack.d.mts +1 -1
  64. package/dist/collections/stack.d.mts.map +1 -1
  65. package/dist/guard/is-non-empty-string.d.mts +1 -1
  66. package/dist/guard/is-non-empty-string.d.mts.map +1 -1
  67. package/dist/guard/is-primitive.d.mts +1 -1
  68. package/dist/guard/is-primitive.d.mts.map +1 -1
  69. package/dist/guard/is-type.d.mts +1 -1
  70. package/dist/guard/is-type.d.mts.map +1 -1
  71. package/dist/iterator/range.d.mts +5 -4
  72. package/dist/iterator/range.d.mts.map +1 -1
  73. package/dist/iterator/range.mjs.map +1 -1
  74. package/dist/json/json.d.mts +29 -32
  75. package/dist/json/json.d.mts.map +1 -1
  76. package/dist/json/json.mjs +1 -4
  77. package/dist/json/json.mjs.map +1 -1
  78. package/dist/number/branded-types/finite-number.d.mts +1 -1
  79. package/dist/number/branded-types/finite-number.d.mts.map +1 -1
  80. package/dist/number/branded-types/int.d.mts +2 -2
  81. package/dist/number/branded-types/int.d.mts.map +1 -1
  82. package/dist/number/branded-types/int16.d.mts +1 -1
  83. package/dist/number/branded-types/int16.d.mts.map +1 -1
  84. package/dist/number/branded-types/int32.d.mts +1 -1
  85. package/dist/number/branded-types/int32.d.mts.map +1 -1
  86. package/dist/number/branded-types/negative-finite-number.d.mts +1 -1
  87. package/dist/number/branded-types/negative-finite-number.d.mts.map +1 -1
  88. package/dist/number/branded-types/negative-int.d.mts +1 -1
  89. package/dist/number/branded-types/negative-int.d.mts.map +1 -1
  90. package/dist/number/branded-types/negative-safe-int.d.mts +1 -1
  91. package/dist/number/branded-types/negative-safe-int.d.mts.map +1 -1
  92. package/dist/number/branded-types/non-negative-finite-number.d.mts +1 -1
  93. package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
  94. package/dist/number/branded-types/non-negative-int16.d.mts +1 -1
  95. package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
  96. package/dist/number/branded-types/non-negative-int32.d.mts +1 -1
  97. package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
  98. package/dist/number/branded-types/non-positive-finite-number.d.mts +1 -1
  99. package/dist/number/branded-types/non-positive-finite-number.d.mts.map +1 -1
  100. package/dist/number/branded-types/non-positive-int.d.mts +1 -1
  101. package/dist/number/branded-types/non-positive-int.d.mts.map +1 -1
  102. package/dist/number/branded-types/non-positive-safe-int.d.mts +1 -1
  103. package/dist/number/branded-types/non-positive-safe-int.d.mts.map +1 -1
  104. package/dist/number/branded-types/non-zero-finite-number.d.mts +1 -1
  105. package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
  106. package/dist/number/branded-types/non-zero-int.d.mts +1 -1
  107. package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
  108. package/dist/number/branded-types/non-zero-int16.d.mts +1 -1
  109. package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
  110. package/dist/number/branded-types/non-zero-int32.d.mts +1 -1
  111. package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
  112. package/dist/number/branded-types/non-zero-safe-int.d.mts +1 -1
  113. package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
  114. package/dist/number/branded-types/non-zero-uint16.d.mts +1 -1
  115. package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
  116. package/dist/number/branded-types/non-zero-uint32.d.mts +1 -1
  117. package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
  118. package/dist/number/branded-types/positive-finite-number.d.mts +1 -1
  119. package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
  120. package/dist/number/branded-types/positive-int.d.mts +2 -2
  121. package/dist/number/branded-types/positive-int.d.mts.map +1 -1
  122. package/dist/number/branded-types/positive-int16.d.mts +1 -1
  123. package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
  124. package/dist/number/branded-types/positive-int32.d.mts +1 -1
  125. package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
  126. package/dist/number/branded-types/positive-safe-int.d.mts +2 -2
  127. package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
  128. package/dist/number/branded-types/positive-uint16.d.mts +1 -1
  129. package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
  130. package/dist/number/branded-types/positive-uint32.d.mts +1 -1
  131. package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
  132. package/dist/number/branded-types/safe-int.d.mts +2 -2
  133. package/dist/number/branded-types/safe-int.d.mts.map +1 -1
  134. package/dist/number/branded-types/safe-int.mjs.map +1 -1
  135. package/dist/number/branded-types/safe-uint.d.mts +1 -1
  136. package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
  137. package/dist/number/branded-types/uint.d.mts +2 -2
  138. package/dist/number/branded-types/uint.d.mts.map +1 -1
  139. package/dist/number/branded-types/uint16.d.mts +1 -1
  140. package/dist/number/branded-types/uint16.d.mts.map +1 -1
  141. package/dist/number/branded-types/uint32.d.mts +1 -1
  142. package/dist/number/branded-types/uint32.d.mts.map +1 -1
  143. package/dist/number/enum/int8.d.mts +1 -1
  144. package/dist/number/enum/int8.d.mts.map +1 -1
  145. package/dist/number/enum/uint8.d.mts +1 -1
  146. package/dist/number/enum/uint8.d.mts.map +1 -1
  147. package/dist/number/num-arithmetic-types.d.mts +1 -1
  148. package/dist/number/num-arithmetic-types.d.mts.map +1 -1
  149. package/dist/number/num.d.mts +3 -3
  150. package/dist/number/num.d.mts.map +1 -1
  151. package/dist/number/refined-number-utils.d.mts +2 -2
  152. package/dist/number/refined-number-utils.d.mts.map +1 -1
  153. package/dist/number/refined-number-utils.mjs +6 -4
  154. package/dist/number/refined-number-utils.mjs.map +1 -1
  155. package/dist/object/object.d.mts +5 -8
  156. package/dist/object/object.d.mts.map +1 -1
  157. package/dist/object/object.mjs +16 -13
  158. package/dist/object/object.mjs.map +1 -1
  159. package/dist/others/cast-mutable.d.mts +1 -1
  160. package/dist/others/cast-mutable.d.mts.map +1 -1
  161. package/dist/others/cast-readonly.d.mts +1 -1
  162. package/dist/others/cast-readonly.d.mts.map +1 -1
  163. package/dist/others/debounce-function.d.mts.map +1 -1
  164. package/dist/others/debounce-function.mjs +1 -5
  165. package/dist/others/debounce-function.mjs.map +1 -1
  166. package/dist/others/memoize-function.d.mts +1 -1
  167. package/dist/others/memoize-function.d.mts.map +1 -1
  168. package/dist/string/str.d.mts +26 -18
  169. package/dist/string/str.d.mts.map +1 -1
  170. package/dist/string/str.mjs +9 -1
  171. package/dist/string/str.mjs.map +1 -1
  172. package/dist/types.d.mts +1 -1
  173. package/dist/types.d.mts.map +1 -1
  174. package/package.json +31 -30
  175. package/src/array/impl/array-utils-creation.mts +24 -22
  176. package/src/array/impl/array-utils-creation.test.mts +25 -22
  177. package/src/array/impl/array-utils-element-access.mts +7 -7
  178. package/src/array/impl/array-utils-element-access.test.mts +2 -2
  179. package/src/array/impl/array-utils-iterators.mts +1 -1
  180. package/src/array/impl/array-utils-iterators.test.mts +1 -1
  181. package/src/array/impl/array-utils-length-bounded-array-cast.mts +7 -7
  182. package/src/array/impl/array-utils-length-bounded-array-cast.test.mts +6 -6
  183. package/src/array/impl/array-utils-length-bounded-array-guard.mts +15 -15
  184. package/src/array/impl/array-utils-length-bounded-array-guard.test.mts +66 -54
  185. package/src/array/impl/array-utils-length-bounded-tuple-cast.mts +6 -6
  186. package/src/array/impl/array-utils-length-bounded-tuple-cast.test.mts +10 -10
  187. package/src/array/impl/array-utils-length-bounded-tuple-guard.mts +8 -8
  188. package/src/array/impl/array-utils-length-bounded-tuple-guard.test.mts +38 -28
  189. package/src/array/impl/array-utils-length-constraint-preservation.test.mts +14 -14
  190. package/src/array/impl/array-utils-modification.mts +12 -12
  191. package/src/array/impl/array-utils-modification.test.mts +7 -7
  192. package/src/array/impl/array-utils-overload-type-error.test.mts +1 -1
  193. package/src/array/impl/array-utils-reducing-value.mts +9 -11
  194. package/src/array/impl/array-utils-reducing-value.test.mts +2 -2
  195. package/src/array/impl/array-utils-search.mts +4 -4
  196. package/src/array/impl/array-utils-search.test.mts +25 -17
  197. package/src/array/impl/array-utils-set-op.mts +1 -1
  198. package/src/array/impl/array-utils-shape-invariants.test.mts +8 -8
  199. package/src/array/impl/array-utils-size.mts +5 -5
  200. package/src/array/impl/array-utils-slice-clamped.mts +2 -2
  201. package/src/array/impl/array-utils-slicing.mts +8 -8
  202. package/src/array/impl/array-utils-slicing.test.mts +1 -1
  203. package/src/array/impl/array-utils-transformation.mts +26 -24
  204. package/src/array/impl/array-utils-transformation.test.mts +12 -10
  205. package/src/array/impl/array-utils-validation.mts +7 -7
  206. package/src/array/impl/array-utils-validation.test.mts +39 -39
  207. package/src/array/impl/array.test.mts +1 -1
  208. package/src/collections/imap-mapped.mts +15 -9
  209. package/src/collections/imap-mapped.test.mts +1 -1
  210. package/src/collections/imap.mts +15 -9
  211. package/src/collections/imap.test.mts +7 -5
  212. package/src/collections/iset-mapped.mts +14 -8
  213. package/src/collections/iset.mts +12 -10
  214. package/src/collections/iset.test.mts +14 -12
  215. package/src/collections/queue.mts +1 -1
  216. package/src/collections/stack.mts +1 -1
  217. package/src/collections/stack.test.mts +8 -6
  218. package/src/guard/is-error.test.mts +6 -4
  219. package/src/guard/is-non-empty-string.mts +1 -1
  220. package/src/guard/is-non-empty-string.test.mts +15 -11
  221. package/src/guard/is-primitive.mts +1 -1
  222. package/src/guard/is-type.mts +1 -1
  223. package/src/guard/is-type.test.mts +87 -59
  224. package/src/iterator/range.mts +5 -9
  225. package/src/iterator/range.test.mts +29 -0
  226. package/src/json/json.mts +32 -35
  227. package/src/json/json.test.mts +106 -89
  228. package/src/number/branded-types/finite-number.mts +4 -4
  229. package/src/number/branded-types/int.mts +2 -2
  230. package/src/number/branded-types/int16.mts +1 -1
  231. package/src/number/branded-types/int32.mts +1 -1
  232. package/src/number/branded-types/negative-finite-number.mts +1 -1
  233. package/src/number/branded-types/negative-finite-number.test.mts +4 -4
  234. package/src/number/branded-types/negative-int.mts +3 -3
  235. package/src/number/branded-types/negative-int.test.mts +1 -1
  236. package/src/number/branded-types/negative-safe-int.mts +3 -3
  237. package/src/number/branded-types/negative-safe-int.test.mts +1 -1
  238. package/src/number/branded-types/non-negative-finite-number.mts +3 -3
  239. package/src/number/branded-types/non-negative-int16.mts +1 -1
  240. package/src/number/branded-types/non-negative-int32.mts +1 -1
  241. package/src/number/branded-types/non-positive-finite-number.mts +1 -1
  242. package/src/number/branded-types/non-positive-int.mts +1 -1
  243. package/src/number/branded-types/non-positive-safe-int.mts +1 -1
  244. package/src/number/branded-types/non-zero-finite-number.mts +5 -5
  245. package/src/number/branded-types/non-zero-int.mts +1 -1
  246. package/src/number/branded-types/non-zero-int16.mts +1 -1
  247. package/src/number/branded-types/non-zero-int32.mts +1 -1
  248. package/src/number/branded-types/non-zero-safe-int.mts +4 -4
  249. package/src/number/branded-types/non-zero-uint16.mts +1 -1
  250. package/src/number/branded-types/non-zero-uint32.mts +1 -1
  251. package/src/number/branded-types/positive-finite-number.mts +4 -4
  252. package/src/number/branded-types/positive-int.mts +2 -2
  253. package/src/number/branded-types/positive-int16.mts +1 -1
  254. package/src/number/branded-types/positive-int32.mts +1 -1
  255. package/src/number/branded-types/positive-safe-int.mts +4 -4
  256. package/src/number/branded-types/positive-uint16.mts +1 -1
  257. package/src/number/branded-types/positive-uint32.mts +1 -1
  258. package/src/number/branded-types/safe-int.mts +2 -5
  259. package/src/number/branded-types/safe-uint.mts +1 -1
  260. package/src/number/branded-types/uint.mts +2 -2
  261. package/src/number/branded-types/uint16.mts +1 -1
  262. package/src/number/branded-types/uint32.mts +1 -1
  263. package/src/number/enum/int8.mts +5 -5
  264. package/src/number/enum/uint8.mts +4 -4
  265. package/src/number/num-arithmetic-types.mts +27 -27
  266. package/src/number/num-arithmetic-types.test.mts +21 -21
  267. package/src/number/num-arithmetic.test.mts +6 -6
  268. package/src/number/num.mts +24 -24
  269. package/src/number/num.test.mts +1 -1
  270. package/src/number/refined-number-utils.mts +25 -21
  271. package/src/object/object.mts +46 -34
  272. package/src/object/object.test.mts +5 -5
  273. package/src/others/cast-mutable.mts +1 -1
  274. package/src/others/cast-readonly.mts +1 -1
  275. package/src/others/debounce-function.mts +1 -5
  276. package/src/others/fast-deep-equal.test.mts +1 -1
  277. package/src/others/map-nullable.test.mts +1 -1
  278. package/src/others/memoize-function.mts +1 -1
  279. package/src/string/str.mts +33 -25
  280. package/src/string/str.test.mts +48 -38
  281. package/src/types.mts +14 -14
@@ -1,12 +1,12 @@
1
1
  /* eslint-disable unicorn/prefer-iterator-to-array-at-end */
2
- import {
3
- type FixedLengthTuple,
4
- type ReadonlyRecord,
5
- type WidenLiteral,
2
+ import type {
3
+ FixedLengthTuple,
4
+ ReadonlyRecord,
5
+ WidenLiteral,
6
6
  } from 'ts-type-forge';
7
7
  import { asUint32 } from '../number/index.mjs';
8
8
  import { unknownToString } from '../others/index.mjs';
9
- import { type MapSetKeyType, type SizeType } from '../types.mjs';
9
+ import type { MapSetKeyType, SizeType } from '../types.mjs';
10
10
 
11
11
  /**
12
12
  * Interface for an immutable set with custom element mapping and membership
@@ -1240,7 +1240,9 @@ class ISetMappedClass<K, KM extends MapSetKeyType>
1240
1240
  /** @inheritdoc */
1241
1241
  every(predicate: (key: K) => boolean): boolean {
1242
1242
  for (const key of this.values()) {
1243
- if (!predicate(key)) return false;
1243
+ if (!predicate(key)) {
1244
+ return false;
1245
+ }
1244
1246
  }
1245
1247
 
1246
1248
  return true;
@@ -1249,7 +1251,9 @@ class ISetMappedClass<K, KM extends MapSetKeyType>
1249
1251
  /** @inheritdoc */
1250
1252
  some(predicate: (key: K) => boolean): boolean {
1251
1253
  for (const key of this.values()) {
1252
- if (predicate(key)) return true;
1254
+ if (predicate(key)) {
1255
+ return true;
1256
+ }
1253
1257
  }
1254
1258
 
1255
1259
  return false;
@@ -1257,7 +1261,9 @@ class ISetMappedClass<K, KM extends MapSetKeyType>
1257
1261
 
1258
1262
  /** @inheritdoc */
1259
1263
  add(key: K): ISetMapped<K, KM> {
1260
- if (this.has(key)) return this;
1264
+ if (this.has(key)) {
1265
+ return this;
1266
+ }
1261
1267
 
1262
1268
  return ISetMapped.create(
1263
1269
  [...this.#set, this.#toKey(key)].map(this.#fromKey),
@@ -1,12 +1,12 @@
1
1
  /* eslint-disable unicorn/prefer-iterator-to-array-at-end */
2
- import {
3
- type FixedLengthTuple,
4
- type ReadonlyRecord,
5
- type WidenLiteral,
2
+ import type {
3
+ FixedLengthTuple,
4
+ ReadonlyRecord,
5
+ WidenLiteral,
6
6
  } from 'ts-type-forge';
7
7
  import { asUint32 } from '../number/index.mjs';
8
8
  import { unknownToString } from '../others/index.mjs';
9
- import { type MapSetKeyType, type SizeType } from '../types.mjs';
9
+ import type { MapSetKeyType, SizeType } from '../types.mjs';
10
10
 
11
11
  /**
12
12
  * Interface for an immutable set with membership testing and set operation
@@ -766,7 +766,9 @@ class ISetClass<K extends MapSetKeyType> implements ISet<K>, Iterable<K> {
766
766
  /** @inheritdoc */
767
767
  every(predicate: (key: K) => boolean): boolean {
768
768
  for (const key of this.values()) {
769
- if (!predicate(key)) return false;
769
+ if (!predicate(key)) {
770
+ return false;
771
+ }
770
772
  }
771
773
 
772
774
  return true;
@@ -775,7 +777,9 @@ class ISetClass<K extends MapSetKeyType> implements ISet<K>, Iterable<K> {
775
777
  /** @inheritdoc */
776
778
  some(predicate: (key: K) => boolean): boolean {
777
779
  for (const key of this.values()) {
778
- if (predicate(key)) return true;
780
+ if (predicate(key)) {
781
+ return true;
782
+ }
779
783
  }
780
784
 
781
785
  return false;
@@ -783,9 +787,7 @@ class ISetClass<K extends MapSetKeyType> implements ISet<K>, Iterable<K> {
783
787
 
784
788
  /** @inheritdoc */
785
789
  add(key: K): ISet<K> {
786
- if (this.has(key)) return this;
787
-
788
- return ISet.create([...this.#set, key]);
790
+ return this.has(key) ? this : ISet.create([...this.#set, key]);
789
791
  }
790
792
 
791
793
  /** @inheritdoc */
@@ -1,12 +1,12 @@
1
- import {
2
- type DeepReadonly,
3
- type FixedLengthTuple,
4
- type MutableFixedLengthTuple,
5
- type Primitive,
1
+ import type {
2
+ DeepReadonly,
3
+ FixedLengthTuple,
4
+ MutableFixedLengthTuple,
5
+ Primitive,
6
6
  } from 'ts-type-forge';
7
7
  import { expectType } from '../expect-type.mjs';
8
8
  import { isString } from '../guard/index.mjs';
9
- import { type MapSetKeyType } from '../types.mjs';
9
+ import type { MapSetKeyType } from '../types.mjs';
10
10
  import { ISet } from './iset.mjs';
11
11
 
12
12
  describe('ISet.create', () => {
@@ -188,13 +188,15 @@ describe('every method as type guard', () => {
188
188
  test('should narrow type when used as type guard', () => {
189
189
  const set = ISet.create<string | number>(['hello', 'world']);
190
190
 
191
- if (set.every((value): value is string => typeof value === 'string')) {
192
- // Type should be narrowed to ISet<string>
193
- const values = set.toArray();
191
+ if (!set.every((value): value is string => typeof value === 'string')) {
192
+ return;
193
+ }
194
+
195
+ // Type should be narrowed to ISet<string>
196
+ const values = set.toArray();
194
197
 
195
- for (const value of values) {
196
- assert.isTrue(isString(value));
197
- }
198
+ for (const value of values) {
199
+ assert.isTrue(isString(value));
198
200
  }
199
201
  });
200
202
 
@@ -1,7 +1,7 @@
1
1
  import { Optional } from '../functional/index.mjs';
2
2
  import { range } from '../iterator/index.mjs';
3
3
  import { asSafeUint, asUint32 } from '../number/index.mjs';
4
- import { type SizeType } from '../types.mjs';
4
+ import type { SizeType } from '../types.mjs';
5
5
 
6
6
  /**
7
7
  * Interface for a high-performance queue with FIFO (First-In, First-Out)
@@ -1,7 +1,7 @@
1
1
  import { Optional } from '../functional/index.mjs';
2
2
  import { range } from '../iterator/index.mjs';
3
3
  import { asUint32, Uint32 } from '../number/index.mjs';
4
- import { type SizeType } from '../types.mjs';
4
+ import type { SizeType } from '../types.mjs';
5
5
 
6
6
  /**
7
7
  * Interface for a high-performance stack with LIFO (Last-In, First-Out)
@@ -2,7 +2,7 @@ import { expectType } from '../expect-type.mjs';
2
2
  import { Optional } from '../functional/index.mjs';
3
3
  import { range } from '../iterator/index.mjs';
4
4
  import { asPositiveSafeInt, asSafeInt } from '../number/index.mjs';
5
- import { type SizeType } from '../types.mjs';
5
+ import type { SizeType } from '../types.mjs';
6
6
  import { createStack, type Stack } from './stack.mjs';
7
7
 
8
8
  describe('Stack test', () => {
@@ -263,12 +263,14 @@ describe('Stack test', () => {
263
263
  for (const i of range(100)) {
264
264
  stack.push(i);
265
265
 
266
- if (i % 2 === 1) {
267
- // Pop every other time
268
- const result = stack.pop();
269
-
270
- expect(Optional.unwrap(result)).toBe(i);
266
+ if (i % 2 !== 1) {
267
+ continue;
271
268
  }
269
+
270
+ // Pop every other time
271
+ const result = stack.pop();
272
+
273
+ expect(Optional.unwrap(result)).toBe(i);
272
274
  }
273
275
 
274
276
  // Should have 50 elements remaining (0, 2, 4, ..., 98)
@@ -111,11 +111,13 @@ describe('isError from @sindresorhus/is', () => {
111
111
  test('should act as a type guard', () => {
112
112
  const value: Error | string = new Error('test');
113
113
 
114
- if (isErrorBySindreSorhus(value)) {
115
- expectType<typeof value, Error>('=');
116
-
117
- expect(value.message).toBe('test');
114
+ if (!isErrorBySindreSorhus(value)) {
115
+ return;
118
116
  }
117
+
118
+ expectType<typeof value, Error>('=');
119
+
120
+ expect(value.message).toBe('test');
119
121
  });
120
122
 
121
123
  test('should work with AggregateError', () => {
@@ -1,4 +1,4 @@
1
- import { type NonEmptyString, type RelaxedExclude } from 'ts-type-forge';
1
+ import type { NonEmptyString, RelaxedExclude } from 'ts-type-forge';
2
2
 
3
3
  /**
4
4
  * Type guard that checks if a value is a non-empty string.
@@ -1,4 +1,4 @@
1
- import { type NonEmptyString } from 'ts-type-forge';
1
+ import type { NonEmptyString } from 'ts-type-forge';
2
2
  import { expectType } from '../expect-type.mjs';
3
3
  import { isNonEmptyString } from './is-non-empty-string.mjs';
4
4
 
@@ -55,24 +55,28 @@ describe(isNonEmptyString, () => {
55
55
  const value: unknown = 'test';
56
56
 
57
57
  // @ts-expect-error Testing non-string types
58
- if (isNonEmptyString(value)) {
59
- expectType<typeof value, NonEmptyString>('=');
58
+ if (!isNonEmptyString(value)) {
59
+ return;
60
+ }
60
61
 
61
- // TypeScript knows it's a string
62
- expect(value.length).toBeGreaterThan(0);
62
+ expectType<typeof value, NonEmptyString>('=');
63
63
 
64
- expect(value.at(0)).toBe('t');
65
- }
64
+ // TypeScript knows it's a string
65
+ expect(value.length).toBeGreaterThan(0);
66
+
67
+ expect(value.at(0)).toBe('t');
66
68
  });
67
69
 
68
70
  test('should narrow string | undefined | null types', () => {
69
71
  const maybeString: string | undefined | null = 'hello';
70
72
 
71
- if (isNonEmptyString(maybeString)) {
72
- expectType<typeof maybeString, NonEmptyString>('=');
73
-
74
- expect(maybeString.toUpperCase()).toBe('HELLO');
73
+ if (!isNonEmptyString(maybeString)) {
74
+ return;
75
75
  }
76
+
77
+ expectType<typeof maybeString, NonEmptyString>('=');
78
+
79
+ expect(maybeString.toUpperCase()).toBe('HELLO');
76
80
  });
77
81
 
78
82
  test('should work in filter operations', () => {
@@ -1,4 +1,4 @@
1
- import { type Primitive } from 'ts-type-forge';
1
+ import type { Primitive } from 'ts-type-forge';
2
2
  import { expectType } from '../expect-type.mjs';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { type RelaxedExclude } from 'ts-type-forge';
1
+ import type { RelaxedExclude } from 'ts-type-forge';
2
2
 
3
3
  /**
4
4
  * Type guard that checks if a value is `undefined`.
@@ -143,11 +143,13 @@ describe(isString, () => {
143
143
  test('should act as a type guard', () => {
144
144
  const value: unknown = 'test';
145
145
 
146
- if (isString(value)) {
147
- expectType<typeof value, string>('=');
148
-
149
- expect(value).toHaveLength(4);
146
+ if (!isString(value)) {
147
+ return;
150
148
  }
149
+
150
+ expectType<typeof value, string>('=');
151
+
152
+ expect(value).toHaveLength(4);
151
153
  });
152
154
  });
153
155
 
@@ -182,11 +184,13 @@ describe(isNumber, () => {
182
184
  test('should act as a type guard', () => {
183
185
  const value: unknown = 42;
184
186
 
185
- if (isNumber(value)) {
186
- expectType<typeof value, number>('=');
187
-
188
- expect(value + 1).toBe(43);
187
+ if (!isNumber(value)) {
188
+ return;
189
189
  }
190
+
191
+ expectType<typeof value, number>('=');
192
+
193
+ expect(value + 1).toBe(43);
190
194
  });
191
195
  });
192
196
 
@@ -212,11 +216,13 @@ describe(isBigint, () => {
212
216
  test('should act as a type guard', () => {
213
217
  const value: unknown = 123n;
214
218
 
215
- if (isBigint(value)) {
216
- expectType<typeof value, bigint>('=');
217
-
218
- expect(value + 1n).toBe(124n);
219
+ if (!isBigint(value)) {
220
+ return;
219
221
  }
222
+
223
+ expectType<typeof value, bigint>('=');
224
+
225
+ expect(value + 1n).toBe(124n);
220
226
  });
221
227
  });
222
228
 
@@ -243,11 +249,13 @@ describe(isBoolean, () => {
243
249
  test('should act as a type guard', () => {
244
250
  const value: unknown = true;
245
251
 
246
- if (isBoolean(value)) {
247
- expectType<typeof value, boolean>('=');
248
-
249
- assert.isTrue(value);
252
+ if (!isBoolean(value)) {
253
+ return;
250
254
  }
255
+
256
+ expectType<typeof value, boolean>('=');
257
+
258
+ assert.isTrue(value);
251
259
  });
252
260
  });
253
261
 
@@ -271,11 +279,13 @@ describe(isSymbol, () => {
271
279
  test('should act as a type guard', () => {
272
280
  const value: unknown = Symbol('test');
273
281
 
274
- if (isSymbol(value)) {
275
- expectType<typeof value, symbol>('=');
276
-
277
- expect(value.toString()).toContain('Symbol');
282
+ if (!isSymbol(value)) {
283
+ return;
278
284
  }
285
+
286
+ expectType<typeof value, symbol>('=');
287
+
288
+ expect(value.toString()).toContain('Symbol');
279
289
  });
280
290
  });
281
291
 
@@ -307,12 +317,14 @@ describe(isNotBoolean, () => {
307
317
  test('should act as a type guard', () => {
308
318
  const value: string | number | boolean = 'test';
309
319
 
310
- if (isNotBoolean(value)) {
311
- expectType<typeof value, string | number>('<=');
312
-
313
- // Should not have boolean methods
314
- assert.isTrue(typeof value === 'string' || typeof value === 'number');
320
+ if (!isNotBoolean(value)) {
321
+ return;
315
322
  }
323
+
324
+ expectType<typeof value, string | number>('<=');
325
+
326
+ // Should not have boolean methods
327
+ assert.isTrue(typeof value === 'string' || typeof value === 'number');
316
328
  });
317
329
  });
318
330
 
@@ -354,11 +366,13 @@ describe(isNotNumber, () => {
354
366
  test('should act as a type guard', () => {
355
367
  const value: string | number | boolean = 'test';
356
368
 
357
- if (isNotNumber(value)) {
358
- expectType<typeof value, string | boolean>('<=');
359
-
360
- assert.isTrue(typeof value === 'string' || typeof value === 'boolean');
369
+ if (!isNotNumber(value)) {
370
+ return;
361
371
  }
372
+
373
+ expectType<typeof value, string | boolean>('<=');
374
+
375
+ assert.isTrue(typeof value === 'string' || typeof value === 'boolean');
362
376
  });
363
377
  });
364
378
 
@@ -392,11 +406,13 @@ describe(isNotBigint, () => {
392
406
  test('should act as a type guard', () => {
393
407
  const value: number | bigint = 123;
394
408
 
395
- if (isNotBigint(value)) {
396
- expectType<typeof value, number>('<=');
397
-
398
- expectTypeOf(value).toBeNumber();
409
+ if (!isNotBigint(value)) {
410
+ return;
399
411
  }
412
+
413
+ expectType<typeof value, number>('<=');
414
+
415
+ expectTypeOf(value).toBeNumber();
400
416
  });
401
417
  });
402
418
 
@@ -434,11 +450,13 @@ describe(isNotString, () => {
434
450
  test('should act as a type guard', () => {
435
451
  const value: string | number | boolean = 42;
436
452
 
437
- if (isNotString(value)) {
438
- expectType<typeof value, number | boolean>('<=');
439
-
440
- assert.isTrue(typeof value === 'number' || typeof value === 'boolean');
453
+ if (!isNotString(value)) {
454
+ return;
441
455
  }
456
+
457
+ expectType<typeof value, number | boolean>('<=');
458
+
459
+ assert.isTrue(typeof value === 'number' || typeof value === 'boolean');
442
460
  });
443
461
  });
444
462
 
@@ -474,11 +492,13 @@ describe(isNotSymbol, () => {
474
492
  test('should act as a type guard', () => {
475
493
  const value: string | number | symbol = 'test';
476
494
 
477
- if (isNotSymbol(value)) {
478
- expectType<typeof value, string | number>('<=');
479
-
480
- assert.isTrue(typeof value === 'string' || typeof value === 'number');
495
+ if (!isNotSymbol(value)) {
496
+ return;
481
497
  }
498
+
499
+ expectType<typeof value, string | number>('<=');
500
+
501
+ assert.isTrue(typeof value === 'string' || typeof value === 'number');
482
502
  });
483
503
  });
484
504
 
@@ -510,12 +530,14 @@ describe(isNullish, () => {
510
530
  test('should act as a type guard', () => {
511
531
  const value: string | null | undefined = null;
512
532
 
513
- if (isNullish(value)) {
514
- expectType<typeof value, null | undefined>('<=');
515
-
516
- // Value is guaranteed to be null or undefined in this branch
517
- expect(true).toBe(true);
533
+ if (!isNullish(value)) {
534
+ return;
518
535
  }
536
+
537
+ expectType<typeof value, null | undefined>('<=');
538
+
539
+ // Value is guaranteed to be null or undefined in this branch
540
+ expect(true).toBe(true);
519
541
  });
520
542
 
521
543
  test('should handle edge cases', () => {
@@ -558,11 +580,13 @@ describe(isNonNullish, () => {
558
580
  test('should act as a type guard', () => {
559
581
  const value: string | null | undefined = 'test';
560
582
 
561
- if (isNonNullish(value)) {
562
- expectType<typeof value, string>('<=');
563
-
564
- expect(value).toHaveLength(4);
583
+ if (!isNonNullish(value)) {
584
+ return;
565
585
  }
586
+
587
+ expectType<typeof value, string>('<=');
588
+
589
+ expect(value).toHaveLength(4);
566
590
  });
567
591
 
568
592
  test('should work with array filtering', () => {
@@ -588,12 +612,14 @@ describe(isNonNullish, () => {
588
612
 
589
613
  const value: ComplexType = 42;
590
614
 
591
- if (isNonNullish(value)) {
592
- expectType<typeof value, string | number | boolean>('<=');
593
-
594
- // Value is guaranteed to be non-nullish in this branch
595
- expect(true).toBe(true);
615
+ if (!isNonNullish(value)) {
616
+ return;
596
617
  }
618
+
619
+ expectType<typeof value, string | number | boolean>('<=');
620
+
621
+ // Value is guaranteed to be non-nullish in this branch
622
+ expect(true).toBe(true);
597
623
  });
598
624
  });
599
625
 
@@ -601,11 +627,13 @@ describe('type guard behavior in complex scenarios', () => {
601
627
  test('should work with nested conditions', () => {
602
628
  const value: string | number | boolean | null | undefined = 'test';
603
629
 
604
- if (isNonNullish(value) && isNotBoolean(value) && isNotNumber(value)) {
605
- expectType<typeof value, string>('<=');
606
-
607
- expectTypeOf(value).toBeString();
630
+ if (!(isNonNullish(value) && isNotBoolean(value) && isNotNumber(value))) {
631
+ return;
608
632
  }
633
+
634
+ expectType<typeof value, string>('<=');
635
+
636
+ expectTypeOf(value).toBeString();
609
637
  });
610
638
 
611
639
  test('should work with array operations', () => {
@@ -1,9 +1,4 @@
1
- import {
2
- type NonZeroSafeInt,
3
- type PositiveSafeInt,
4
- type SafeUint,
5
- type WithSmallInt,
6
- } from 'ts-type-forge';
1
+ import type { NonZeroSafeInt, SafeUint, WithSmallInt } from 'ts-type-forge';
7
2
  import { SafeInt, asSafeInt } from '../number/index.mjs';
8
3
 
9
4
  /**
@@ -18,8 +13,9 @@ import { SafeInt, asSafeInt } from '../number/index.mjs';
18
13
  *
19
14
  * The function has two overloaded signatures:
20
15
  *
21
- * 1. For non-negative ranges: accepts SafeUint parameters and optional positive
22
- * step
16
+ * 1. For non-negative ranges: accepts SafeUint parameters and an optional
17
+ * non-zero step. Every value lies between `start` and `end`, so a negative
18
+ * step still yields only non-negative numbers
23
19
  * 2. For general ranges: accepts SafeInt parameters and optional non-zero step
24
20
  *
25
21
  * **Generator Behavior:**
@@ -75,7 +71,7 @@ export function range(
75
71
  start: WithSmallInt<SafeUint, MaxInt>,
76
72
  end: WithSmallInt<SafeUint, MaxInt>,
77
73
  // eslint-disable-next-line @typescript-eslint/unified-signatures
78
- step?: WithSmallInt<PositiveSafeInt, MaxInt>,
74
+ step?: WithSmallInt<NonZeroSafeInt, MaxInt>,
79
75
  ): Generator<SafeUint, void, unknown>;
80
76
 
81
77
  export function range(
@@ -1,3 +1,6 @@
1
+ import type { SafeInt, SafeUint } from 'ts-type-forge';
2
+ import { expectType } from '../expect-type.mjs';
3
+ import { asNonZeroSafeInt, asSafeUint } from '../number/index.mjs';
1
4
  import { range } from './range.mjs';
2
5
 
3
6
  describe(range, () => {
@@ -49,4 +52,30 @@ describe(range, () => {
49
52
  test('range(1, 12, 2)', () => {
50
53
  assert.deepStrictEqual(Array.from(range(1, 12, 2)), [1, 3, 5, 7, 9, 11]);
51
54
  });
55
+
56
+ // A negative step from non-negative bounds only counts down to `end`, so
57
+ // every value stays non-negative.
58
+ test('a negative step from non-negative bounds yields SafeUint', () => {
59
+ const xs = Array.from(range(asSafeUint(3), asSafeUint(0), -1));
60
+
61
+ expectType<(typeof xs)[number], SafeUint>('=');
62
+
63
+ assert.deepStrictEqual(xs, [3, 2, 1]);
64
+
65
+ const ys = Array.from(
66
+ range(asSafeUint(3), asSafeUint(0), asNonZeroSafeInt(-2)),
67
+ );
68
+
69
+ expectType<(typeof ys)[number], SafeUint>('=');
70
+
71
+ assert.deepStrictEqual(ys, [3, 1]);
72
+ });
73
+
74
+ test('a negative bound still yields SafeInt', () => {
75
+ const xs = Array.from(range(0, -2, -1));
76
+
77
+ expectType<(typeof xs)[number], SafeInt>('=');
78
+
79
+ assert.deepStrictEqual(xs, [0, -1]);
80
+ });
52
81
  });