type-plus 4.8.2 → 4.10.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 (734) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +19 -18
  3. package/cjs/ComposableTypes.d.ts +1 -0
  4. package/cjs/ComposableTypes.d.ts.map +1 -0
  5. package/cjs/JSONTypes.d.ts +1 -0
  6. package/cjs/JSONTypes.d.ts.map +1 -0
  7. package/cjs/JSONTypes.js.map +1 -1
  8. package/cjs/PrimitiveTypes.d.ts +1 -0
  9. package/cjs/PrimitiveTypes.d.ts.map +1 -0
  10. package/cjs/UnionKeys.d.ts +1 -0
  11. package/cjs/UnionKeys.d.ts.map +1 -0
  12. package/cjs/array/CommonPropKeys.d.ts +2 -1
  13. package/cjs/array/CommonPropKeys.d.ts.map +1 -0
  14. package/cjs/array/Concat.d.ts +1 -0
  15. package/cjs/array/Concat.d.ts.map +1 -0
  16. package/cjs/array/CreateTuple.d.ts +2 -1
  17. package/cjs/array/CreateTuple.d.ts.map +1 -0
  18. package/cjs/array/Filter.d.ts +1 -0
  19. package/cjs/array/Filter.d.ts.map +1 -0
  20. package/cjs/array/FindFirst.d.ts +1 -0
  21. package/cjs/array/FindFirst.d.ts.map +1 -0
  22. package/cjs/array/FindLast.d.ts +1 -0
  23. package/cjs/array/FindLast.d.ts.map +1 -0
  24. package/cjs/array/Head.d.ts +1 -0
  25. package/cjs/array/Head.d.ts.map +1 -0
  26. package/cjs/array/IntersectOfProps.d.ts +3 -2
  27. package/cjs/array/IntersectOfProps.d.ts.map +1 -0
  28. package/cjs/array/IsArray.d.ts +1 -0
  29. package/cjs/array/IsArray.d.ts.map +1 -0
  30. package/cjs/array/Last.d.ts +1 -0
  31. package/cjs/array/Last.d.ts.map +1 -0
  32. package/cjs/array/PadLeft.d.ts +4 -3
  33. package/cjs/array/PadLeft.d.ts.map +1 -0
  34. package/cjs/array/Reverse.d.ts +1 -0
  35. package/cjs/array/Reverse.d.ts.map +1 -0
  36. package/cjs/array/Some.d.ts +4 -3
  37. package/cjs/array/Some.d.ts.map +1 -0
  38. package/cjs/array/Tail.d.ts +2 -1
  39. package/cjs/array/Tail.d.ts.map +1 -0
  40. package/cjs/array/UnionOfProps.d.ts +3 -2
  41. package/cjs/array/UnionOfProps.d.ts.map +1 -0
  42. package/cjs/array/UnionOfValues.d.ts +1 -0
  43. package/cjs/array/UnionOfValues.d.ts.map +1 -0
  44. package/cjs/array/drop.d.ts +3 -2
  45. package/cjs/array/drop.d.ts.map +1 -0
  46. package/cjs/array/drop.js.map +1 -1
  47. package/cjs/array/index.d.ts +20 -19
  48. package/cjs/array/index.d.ts.map +1 -0
  49. package/cjs/array/index.js +3 -3
  50. package/cjs/array/index.js.map +1 -1
  51. package/cjs/array/literalArray.d.ts +2 -1
  52. package/cjs/array/literalArray.d.ts.map +1 -0
  53. package/cjs/array/reduceWhile.d.ts +1 -0
  54. package/cjs/array/reduceWhile.d.ts.map +1 -0
  55. package/cjs/assertion/assertType.d.ts +3 -2
  56. package/cjs/assertion/assertType.d.ts.map +1 -0
  57. package/cjs/assertion/assertType.js +3 -3
  58. package/cjs/assertion/assertType.js.map +1 -1
  59. package/cjs/assertion/index.d.ts +2 -1
  60. package/cjs/assertion/index.d.ts.map +1 -0
  61. package/cjs/assertion/index.js +1 -1
  62. package/cjs/assertion/index.js.map +1 -1
  63. package/cjs/class/AnyConstructor.d.ts +1 -0
  64. package/cjs/class/AnyConstructor.d.ts.map +1 -0
  65. package/cjs/class/index.d.ts +3 -2
  66. package/cjs/class/index.d.ts.map +1 -0
  67. package/cjs/class/index.js +1 -1
  68. package/cjs/class/index.js.map +1 -1
  69. package/cjs/class/isConstructor.d.ts +2 -1
  70. package/cjs/class/isConstructor.d.ts.map +1 -0
  71. package/cjs/function/AnyFunction.d.ts +1 -0
  72. package/cjs/function/AnyFunction.d.ts.map +1 -0
  73. package/cjs/function/index.d.ts +2 -1
  74. package/cjs/function/index.d.ts.map +1 -0
  75. package/cjs/functional/ChainFn.d.ts +1 -0
  76. package/cjs/functional/ChainFn.d.ts.map +1 -0
  77. package/cjs/functional/compose.d.ts +3 -2
  78. package/cjs/functional/compose.d.ts.map +1 -0
  79. package/cjs/functional/compose.js.map +1 -1
  80. package/cjs/functional/index.d.ts +3 -2
  81. package/cjs/functional/index.d.ts.map +1 -0
  82. package/cjs/functional/index.js +1 -1
  83. package/cjs/functional/index.js.map +1 -1
  84. package/cjs/index.d.ts +18 -17
  85. package/cjs/index.d.ts.map +1 -0
  86. package/cjs/index.js +14 -14
  87. package/cjs/index.js.map +1 -1
  88. package/cjs/math/Abs.d.ts +2 -1
  89. package/cjs/math/Abs.d.ts.map +1 -0
  90. package/cjs/math/Add.d.ts +7 -6
  91. package/cjs/math/Add.d.ts.map +1 -0
  92. package/cjs/math/Digit.d.ts +7 -4
  93. package/cjs/math/Digit.d.ts.map +1 -0
  94. package/cjs/math/GreaterThan.d.ts +10 -9
  95. package/cjs/math/GreaterThan.d.ts.map +1 -0
  96. package/cjs/math/IsPositive.d.ts +1 -0
  97. package/cjs/math/IsPositive.d.ts.map +1 -0
  98. package/cjs/math/IsWhole.d.ts +1 -0
  99. package/cjs/math/IsWhole.d.ts.map +1 -0
  100. package/cjs/math/Max.d.ts +4 -10
  101. package/cjs/math/Max.d.ts.map +1 -0
  102. package/cjs/math/Subtract.d.ts +7 -6
  103. package/cjs/math/Subtract.d.ts.map +1 -0
  104. package/cjs/math/index.d.ts +9 -8
  105. package/cjs/math/index.d.ts.map +1 -0
  106. package/cjs/nodejs/index.d.ts +2 -1
  107. package/cjs/nodejs/index.d.ts.map +1 -0
  108. package/cjs/nodejs/index.js +1 -1
  109. package/cjs/nodejs/index.js.map +1 -1
  110. package/cjs/nodejs/isNodeError.d.ts +1 -0
  111. package/cjs/nodejs/isNodeError.d.ts.map +1 -0
  112. package/cjs/nominal-types/Brand.d.ts +3 -2
  113. package/cjs/nominal-types/Brand.d.ts.map +1 -0
  114. package/cjs/nominal-types/Brand.js +2 -2
  115. package/cjs/nominal-types/Brand.js.map +1 -1
  116. package/cjs/nominal-types/Flavor.d.ts +3 -2
  117. package/cjs/nominal-types/Flavor.d.ts.map +1 -0
  118. package/cjs/nominal-types/Flavor.js +2 -2
  119. package/cjs/nominal-types/Flavor.js.map +1 -1
  120. package/cjs/nominal-types/index.d.ts +4 -3
  121. package/cjs/nominal-types/index.d.ts.map +1 -0
  122. package/cjs/nominal-types/index.js +3 -3
  123. package/cjs/nominal-types/index.js.map +1 -1
  124. package/cjs/nominal-types/nominalMatch.d.ts +3 -2
  125. package/cjs/nominal-types/nominalMatch.d.ts.map +1 -0
  126. package/cjs/nominal-types/nominalMatch.js +2 -2
  127. package/cjs/nominal-types/nominalMatch.js.map +1 -1
  128. package/cjs/nominal-types/types.d.ts +1 -0
  129. package/cjs/nominal-types/types.d.ts.map +1 -0
  130. package/cjs/object/ANotB.d.ts +5 -4
  131. package/cjs/object/ANotB.d.ts.map +1 -0
  132. package/cjs/object/AnyRecord.d.ts +1 -0
  133. package/cjs/object/AnyRecord.d.ts.map +1 -0
  134. package/cjs/object/ExcludePropType.d.ts +1 -0
  135. package/cjs/object/ExcludePropType.d.ts.map +1 -0
  136. package/cjs/object/IsDisjoint.d.ts +4 -3
  137. package/cjs/object/IsDisjoint.d.ts.map +1 -0
  138. package/cjs/object/IsRecord.d.ts +1 -0
  139. package/cjs/object/IsRecord.d.ts.map +1 -0
  140. package/cjs/object/KeyTypes.d.ts +1 -0
  141. package/cjs/object/KeyTypes.d.ts.map +1 -0
  142. package/cjs/object/KeyofOptional.d.ts +1 -0
  143. package/cjs/object/KeyofOptional.d.ts.map +1 -0
  144. package/cjs/object/KeysWithDiffType.d.ts +4 -3
  145. package/cjs/object/KeysWithDiffType.d.ts.map +1 -0
  146. package/cjs/object/KnownKeys.d.ts +2 -1
  147. package/cjs/object/KnownKeys.d.ts.map +1 -0
  148. package/cjs/object/OptionalKeys.d.ts +2 -1
  149. package/cjs/object/OptionalKeys.d.ts.map +1 -0
  150. package/cjs/object/Partial.d.ts +4 -3
  151. package/cjs/object/Partial.d.ts.map +1 -0
  152. package/cjs/object/RecursiveIntersect.d.ts +2 -1
  153. package/cjs/object/RecursiveIntersect.d.ts.map +1 -0
  154. package/cjs/object/RecursivePartial.d.ts +2 -1
  155. package/cjs/object/RecursivePartial.d.ts.map +1 -0
  156. package/cjs/object/RecursiveRequired.d.ts +2 -1
  157. package/cjs/object/RecursiveRequired.d.ts.map +1 -0
  158. package/cjs/object/Required.d.ts +1 -0
  159. package/cjs/object/Required.d.ts.map +1 -0
  160. package/cjs/object/RequiredKeys.d.ts +3 -2
  161. package/cjs/object/RequiredKeys.d.ts.map +1 -0
  162. package/cjs/object/SpreadRecord.d.ts +2 -1
  163. package/cjs/object/SpreadRecord.d.ts.map +1 -0
  164. package/cjs/object/ValueOf.d.ts +1 -0
  165. package/cjs/object/ValueOf.d.ts.map +1 -0
  166. package/cjs/object/everyKey.d.ts +2 -1
  167. package/cjs/object/everyKey.d.ts.map +1 -0
  168. package/cjs/object/facade.d.ts +2 -1
  169. package/cjs/object/facade.d.ts.map +1 -0
  170. package/cjs/object/filterKey.d.ts +2 -1
  171. package/cjs/object/filterKey.d.ts.map +1 -0
  172. package/cjs/object/findKey.d.ts +2 -1
  173. package/cjs/object/findKey.d.ts.map +1 -0
  174. package/cjs/object/forEachKey.d.ts +2 -1
  175. package/cjs/object/forEachKey.d.ts.map +1 -0
  176. package/cjs/object/getField.d.ts +2 -1
  177. package/cjs/object/getField.d.ts.map +1 -0
  178. package/cjs/object/hasKey.d.ts +2 -1
  179. package/cjs/object/hasKey.d.ts.map +1 -0
  180. package/cjs/object/hasProperty.d.ts +2 -1
  181. package/cjs/object/hasProperty.d.ts.map +1 -0
  182. package/cjs/object/index.d.ts +37 -36
  183. package/cjs/object/index.d.ts.map +1 -0
  184. package/cjs/object/index.js +18 -18
  185. package/cjs/object/index.js.map +1 -1
  186. package/cjs/object/mapKey.d.ts +2 -1
  187. package/cjs/object/mapKey.d.ts.map +1 -0
  188. package/cjs/object/mapProperties.d.ts +3 -2
  189. package/cjs/object/mapProperties.d.ts.map +1 -0
  190. package/cjs/object/mapProperties.js +2 -2
  191. package/cjs/object/mapProperties.js.map +1 -1
  192. package/cjs/object/omit.d.ts +4 -3
  193. package/cjs/object/omit.d.ts.map +1 -0
  194. package/cjs/object/omit.js +2 -2
  195. package/cjs/object/omit.js.map +1 -1
  196. package/cjs/object/pick.d.ts +3 -2
  197. package/cjs/object/pick.d.ts.map +1 -0
  198. package/cjs/object/pick.js +2 -2
  199. package/cjs/object/pick.js.map +1 -1
  200. package/cjs/object/record.d.ts +3 -2
  201. package/cjs/object/record.d.ts.map +1 -0
  202. package/cjs/object/record.js +1 -1
  203. package/cjs/object/record.js.map +1 -1
  204. package/cjs/object/reduceKey.d.ts +2 -1
  205. package/cjs/object/reduceKey.d.ts.map +1 -0
  206. package/cjs/object/replaceProperty.d.ts +2 -1
  207. package/cjs/object/replaceProperty.d.ts.map +1 -0
  208. package/cjs/object/someKey.d.ts +2 -1
  209. package/cjs/object/someKey.d.ts.map +1 -0
  210. package/cjs/object/split.d.ts +3 -2
  211. package/cjs/object/split.d.ts.map +1 -0
  212. package/cjs/object/split.js +3 -3
  213. package/cjs/object/split.js.map +1 -1
  214. package/cjs/object/typeOverrideIncompatible.d.ts +2 -1
  215. package/cjs/object/typeOverrideIncompatible.d.ts.map +1 -0
  216. package/cjs/predicates/CanAssign.d.ts +3 -2
  217. package/cjs/predicates/CanAssign.d.ts.map +1 -0
  218. package/cjs/predicates/Equal.d.ts +1 -0
  219. package/cjs/predicates/Equal.d.ts.map +1 -0
  220. package/cjs/predicates/Extends.d.ts +1 -0
  221. package/cjs/predicates/Extends.d.ts.map +1 -0
  222. package/cjs/predicates/If.d.ts +1 -0
  223. package/cjs/predicates/If.d.ts.map +1 -0
  224. package/cjs/predicates/IsEmptyObject.d.ts +1 -0
  225. package/cjs/predicates/IsEmptyObject.d.ts.map +1 -0
  226. package/cjs/predicates/index.d.ts +9 -8
  227. package/cjs/predicates/index.d.ts.map +1 -0
  228. package/cjs/predicates/index.js +2 -2
  229. package/cjs/predicates/index.js.map +1 -1
  230. package/cjs/predicates/isType.d.ts +3 -2
  231. package/cjs/predicates/isType.d.ts.map +1 -0
  232. package/cjs/predicates/isType.js +2 -2
  233. package/cjs/predicates/isType.js.map +1 -1
  234. package/cjs/predicates/logical.d.ts +1 -0
  235. package/cjs/predicates/logical.d.ts.map +1 -0
  236. package/cjs/promise/PromiseValue.d.ts +1 -0
  237. package/cjs/promise/PromiseValue.d.ts.map +1 -0
  238. package/cjs/promise/PromiseValueMerge.d.ts +2 -1
  239. package/cjs/promise/PromiseValueMerge.d.ts.map +1 -0
  240. package/cjs/promise/index.d.ts +5 -4
  241. package/cjs/promise/index.d.ts.map +1 -0
  242. package/cjs/promise/index.js +2 -2
  243. package/cjs/promise/index.js.map +1 -1
  244. package/cjs/promise/isPromise.d.ts +1 -0
  245. package/cjs/promise/isPromise.d.ts.map +1 -0
  246. package/cjs/promise/mapSeries.d.ts +1 -0
  247. package/cjs/promise/mapSeries.d.ts.map +1 -0
  248. package/cjs/testing/index.d.ts +2 -1
  249. package/cjs/testing/index.d.ts.map +1 -0
  250. package/cjs/testing/index.js +1 -1
  251. package/cjs/testing/index.js.map +1 -1
  252. package/cjs/testing/stub.d.ts +3 -2
  253. package/cjs/testing/stub.d.ts.map +1 -0
  254. package/cjs/utils/NonNull.d.ts +1 -0
  255. package/cjs/utils/NonNull.d.ts.map +1 -0
  256. package/cjs/utils/NonUndefined.d.ts +1 -0
  257. package/cjs/utils/NonUndefined.d.ts.map +1 -0
  258. package/cjs/utils/Widen.d.ts +1 -0
  259. package/cjs/utils/Widen.d.ts.map +1 -0
  260. package/cjs/utils/as.d.ts +1 -0
  261. package/cjs/utils/as.d.ts.map +1 -0
  262. package/cjs/utils/index.d.ts +5 -4
  263. package/cjs/utils/index.d.ts.map +1 -0
  264. package/cjs/utils/index.js +1 -1
  265. package/cjs/utils/index.js.map +1 -1
  266. package/esm/ComposableTypes.d.ts +3 -0
  267. package/esm/ComposableTypes.d.ts.map +1 -0
  268. package/esm/JSONTypes.d.ts +12 -0
  269. package/esm/JSONTypes.d.ts.map +1 -0
  270. package/esm/JSONTypes.js.map +1 -1
  271. package/esm/PrimitiveTypes.d.ts +2 -0
  272. package/esm/PrimitiveTypes.d.ts.map +1 -0
  273. package/esm/UnionKeys.d.ts +2 -0
  274. package/esm/UnionKeys.d.ts.map +1 -0
  275. package/esm/array/CommonPropKeys.d.ts +4 -0
  276. package/esm/array/CommonPropKeys.d.ts.map +1 -0
  277. package/esm/array/Concat.d.ts +2 -0
  278. package/esm/array/Concat.d.ts.map +1 -0
  279. package/esm/array/CreateTuple.d.ts +3 -0
  280. package/esm/array/CreateTuple.d.ts.map +1 -0
  281. package/esm/array/Filter.d.ts +3 -0
  282. package/esm/array/Filter.d.ts.map +1 -0
  283. package/esm/array/FindFirst.d.ts +3 -0
  284. package/esm/array/FindFirst.d.ts.map +1 -0
  285. package/esm/array/FindLast.d.ts +2 -0
  286. package/esm/array/FindLast.d.ts.map +1 -0
  287. package/esm/array/Head.d.ts +2 -0
  288. package/esm/array/Head.d.ts.map +1 -0
  289. package/esm/array/IntersectOfProps.d.ts +5 -0
  290. package/esm/array/IntersectOfProps.d.ts.map +1 -0
  291. package/esm/array/IsArray.d.ts +2 -0
  292. package/esm/array/IsArray.d.ts.map +1 -0
  293. package/esm/array/Last.d.ts +2 -0
  294. package/esm/array/Last.d.ts.map +1 -0
  295. package/esm/array/PadLeft.d.ts +5 -0
  296. package/esm/array/PadLeft.d.ts.map +1 -0
  297. package/esm/array/Reverse.d.ts +2 -0
  298. package/esm/array/Reverse.d.ts.map +1 -0
  299. package/esm/array/Some.d.ts +8 -0
  300. package/esm/array/Some.d.ts.map +1 -0
  301. package/esm/array/Tail.d.ts +3 -0
  302. package/esm/array/Tail.d.ts.map +1 -0
  303. package/esm/array/UnionOfProps.d.ts +5 -0
  304. package/esm/array/UnionOfProps.d.ts.map +1 -0
  305. package/esm/array/UnionOfValues.d.ts +3 -0
  306. package/esm/array/UnionOfValues.d.ts.map +1 -0
  307. package/esm/array/drop.d.ts +13 -0
  308. package/esm/array/drop.d.ts.map +1 -0
  309. package/esm/array/drop.js.map +1 -1
  310. package/esm/array/index.d.ts +20 -0
  311. package/esm/array/index.d.ts.map +1 -0
  312. package/esm/array/index.js +3 -3
  313. package/esm/array/index.js.map +1 -1
  314. package/esm/array/literalArray.d.ts +3 -0
  315. package/esm/array/literalArray.d.ts.map +1 -0
  316. package/esm/array/reduceWhile.d.ts +2 -0
  317. package/esm/array/reduceWhile.d.ts.map +1 -0
  318. package/esm/assertion/assertType.d.ts +29 -0
  319. package/esm/assertion/assertType.d.ts.map +1 -0
  320. package/esm/assertion/assertType.js +1 -1
  321. package/esm/assertion/assertType.js.map +1 -1
  322. package/esm/assertion/index.d.ts +2 -0
  323. package/esm/assertion/index.d.ts.map +1 -0
  324. package/esm/assertion/index.js +1 -1
  325. package/esm/assertion/index.js.map +1 -1
  326. package/esm/class/AnyConstructor.d.ts +2 -0
  327. package/esm/class/AnyConstructor.d.ts.map +1 -0
  328. package/esm/class/index.d.ts +3 -0
  329. package/esm/class/index.d.ts.map +1 -0
  330. package/esm/class/index.js +1 -1
  331. package/esm/class/index.js.map +1 -1
  332. package/esm/class/isConstructor.d.ts +3 -0
  333. package/esm/class/isConstructor.d.ts.map +1 -0
  334. package/esm/function/AnyFunction.d.ts +2 -0
  335. package/esm/function/AnyFunction.d.ts.map +1 -0
  336. package/esm/function/index.d.ts +2 -0
  337. package/esm/function/index.d.ts.map +1 -0
  338. package/esm/functional/ChainFn.d.ts +3 -0
  339. package/esm/functional/ChainFn.d.ts.map +1 -0
  340. package/esm/functional/compose.d.ts +4 -0
  341. package/esm/functional/compose.d.ts.map +1 -0
  342. package/esm/functional/compose.js.map +1 -1
  343. package/esm/functional/index.d.ts +3 -0
  344. package/esm/functional/index.d.ts.map +1 -0
  345. package/esm/functional/index.js +1 -1
  346. package/esm/functional/index.js.map +1 -1
  347. package/esm/index.d.ts +19 -0
  348. package/esm/index.d.ts.map +1 -0
  349. package/esm/index.js +14 -14
  350. package/esm/index.js.map +1 -1
  351. package/esm/math/Abs.d.ts +3 -0
  352. package/esm/math/Abs.d.ts.map +1 -0
  353. package/esm/math/Add.d.ts +16 -0
  354. package/esm/math/Add.d.ts.map +1 -0
  355. package/esm/math/Digit.d.ts +97 -0
  356. package/esm/math/Digit.d.ts.map +1 -0
  357. package/esm/math/GreaterThan.d.ts +12 -0
  358. package/esm/math/GreaterThan.d.ts.map +1 -0
  359. package/esm/math/IsPositive.d.ts +2 -0
  360. package/esm/math/IsPositive.d.ts.map +1 -0
  361. package/esm/math/IsWhole.d.ts +2 -0
  362. package/esm/math/IsWhole.d.ts.map +1 -0
  363. package/esm/math/Max.d.ts +4 -0
  364. package/esm/math/Max.d.ts.map +1 -0
  365. package/esm/math/Subtract.d.ts +13 -0
  366. package/esm/math/Subtract.d.ts.map +1 -0
  367. package/esm/math/index.d.ts +9 -0
  368. package/esm/math/index.d.ts.map +1 -0
  369. package/esm/nodejs/index.d.ts +2 -0
  370. package/esm/nodejs/index.d.ts.map +1 -0
  371. package/esm/nodejs/index.js +1 -1
  372. package/esm/nodejs/index.js.map +1 -1
  373. package/esm/nodejs/isNodeError.d.ts +26 -0
  374. package/esm/nodejs/isNodeError.d.ts.map +1 -0
  375. package/esm/nominal-types/Brand.d.ts +11 -0
  376. package/esm/nominal-types/Brand.d.ts.map +1 -0
  377. package/esm/nominal-types/Brand.js +1 -1
  378. package/esm/nominal-types/Brand.js.map +1 -1
  379. package/esm/nominal-types/Flavor.d.ts +8 -0
  380. package/esm/nominal-types/Flavor.d.ts.map +1 -0
  381. package/esm/nominal-types/Flavor.js +1 -1
  382. package/esm/nominal-types/Flavor.js.map +1 -1
  383. package/esm/nominal-types/index.d.ts +4 -0
  384. package/esm/nominal-types/index.d.ts.map +1 -0
  385. package/esm/nominal-types/index.js +3 -3
  386. package/esm/nominal-types/index.js.map +1 -1
  387. package/esm/nominal-types/nominalMatch.d.ts +5 -0
  388. package/esm/nominal-types/nominalMatch.d.ts.map +1 -0
  389. package/esm/nominal-types/nominalMatch.js +1 -1
  390. package/esm/nominal-types/nominalMatch.js.map +1 -1
  391. package/esm/nominal-types/types.d.ts +3 -0
  392. package/esm/nominal-types/types.d.ts.map +1 -0
  393. package/esm/object/ANotB.d.ts +14 -0
  394. package/esm/object/ANotB.d.ts.map +1 -0
  395. package/esm/object/AnyRecord.d.ts +2 -0
  396. package/esm/object/AnyRecord.d.ts.map +1 -0
  397. package/esm/object/ExcludePropType.d.ts +4 -0
  398. package/esm/object/ExcludePropType.d.ts.map +1 -0
  399. package/esm/object/IsDisjoint.d.ts +5 -0
  400. package/esm/object/IsDisjoint.d.ts.map +1 -0
  401. package/esm/object/IsRecord.d.ts +2 -0
  402. package/esm/object/IsRecord.d.ts.map +1 -0
  403. package/esm/object/KeyTypes.d.ts +2 -0
  404. package/esm/object/KeyTypes.d.ts.map +1 -0
  405. package/esm/object/KeyofOptional.d.ts +3 -0
  406. package/esm/object/KeyofOptional.d.ts.map +1 -0
  407. package/esm/object/KeysWithDiffType.d.ts +7 -0
  408. package/esm/object/KeysWithDiffType.d.ts.map +1 -0
  409. package/esm/object/KnownKeys.d.ts +7 -0
  410. package/esm/object/KnownKeys.d.ts.map +1 -0
  411. package/esm/object/OptionalKeys.d.ts +8 -0
  412. package/esm/object/OptionalKeys.d.ts.map +1 -0
  413. package/esm/object/Partial.d.ts +7 -0
  414. package/esm/object/Partial.d.ts.map +1 -0
  415. package/esm/object/RecursiveIntersect.d.ts +5 -0
  416. package/esm/object/RecursiveIntersect.d.ts.map +1 -0
  417. package/esm/object/RecursivePartial.d.ts +5 -0
  418. package/esm/object/RecursivePartial.d.ts.map +1 -0
  419. package/esm/object/RecursiveRequired.d.ts +5 -0
  420. package/esm/object/RecursiveRequired.d.ts.map +1 -0
  421. package/esm/object/Required.d.ts +3 -0
  422. package/esm/object/Required.d.ts.map +1 -0
  423. package/esm/object/RequiredKeys.d.ts +7 -0
  424. package/esm/object/RequiredKeys.d.ts.map +1 -0
  425. package/esm/object/SpreadRecord.d.ts +3 -0
  426. package/esm/object/SpreadRecord.d.ts.map +1 -0
  427. package/esm/object/ValueOf.d.ts +2 -0
  428. package/esm/object/ValueOf.d.ts.map +1 -0
  429. package/esm/object/everyKey.d.ts +3 -0
  430. package/esm/object/everyKey.d.ts.map +1 -0
  431. package/esm/object/facade.d.ts +14 -0
  432. package/esm/object/facade.d.ts.map +1 -0
  433. package/esm/object/filterKey.d.ts +3 -0
  434. package/esm/object/filterKey.d.ts.map +1 -0
  435. package/esm/object/findKey.d.ts +3 -0
  436. package/esm/object/findKey.d.ts.map +1 -0
  437. package/esm/object/forEachKey.d.ts +3 -0
  438. package/esm/object/forEachKey.d.ts.map +1 -0
  439. package/esm/object/getField.d.ts +4 -0
  440. package/esm/object/getField.d.ts.map +1 -0
  441. package/esm/object/hasKey.d.ts +4 -0
  442. package/esm/object/hasKey.d.ts.map +1 -0
  443. package/esm/object/hasProperty.d.ts +3 -0
  444. package/esm/object/hasProperty.d.ts.map +1 -0
  445. package/esm/object/index.d.ts +37 -0
  446. package/esm/object/index.d.ts.map +1 -0
  447. package/esm/object/index.js +18 -18
  448. package/esm/object/index.js.map +1 -1
  449. package/esm/object/mapKey.d.ts +3 -0
  450. package/esm/object/mapKey.d.ts.map +1 -0
  451. package/esm/object/mapProperties.d.ts +6 -0
  452. package/esm/object/mapProperties.d.ts.map +1 -0
  453. package/esm/object/mapProperties.js +1 -1
  454. package/esm/object/mapProperties.js.map +1 -1
  455. package/esm/object/omit.d.ts +18 -0
  456. package/esm/object/omit.d.ts.map +1 -0
  457. package/esm/object/omit.js +1 -1
  458. package/esm/object/omit.js.map +1 -1
  459. package/esm/object/pick.d.ts +21 -0
  460. package/esm/object/pick.d.ts.map +1 -0
  461. package/esm/object/pick.js +1 -1
  462. package/esm/object/pick.js.map +1 -1
  463. package/esm/object/record.d.ts +4 -0
  464. package/esm/object/record.d.ts.map +1 -0
  465. package/esm/object/record.js +1 -1
  466. package/esm/object/record.js.map +1 -1
  467. package/esm/object/reduceKey.d.ts +4 -0
  468. package/esm/object/reduceKey.d.ts.map +1 -0
  469. package/esm/object/replaceProperty.d.ts +6 -0
  470. package/esm/object/replaceProperty.d.ts.map +1 -0
  471. package/esm/object/someKey.d.ts +3 -0
  472. package/esm/object/someKey.d.ts.map +1 -0
  473. package/esm/object/split.d.ts +82 -0
  474. package/esm/object/split.d.ts.map +1 -0
  475. package/esm/object/split.js +1 -1
  476. package/esm/object/split.js.map +1 -1
  477. package/esm/object/typeOverrideIncompatible.d.ts +3 -0
  478. package/esm/object/typeOverrideIncompatible.d.ts.map +1 -0
  479. package/esm/predicates/CanAssign.d.ts +7 -0
  480. package/esm/predicates/CanAssign.d.ts.map +1 -0
  481. package/esm/predicates/Equal.d.ts +5 -0
  482. package/esm/predicates/Equal.d.ts.map +1 -0
  483. package/esm/predicates/Extends.d.ts +5 -0
  484. package/esm/predicates/Extends.d.ts.map +1 -0
  485. package/esm/predicates/If.d.ts +2 -0
  486. package/esm/predicates/If.d.ts.map +1 -0
  487. package/esm/predicates/IsEmptyObject.d.ts +2 -0
  488. package/esm/predicates/IsEmptyObject.d.ts.map +1 -0
  489. package/esm/predicates/index.d.ts +12 -0
  490. package/esm/predicates/index.d.ts.map +1 -0
  491. package/esm/predicates/index.js +2 -2
  492. package/esm/predicates/index.js.map +1 -1
  493. package/esm/predicates/isType.d.ts +11 -0
  494. package/esm/predicates/isType.d.ts.map +1 -0
  495. package/esm/predicates/isType.js +1 -1
  496. package/esm/predicates/isType.js.map +1 -1
  497. package/esm/predicates/logical.d.ts +5 -0
  498. package/esm/predicates/logical.d.ts.map +1 -0
  499. package/esm/promise/PromiseValue.d.ts +2 -0
  500. package/esm/promise/PromiseValue.d.ts.map +1 -0
  501. package/esm/promise/PromiseValueMerge.d.ts +3 -0
  502. package/esm/promise/PromiseValueMerge.d.ts.map +1 -0
  503. package/esm/promise/index.d.ts +5 -0
  504. package/esm/promise/index.d.ts.map +1 -0
  505. package/esm/promise/index.js +2 -2
  506. package/esm/promise/index.js.map +1 -1
  507. package/esm/promise/isPromise.d.ts +2 -0
  508. package/esm/promise/isPromise.d.ts.map +1 -0
  509. package/esm/promise/mapSeries.d.ts +2 -0
  510. package/esm/promise/mapSeries.d.ts.map +1 -0
  511. package/esm/testing/index.d.ts +2 -0
  512. package/esm/testing/index.d.ts.map +1 -0
  513. package/esm/testing/index.js +1 -1
  514. package/esm/testing/index.js.map +1 -1
  515. package/esm/testing/stub.d.ts +10 -0
  516. package/esm/testing/stub.d.ts.map +1 -0
  517. package/esm/utils/NonNull.d.ts +2 -0
  518. package/esm/utils/NonNull.d.ts.map +1 -0
  519. package/esm/utils/NonUndefined.d.ts +2 -0
  520. package/esm/utils/NonUndefined.d.ts.map +1 -0
  521. package/esm/utils/Widen.d.ts +2 -0
  522. package/esm/utils/Widen.d.ts.map +1 -0
  523. package/esm/utils/as.d.ts +7 -0
  524. package/esm/utils/as.d.ts.map +1 -0
  525. package/esm/utils/index.d.ts +5 -0
  526. package/esm/utils/index.d.ts.map +1 -0
  527. package/esm/utils/index.js +1 -1
  528. package/esm/utils/index.js.map +1 -1
  529. package/package.json +47 -42
  530. package/ts/JSONTypes.ts +17 -18
  531. package/ts/array/CommonPropKeys.ts +18 -18
  532. package/ts/array/CreateTuple.ts +1 -1
  533. package/ts/array/IntersectOfProps.ts +20 -20
  534. package/ts/array/PadLeft.ts +3 -3
  535. package/ts/array/Some.ts +3 -3
  536. package/ts/array/Tail.ts +1 -1
  537. package/ts/array/UnionOfProps.ts +18 -18
  538. package/ts/array/drop.ts +3 -3
  539. package/ts/array/index.ts +19 -19
  540. package/ts/array/literalArray.ts +1 -1
  541. package/ts/assertion/assertType.ts +105 -105
  542. package/ts/assertion/index.ts +1 -1
  543. package/ts/binary/_binary.ts +1 -1
  544. package/ts/binary/index.ts +2 -2
  545. package/ts/class/index.ts +2 -2
  546. package/ts/class/isConstructor.ts +1 -1
  547. package/ts/function/index.ts +1 -1
  548. package/ts/functional/Maybe.ts +19 -19
  549. package/ts/functional/compose.ts +4 -3
  550. package/ts/functional/index.ts +3 -3
  551. package/ts/index.ts +19 -19
  552. package/ts/math/Abs.ts +1 -1
  553. package/ts/math/Add.ts +6 -6
  554. package/ts/math/Digit.ts +6 -4
  555. package/ts/math/GreaterThan.ts +16 -17
  556. package/ts/math/Max.ts +6 -30
  557. package/ts/math/Subtract.ts +6 -6
  558. package/ts/math/index.ts +8 -8
  559. package/ts/nodejs/index.ts +1 -1
  560. package/ts/nominal-types/Brand.ts +2 -2
  561. package/ts/nominal-types/Flavor.ts +32 -32
  562. package/ts/nominal-types/index.ts +3 -3
  563. package/ts/nominal-types/nominalMatch.ts +3 -3
  564. package/ts/object/ANotB.ts +21 -21
  565. package/ts/object/IsDisjoint.ts +12 -12
  566. package/ts/object/KeysWithDiffType.ts +3 -3
  567. package/ts/object/KnownKeys.ts +1 -1
  568. package/ts/object/OptionalKeys.ts +1 -1
  569. package/ts/object/Partial.ts +3 -3
  570. package/ts/object/RecursiveIntersect.ts +1 -1
  571. package/ts/object/RecursivePartial.ts +1 -1
  572. package/ts/object/RecursiveRequired.ts +1 -1
  573. package/ts/object/RequiredKeys.ts +2 -2
  574. package/ts/object/SpreadRecord.ts +6 -6
  575. package/ts/object/everyKey.ts +1 -1
  576. package/ts/object/facade.ts +39 -39
  577. package/ts/object/filterKey.ts +1 -1
  578. package/ts/object/findKey.ts +1 -1
  579. package/ts/object/forEachKey.ts +1 -1
  580. package/ts/object/getField.ts +1 -1
  581. package/ts/object/hasKey.ts +7 -7
  582. package/ts/object/hasProperty.ts +1 -1
  583. package/ts/object/index.ts +36 -36
  584. package/ts/object/mapKey.ts +1 -1
  585. package/ts/object/mapProperties.ts +3 -3
  586. package/ts/object/omit.ts +36 -36
  587. package/ts/object/pick.ts +35 -35
  588. package/ts/object/record.ts +5 -4
  589. package/ts/object/reduceKey.ts +1 -1
  590. package/ts/object/replaceProperty.ts +1 -1
  591. package/ts/object/someKey.ts +1 -1
  592. package/ts/object/split.ts +5 -4
  593. package/ts/object/typeOverrideIncompatible.ts +10 -10
  594. package/ts/predicates/CanAssign.ts +2 -2
  595. package/ts/predicates/index.ts +8 -8
  596. package/ts/predicates/isType.ts +30 -30
  597. package/ts/promise/PromiseValueMerge.ts +1 -1
  598. package/ts/promise/index.ts +4 -4
  599. package/ts/testing/index.ts +1 -1
  600. package/ts/testing/stub.ts +2 -2
  601. package/ts/utils/index.ts +4 -4
  602. package/ts/ComposableTypes.spec.ts +0 -29
  603. package/ts/JSONTypes.spec.ts +0 -43
  604. package/ts/array/CommonPropKeys.spec.ts +0 -20
  605. package/ts/array/Concat.spec.ts +0 -21
  606. package/ts/array/CreateTuple.spec.ts +0 -46
  607. package/ts/array/DropFirst.spec.ts +0 -21
  608. package/ts/array/DropLast.spec.ts +0 -21
  609. package/ts/array/DropMatch.spec.ts +0 -234
  610. package/ts/array/Filter.spec.ts +0 -107
  611. package/ts/array/FindFirst.spec.ts +0 -27
  612. package/ts/array/FindLast.spec.ts +0 -27
  613. package/ts/array/Head.spec.ts +0 -21
  614. package/ts/array/IntersectOfProps.spec.ts +0 -14
  615. package/ts/array/Last.spec.ts +0 -32
  616. package/ts/array/PadLeft.spec.ts +0 -26
  617. package/ts/array/Reverse.spec.ts +0 -17
  618. package/ts/array/Some.spec.ts +0 -79
  619. package/ts/array/Tail.spec.ts +0 -32
  620. package/ts/array/UnionOfProps.spec.ts +0 -14
  621. package/ts/array/UnionOfValues.spec.ts +0 -11
  622. package/ts/array/literalArray.spec.ts +0 -7
  623. package/ts/array/reduceWhile.spec.ts +0 -27
  624. package/ts/assertion/assertType.spec.ts +0 -507
  625. package/ts/binary/index.spec.ts +0 -28
  626. package/ts/class/AnyConstructor.spec.ts +0 -13
  627. package/ts/class/isConstructor.spec.ts +0 -35
  628. package/ts/function/AnyFunction.spec.ts +0 -21
  629. package/ts/functional/ChainFn.spec.ts +0 -7
  630. package/ts/functional/Maybe.spec.ts +0 -42
  631. package/ts/functional/compose.spec.ts +0 -32
  632. package/ts/index.spec.ts +0 -7
  633. package/ts/math/Abs.spec.ts +0 -14
  634. package/ts/math/Add.spec.ts +0 -82
  635. package/ts/math/Digit.spec.ts +0 -184
  636. package/ts/math/GreaterThan.spec.ts +0 -43
  637. package/ts/math/IsPositive.spec.ts +0 -15
  638. package/ts/math/IsWhole.spec.ts +0 -19
  639. package/ts/math/Max.spec.ts +0 -35
  640. package/ts/math/Subtract.spec.ts +0 -40
  641. package/ts/nodejs/isNodeError.spec.ts +0 -11
  642. package/ts/nominal-types/Brand.spec.ts +0 -43
  643. package/ts/nominal-types/Flavor.spec.ts +0 -51
  644. package/ts/nominal-types/nominalMatch.spec.ts +0 -54
  645. package/ts/object/ANotB.spec.ts +0 -78
  646. package/ts/object/ExcludePropType.spec.ts +0 -13
  647. package/ts/object/IsDisjoint.spec.ts +0 -25
  648. package/ts/object/IsRecord.spec.ts +0 -22
  649. package/ts/object/KeyTypes.spec.ts +0 -9
  650. package/ts/object/KeyofOptional.spec.ts +0 -8
  651. package/ts/object/KeysWithDiffType.spec.ts +0 -21
  652. package/ts/object/KnownKeys.spec.ts +0 -39
  653. package/ts/object/OptionalKeys.spec.ts +0 -23
  654. package/ts/object/Partial.spec.ts +0 -49
  655. package/ts/object/RecursiveIntersect.spec.ts +0 -39
  656. package/ts/object/RecursiveRequired.spec.ts +0 -57
  657. package/ts/object/Required.spec.ts +0 -29
  658. package/ts/object/RequiredKeys.spec.ts +0 -24
  659. package/ts/object/SpreadRecord.spec.ts +0 -14
  660. package/ts/object/ValueOf.spec.ts +0 -36
  661. package/ts/object/everyKey.spec.ts +0 -11
  662. package/ts/object/facade.spec.ts +0 -22
  663. package/ts/object/filterKey.spec.ts +0 -8
  664. package/ts/object/findKey.spec.ts +0 -8
  665. package/ts/object/forEachKey.spec.ts +0 -9
  666. package/ts/object/getField.spec.ts +0 -21
  667. package/ts/object/hasKey.spec.ts +0 -29
  668. package/ts/object/hasProperty.spec.ts +0 -15
  669. package/ts/object/mapKey.spec.ts +0 -8
  670. package/ts/object/mapProperties.spec.ts +0 -27
  671. package/ts/object/omit.spec.ts +0 -104
  672. package/ts/object/pick.spec.ts +0 -66
  673. package/ts/object/record.spec.ts +0 -54
  674. package/ts/object/reduceKey.spec.ts +0 -18
  675. package/ts/object/replaceProperty.spec.ts +0 -16
  676. package/ts/object/run.ts +0 -0
  677. package/ts/object/someKey.spec.ts +0 -6
  678. package/ts/object/split.spec.ts +0 -119
  679. package/ts/object/typeOverrideIncompatible.spec.ts +0 -24
  680. package/ts/predicates/CanAssign.spec.ts +0 -57
  681. package/ts/predicates/Equal.spec.ts +0 -71
  682. package/ts/predicates/If.spec.ts +0 -14
  683. package/ts/predicates/IsEmptyObject.spec.ts +0 -15
  684. package/ts/predicates/index.spec.ts +0 -73
  685. package/ts/predicates/isType.spec.ts +0 -106
  686. package/ts/predicates/logical.spec.ts +0 -59
  687. package/ts/promise/PromiseValue.spec.ts +0 -6
  688. package/ts/promise/PromiseValueMerge.spec.ts +0 -7
  689. package/ts/promise/isPromise.spec.ts +0 -26
  690. package/ts/promise/mapSeries.spec.ts +0 -12
  691. package/ts/testing/stub.spec.ts +0 -58
  692. package/ts/type-checker/.eslintrc.json +0 -5
  693. package/ts/type-checker/AnyType.ts +0 -13
  694. package/ts/type-checker/Boolean.ts +0 -34
  695. package/ts/type-checker/Tuple.spec.ts +0 -15
  696. package/ts/type-checker/Tuple.ts +0 -14
  697. package/ts/type-checker/buildTypes.spec.ts +0 -28
  698. package/ts/type-checker/index.ts +0 -0
  699. package/ts/type-checker/typeChecker.spec.ts +0 -14
  700. package/ts/type-checker/typeChecker.ts +0 -52
  701. package/ts/type-checker/types.ts +0 -19
  702. package/ts/types/.eslintrc.json +0 -5
  703. package/ts/types/AllType.ts +0 -31
  704. package/ts/types/Any.ts +0 -7
  705. package/ts/types/Array.ts +0 -43
  706. package/ts/types/BigInt.ts +0 -36
  707. package/ts/types/Boolean.ts +0 -36
  708. package/ts/types/Generate.ts +0 -48
  709. package/ts/types/Null.ts +0 -14
  710. package/ts/types/Number.ts +0 -56
  711. package/ts/types/Object.ts +0 -53
  712. package/ts/types/Record.ts +0 -25
  713. package/ts/types/String.ts +0 -56
  714. package/ts/types/Symbol.ts +0 -19
  715. package/ts/types/Tuple.ts +0 -50
  716. package/ts/types/Undefined.ts +0 -8
  717. package/ts/types/Union.ts +0 -46
  718. package/ts/types/Unknown.ts +0 -9
  719. package/ts/types/analyze.spec.ts +0 -979
  720. package/ts/types/analyze.ts +0 -170
  721. package/ts/types/check.spec.ts +0 -12
  722. package/ts/types/check.ts +0 -26
  723. package/ts/types/conform.spec.ts +0 -7
  724. package/ts/types/conform.ts +0 -27
  725. package/ts/types/getPlainAnalysisReport.spec.ts +0 -354
  726. package/ts/types/getPlainAnalysisReport.ts +0 -115
  727. package/ts/types/index.ts +0 -28
  728. package/ts/types/optional.ts +0 -30
  729. package/ts/types/required.ts +0 -30
  730. package/ts/types/satisfy.accept.ts +0 -39
  731. package/ts/types/satisfy.spec.ts +0 -600
  732. package/ts/types/satisfy.ts +0 -27
  733. package/ts/types/types.ts +0 -10
  734. package/ts/utils/as.spec.ts +0 -45
@@ -1,979 +0,0 @@
1
- import { satisfies } from 'satisfier'
2
- import * as T from '.'
3
- import { AllType } from './AllType'
4
- import { analyze } from './analyze'
5
-
6
- describe('non-strict', () => {
7
- const options = { strict: false, debug: false }
8
- describe('undefined', () => {
9
- test('only undefined passes', () => {
10
- const t = T.undefined
11
- assert(analyze(options, t, undefined), { type: 'undefined' })
12
- analyzeFailsOtherThan(options, t, undefined)
13
- assert(analyze(options, t, true), { type: 'undefined', fail: true })
14
- })
15
- })
16
- describe('null', () => {
17
- test('only null passes', () => {
18
- const t = T.null
19
- assert(analyze(options, t, null), { type: 'null' })
20
- analyzeFailsOtherThan(options, t, null)
21
- assert(analyze(options, t, true), { type: 'null', fail: true })
22
- })
23
- test('optional', () => {
24
- const t = T.null.optional
25
- const pass = {
26
- type: 'union' as const,
27
- value: [
28
- { type: 'null' },
29
- { type: 'undefined' }
30
- ]
31
- }
32
- assert(analyze(options, t, null), pass)
33
- assert(analyze(options, t, undefined), pass)
34
- assert(analyze(options, t, true), {
35
- type: 'union' as const,
36
- value: [
37
- { type: 'null', fail: true },
38
- { type: 'undefined', fail: true }
39
- ],
40
- fail: true
41
- })
42
- })
43
- })
44
- describe('boolean', () => {
45
- test('only true | false passes', () => {
46
- const t = T.boolean
47
- const pass = { type: 'boolean' as const }
48
- assert(analyze(options, t, true), pass)
49
- assert(analyze(options, t, false), pass)
50
- analyzeFailsOtherThan(options, t, true, false)
51
- assert(analyze(options, t, null), { type: 'boolean', fail: true })
52
- })
53
- test('true', () => {
54
- const t = T.boolean.true
55
- assert(analyze(options, t, true), { type: 'boolean', value: true })
56
- assert(analyze(options, t, null), { type: 'boolean', value: true, fail: true })
57
- })
58
- test('false', () => {
59
- const t = T.boolean.false
60
- assert(analyze(options, t, false), { type: 'boolean', value: false })
61
- assert(analyze(options, t, null), { type: 'boolean', value: false, fail: true })
62
- })
63
- test('optional', () => {
64
- const t = T.boolean.optional
65
- const pass = {
66
- type: 'union' as const,
67
- value: [
68
- { type: 'boolean' },
69
- { type: 'undefined' }
70
- ],
71
- }
72
- assert(analyze(options, t, undefined), pass)
73
- assert(analyze(options, t, true), pass)
74
- assert(analyze(options, t, false), pass)
75
- analyzeFailsOtherThan(options, t, true, false, undefined)
76
- assert(analyze(options, t, null), {
77
- type: 'union' as const,
78
- value: [
79
- { type: 'boolean', fail: true },
80
- { type: 'undefined', fail: true }
81
- ],
82
- fail: true
83
- })
84
- })
85
- test('optional create', () => {
86
- const t = T.boolean.optional.create(true)
87
- const pass = {
88
- type: 'union' as const,
89
- value: [
90
- { type: 'boolean', value: true },
91
- { type: 'undefined' }
92
- ],
93
- }
94
- assert(analyze(options, t, undefined), pass)
95
- assert(analyze(options, t, true), pass)
96
- assert(analyze(options, t, false), {
97
- type: 'union' as const,
98
- value: [
99
- { type: 'boolean', value: true, fail: true },
100
- { type: 'undefined', fail: true }
101
- ],
102
- fail: true
103
- })
104
- })
105
- test('optional true', () => {
106
- const t = T.boolean.optional.true
107
- const pass = {
108
- type: 'union' as const,
109
- value: [
110
- { type: 'boolean', value: true },
111
- { type: 'undefined' }
112
- ],
113
- }
114
- assert(analyze(options, t, undefined), pass)
115
- assert(analyze(options, t, true), pass)
116
- assert(analyze(options, t, false), {
117
- type: 'union' as const,
118
- value: [
119
- { type: 'boolean', value: true, fail: true },
120
- { type: 'undefined', fail: true }
121
- ],
122
- fail: true
123
- })
124
- })
125
- test('optional false', () => {
126
- const t = T.boolean.optional.false
127
- const pass = {
128
- type: 'union' as const,
129
- value: [
130
- { type: 'boolean', value: false },
131
- { type: 'undefined' }
132
- ],
133
- }
134
- assert(analyze(options, t, undefined), pass)
135
- assert(analyze(options, t, false), pass)
136
- assert(analyze(options, t, true), {
137
- type: 'union' as const,
138
- value: [
139
- { type: 'boolean', value: false, fail: true },
140
- { type: 'undefined', fail: true }
141
- ],
142
- fail: true
143
- })
144
- })
145
- })
146
- describe('number', () => {
147
- test('only number passes', () => {
148
- const t = T.number
149
- const pass = { type: 'number' as const }
150
- assert(analyze(options, t, 0), pass)
151
- assert(analyze(options, t, 1), pass)
152
- assert(analyze(options, t, -1), pass)
153
- analyzeFailsOtherThan(options, t, -1, 0, 1)
154
- assert(analyze(options, t, null), { type: 'number', fail: true })
155
- })
156
- test('0', () => {
157
- const t = T.number.create(0)
158
- const pass = { type: 'number' as const, value: 0 }
159
- assert(analyze(options, t, 0), pass)
160
- analyzeFailsOtherThan(options, t, 0)
161
- assert(analyze(options, t, 1), { type: 'number', value: 0, fail: true })
162
- })
163
- test('1', () => {
164
- const t = T.number.create(1)
165
- const pass = { type: 'number' as const, value: 1 }
166
- assert(analyze(options, t, 1), pass)
167
- analyzeFailsOtherThan(options, t, 1)
168
- assert(analyze(options, t, 0), { type: 'number', value: 1, fail: true })
169
- })
170
- test('optional', () => {
171
- const t = T.number.optional
172
- const pass = {
173
- type: 'union' as const,
174
- value: [
175
- { type: 'number' },
176
- { type: 'undefined' }
177
- ]
178
- }
179
- assert(analyze(options, t, undefined), pass)
180
- assert(analyze(options, t, 0), pass)
181
- assert(analyze(options, t, 1), pass)
182
- assert(analyze(options, t, -1), pass)
183
- analyzeFailsOtherThan(options, t, -1, 0, 1, undefined)
184
- assert(analyze(options, t, null), {
185
- type: 'union' as const,
186
- value: [
187
- { type: 'number', fail: true },
188
- { type: 'undefined', fail: true }
189
- ],
190
- fail: true
191
- })
192
- })
193
- test('optional create', () => {
194
- const t = T.number.optional.create(1)
195
- const pass = {
196
- type: 'union' as const,
197
- value: [
198
- { type: 'number', value: 1 },
199
- { type: 'undefined' }
200
- ]
201
- }
202
- assert(analyze(options, t, undefined), pass)
203
- assert(analyze(options, t, 1), pass)
204
- assert(analyze(options, t, 0), {
205
- type: 'union' as const,
206
- value: [
207
- { type: 'number', value: 1, fail: true },
208
- { type: 'undefined', fail: true }
209
- ],
210
- fail: true
211
- })
212
- })
213
- test('list: single', () => {
214
- const t = T.number.list(1)
215
- const pass = { type: 'number' as const, value: 1 }
216
- assert(analyze(options, t, 1), pass)
217
- assert(analyze(options, t, 0), {
218
- type: 'number',
219
- value: 1,
220
- fail: true
221
- })
222
- })
223
- test('list: multiple', () => {
224
- const t = T.number.list(1, 2, 3)
225
- const pass = {
226
- type: 'union' as const,
227
- value: [
228
- { type: 'number', value: 1 },
229
- { type: 'number', value: 2 },
230
- { type: 'number', value: 3 },
231
- ]
232
- }
233
- assert(analyze(options, t, 1), pass)
234
- assert(analyze(options, t, 2), pass)
235
- assert(analyze(options, t, 3), pass)
236
- assert(analyze(options, t, 0), {
237
- type: 'union' as const,
238
- value: [
239
- { type: 'number', value: 1, fail: true },
240
- { type: 'number', value: 2, fail: true },
241
- { type: 'number', value: 3, fail: true }
242
- ],
243
- fail: true
244
- })
245
- })
246
- test('optional.list: multiple', () => {
247
- const t = T.number.optional.list(1, 2, 3)
248
- const pass = {
249
- type: 'union' as const,
250
- value: [
251
- { type: 'number', value: 1 },
252
- { type: 'number', value: 2 },
253
- { type: 'number', value: 3 },
254
- { type: 'undefined' }
255
- ]
256
- }
257
- assert(analyze(options, t, undefined), pass)
258
- assert(analyze(options, t, 1), pass)
259
- assert(analyze(options, t, 2), pass)
260
- assert(analyze(options, t, 3), pass)
261
- assert(analyze(options, t, 0), {
262
- type: 'union' as const,
263
- value: [
264
- { type: 'number', value: 1, fail: true },
265
- { type: 'number', value: 2, fail: true },
266
- { type: 'number', value: 3, fail: true },
267
- { type: 'undefined', fail: true }
268
- ],
269
- fail: true
270
- })
271
- })
272
- })
273
- describe('string', () => {
274
- test('only string passes', () => {
275
- const t = T.string
276
- const pass = { type: 'string' as const }
277
- assert(analyze(options, t, ''), pass)
278
- assert(analyze(options, t, 'a'), pass)
279
- analyzeFailsOtherThan(options, t, '', 'a')
280
- assert(analyze(options, t, null), { type: 'string', fail: true })
281
- })
282
- test("''", () => {
283
- const t = T.string.create('')
284
- const pass = { type: 'string' as const, value: '' }
285
- assert(analyze(options, t, ''), pass)
286
- analyzeFailsOtherThan(options, t, '')
287
- assert(analyze(options, t, 'a'), { type: 'string', value: '', fail: true })
288
- })
289
- test(`'a'`, () => {
290
- const t = T.string.create('a')
291
- const pass = { type: 'string' as const, value: 'a' }
292
- assert(analyze(options, t, 'a'), pass)
293
- analyzeFailsOtherThan(options, t, 'a')
294
- assert(analyze(options, t, ''), { type: 'string', value: 'a', fail: true })
295
- })
296
- test('optional', () => {
297
- const t = T.string.optional
298
- const pass = {
299
- type: 'union' as const,
300
- value: [
301
- { type: 'string' },
302
- { type: 'undefined' }
303
- ]
304
- }
305
- assert(analyze(options, t, undefined), pass)
306
- assert(analyze(options, t, ''), pass)
307
- assert(analyze(options, t, 'a'), pass)
308
- analyzeFailsOtherThan(options, t, '', 'a', undefined)
309
- assert(analyze(options, t, null), {
310
- type: 'union' as const,
311
- value: [
312
- { type: 'string', fail: true },
313
- { type: 'undefined', fail: true }
314
- ],
315
- fail: true
316
- })
317
- })
318
- test('optional create', () => {
319
- const t = T.string.optional.create('a')
320
- const pass = {
321
- type: 'union' as const,
322
- value: [
323
- { type: 'string', value: 'a' },
324
- { type: 'undefined' }
325
- ]
326
- }
327
- assert(analyze(options, t, undefined), pass)
328
- assert(analyze(options, t, 'a'), pass)
329
- assert(analyze(options, t, ''), {
330
- type: 'union' as const,
331
- value: [
332
- { type: 'string', value: 'a', fail: true },
333
- { type: 'undefined', fail: true }
334
- ],
335
- fail: true
336
- })
337
- })
338
- test('list: single', () => {
339
- const t = T.string.list('a')
340
- assert(analyze(options, t, 'a'), { type: 'string', value: 'a' })
341
- assert(analyze(options, t, ''), {
342
- type: 'string',
343
- value: 'a',
344
- fail: true
345
- })
346
- })
347
- test('list: multiple', () => {
348
- const t = T.string.list('1', '2', '3')
349
- const pass = {
350
- type: 'union' as const,
351
- value: [
352
- { type: 'string', value: '1' },
353
- { type: 'string', value: '2' },
354
- { type: 'string', value: '3' }
355
- ]
356
- }
357
- assert(analyze(options, t, '1'), pass)
358
- assert(analyze(options, t, '2'), pass)
359
- assert(analyze(options, t, '3'), pass)
360
- assert(analyze(options, t, 1), {
361
- type: 'union' as const,
362
- value: [
363
- { type: 'string', value: '1', fail: true },
364
- { type: 'string', value: '2', fail: true },
365
- { type: 'string', value: '3', fail: true },
366
- ],
367
- fail: true
368
- })
369
- })
370
- test('optional.list: multiple', () => {
371
- const t = T.string.optional.list('1', '2', '3')
372
- const pass = {
373
- type: 'union' as const,
374
- value: [
375
- { type: 'string', value: '1' },
376
- { type: 'string', value: '2' },
377
- { type: 'string', value: '3' },
378
- { type: 'undefined' }
379
- ]
380
- }
381
- assert(analyze(options, t, undefined), pass)
382
- assert(analyze(options, t, '1'), pass)
383
- assert(analyze(options, t, '2'), pass)
384
- assert(analyze(options, t, '3'), pass)
385
- assert(analyze(options, t, 1), {
386
- type: 'union' as const,
387
- value: [
388
- { type: 'string', value: '1', fail: true },
389
- { type: 'string', value: '2', fail: true },
390
- { type: 'string', value: '3', fail: true },
391
- { type: 'undefined', fail: true }
392
- ],
393
- fail: true
394
- })
395
- })
396
- })
397
- describe('bigint', () => {
398
- // test('only number passes', () => {
399
- // const t = T.number
400
- // const pass = { type: 'number' }
401
- // assert(analyze(options, t, 0), pass)
402
- // assert(analyze(options, t, 1), pass)
403
- // assert(analyze(options, t, -1), pass)
404
- // analyzeFailsOtherThan(options, t, -1, 0, 1)
405
- // assert(analyze(options, t, null), { pass: false, type: 'number' })
406
- // })
407
- // test('0', () => {
408
- // const t = T.number.create(0)
409
- // const pass = { type: 'number', value: 0 }
410
- // assert(analyze(options, t, 0), pass)
411
- // analyzeFailsOtherThan(options, t, 0)
412
- // assert(analyze(options, t, 1), { pass: false, type: 'number', value: 0, actual: 1 })
413
- // })
414
- // test('1', () => {
415
- // const t = T.number.create(1)
416
- // const pass = { type: 'number', value: 1 }
417
- // assert(analyze(options, t, 1), pass)
418
- // analyzeFailsOtherThan(options, t, 1)
419
- // assert(analyze(options, t, 0), { pass: false, type: 'number', value: 1, actual: 0 })
420
- // })
421
- // test('optional', () => {
422
- // const t = T.number.optional
423
- // const pass = {
424
- // pass: true,
425
- // type: 'union',
426
- // value: [
427
- // { type: 'number' },
428
- // { type: 'undefined' }
429
- // ]
430
- // }
431
- // assert(analyze(options, t, undefined), pass)
432
- // assert(analyze(options, t, 0), pass)
433
- // assert(analyze(options, t, 1), pass)
434
- // assert(analyze(options, t, -1), pass)
435
- // analyzeFailsOtherThan(options, t, -1, 0, 1, undefined)
436
- // assert(analyze(options, t, null), {
437
- // pass: false,
438
- // type: 'union',
439
- // value: [
440
- // { pass: false, type: 'number' },
441
- // { pass: false, type: 'undefined' }
442
- // ],
443
- // actual: null
444
- // })
445
- // })
446
- // test('optional create', () => {
447
- // const t = T.number.optional.create(1)
448
- // const pass = {
449
- // pass: true,
450
- // type: 'union',
451
- // value: [
452
- // { type: 'number', value: 1 },
453
- // { type: 'undefined' }
454
- // ]
455
- // }
456
- // assert(analyze(options, t, undefined), pass)
457
- // assert(analyze(options, t, 1), pass)
458
- // assert(analyze(options, t, 0), {
459
- // pass: false,
460
- // type: 'union',
461
- // value: [
462
- // { pass: false, type: 'number', value: 1, actual: 0 },
463
- // { pass: false, type: 'undefined', actual: 0 }
464
- // ],
465
- // actual: 0
466
- // })
467
- // })
468
- // test('list: single', () => {
469
- // const t = T.number.list(1)
470
- // const pass = { type: 'number', value: 1 }
471
- // assert(analyze(options, t, 1), pass)
472
- // assert(analyze(options, t, 0), {
473
- // pass: false,
474
- // type: 'number',
475
- // value: 1,
476
- // actual: 0
477
- // })
478
- // })
479
- // test('list: multiple', () => {
480
- // const t = T.number.list(1, 2, 3)
481
- // const pass = {
482
- // pass: true,
483
- // type: 'union',
484
- // value: [
485
- // { type: 'number', value: 1 },
486
- // { type: 'number', value: 2 },
487
- // { type: 'number', value: 3 },
488
- // ]
489
- // }
490
- // assert(analyze(options, t, 1), pass)
491
- // assert(analyze(options, t, 2), pass)
492
- // assert(analyze(options, t, 3), pass)
493
- // assert(analyze(options, t, 0), {
494
- // pass: false,
495
- // type: 'union',
496
- // value: [
497
- // { pass: false, type: 'number', value: 1, actual: 0 },
498
- // { pass: false, type: 'number', value: 2, actual: 0 },
499
- // { pass: false, type: 'number', value: 3, actual: 0 }
500
- // ],
501
- // actual: 0
502
- // })
503
- // })
504
- // test('optional.list: multiple', () => {
505
- // const t = T.number.optional.list(1, 2, 3)
506
- // const pass = {
507
- // pass: true,
508
- // type: 'union',
509
- // value: [
510
- // { type: 'number', value: 1 },
511
- // { type: 'number', value: 2 },
512
- // { type: 'number', value: 3 },
513
- // { type: 'undefined' }
514
- // ]
515
- // }
516
- // assert(analyze(options, t, undefined), pass)
517
- // assert(analyze(options, t, 1), pass)
518
- // assert(analyze(options, t, 2), pass)
519
- // assert(analyze(options, t, 3), pass)
520
- // assert(analyze(options, t, 0), {
521
- // pass: false,
522
- // type: 'union',
523
- // value: [
524
- // { pass: false, type: 'number', value: 1, actual: 0 },
525
- // { pass: false, type: 'number', value: 2, actual: 0 },
526
- // { pass: false, type: 'number', value: 3, actual: 0 },
527
- // { pass: false, type: 'undefined', actual: 0 }
528
- // ],
529
- // actual: 0
530
- // })
531
- // })
532
- })
533
- describe('symbol', () => {
534
- test('only symbol passes', () => {
535
- const t = T.symbol
536
- const pass = { type: 'symbol' } as const
537
- assert(analyze(options, t, Symbol()), pass)
538
- assert(analyze(options, t, Symbol('abc')), pass)
539
- assert(analyze(options, t, Symbol.for('def')), pass)
540
- analyzeFailsOtherThan(options, t, Symbol.for('a'))
541
- assert(analyze(options, t, true), { type: 'symbol', fail: true })
542
- })
543
- test('optional', () => {
544
- const t = T.symbol.optional
545
- const pass = {
546
- type: 'union' as const,
547
- value: [
548
- { type: 'symbol' },
549
- { type: 'undefined' }
550
- ]
551
- }
552
- assert(analyze(options, t, Symbol()), pass)
553
- assert(analyze(options, t, Symbol('abc')), pass)
554
- assert(analyze(options, t, Symbol.for('def')), pass)
555
- assert(analyze(options, t, undefined), pass)
556
- assert(analyze(options, t, true), {
557
- type: 'union' as const,
558
- value: [
559
- { type: 'symbol', fail: true },
560
- { type: 'undefined', fail: true }
561
- ],
562
- fail: true
563
- })
564
- })
565
- })
566
- describe('union', () => {
567
- test('on two types', () => {
568
- const t = T.union.create(T.boolean, T.number)
569
- const pass = { type: 'union' as const, value: [{ type: 'boolean' }, { type: 'number' }] }
570
- assert(analyze(options, t, 0), pass)
571
- assert(analyze(options, t, false), pass)
572
- })
573
- test('on multiple primitive types', () => {
574
- const t = T.union.create(T.boolean, T.null, T.number)
575
- const pass = {
576
- type: 'union' as const,
577
- value: [
578
- { type: 'boolean' },
579
- { type: 'null' },
580
- { type: 'number' }
581
- ]
582
- }
583
- assert(analyze(options, t, false), pass)
584
- assert(analyze(options, t, null), pass)
585
- assert(analyze(options, t, 0), pass)
586
- })
587
- })
588
- describe('array', () => {
589
- test('only array of any kind passes', () => {
590
- const t = T.array
591
- const pass = { type: 'array' as const }
592
- assert(analyze(options, t, []), pass)
593
- assert(analyze(options, t, ['a']), pass)
594
- analyzeFailsOtherThan(options, t, [], ['a'])
595
- assert(analyze(options, t, null), { type: 'array', fail: true })
596
- })
597
- test('array.unknown accepts only array of any kind', () => {
598
- const t = T.array.unknown
599
- const pass = { type: 'array', value: { type: 'unknown' } } as const
600
- assert(analyze(options, t, []), pass)
601
- assert(analyze(options, t, ['a']), pass)
602
- analyzeFailsOtherThan(options, t, [], ['a'])
603
- assert(analyze(options, t, null), {
604
- type: 'array',
605
- value: { type: 'unknown' },
606
- fail: true
607
- })
608
- })
609
- test('specific type', () => {
610
- const t = T.array.create(T.number)
611
- const pass = { type: 'array', value: { type: 'number' } } as const
612
- assert(analyze(options, t, []), pass)
613
- assert(analyze(options, t, [0]), pass)
614
- assert(analyze(options, t, [1, 2]), pass)
615
- assert(analyze(options, t, ['a']), {
616
- type: 'array',
617
- value: { type: 'number', fail: true },
618
- fail: true
619
- })
620
- assert(analyze(options, t, [1, 'a']), {
621
- type: 'array',
622
- // value: { type: 'number' },
623
- value: { type: 'number', fail: true },
624
- fail: true
625
- })
626
- assert(analyze(options, t, ['a', 1]), {
627
- type: 'array',
628
- value: { type: 'number', fail: true },
629
- fail: true
630
- })
631
- })
632
- test('specific const type', () => {
633
- const t = T.array.create(T.number.create(2))
634
- const pass = { type: 'array', value: { type: 'number', value: 2 } } as const
635
- assert(analyze(options, t, []), pass)
636
- assert(analyze(options, t, [2]), pass)
637
- assert(analyze(options, t, [0]), {
638
- type: 'array',
639
- value: { type: 'number', value: 2, fail: true },
640
- fail: true
641
- })
642
- })
643
- test(`array's value type can be union type`, () => {
644
- const t = T.array.create(T.union.create(T.number, T.boolean))
645
- const pass = {
646
- type: 'array',
647
- value: {
648
- type: 'union',
649
- value: [{ type: 'number' }, { type: 'boolean' }]
650
- }
651
- } as const
652
- assert(analyze(options, t, []), pass)
653
- assert(analyze(options, t, [0]), pass)
654
- assert(analyze(options, t, [false]), pass)
655
- assert(analyze(options, t, [false, 0]), pass)
656
- assert(analyze(options, t, [0, false, '']), {
657
- type: 'array',
658
- value: {
659
- type: 'union',
660
- value: [
661
- { type: 'number', fail: true },
662
- { type: 'boolean', fail: true }
663
- ],
664
- fail: true
665
- },
666
- fail: true
667
- })
668
- })
669
- test('optional', () => {
670
- const t = T.array.optional
671
- const pass = { type: 'union' as const, value: [{ type: 'array' }, { type: 'undefined' }] }
672
- assert(analyze(options, t, []), pass)
673
- assert(analyze(options, t, [1]), pass)
674
- assert(analyze(options, t, ['a']), pass)
675
- assert(analyze(options, t, undefined), pass)
676
- })
677
- test('optional create', () => {
678
- const t = T.array.optional.create(T.string)
679
- const pass = {
680
- type: 'union' as const,
681
- value: [
682
- { type: 'array', value: { type: 'string' } },
683
- { type: 'undefined' }
684
- ]
685
- }
686
- assert(analyze(options, t, ['']), pass)
687
- assert(analyze(options, t, ['a']), pass)
688
- assert(analyze(options, t, undefined), pass)
689
- })
690
- })
691
- describe('tuple', () => {
692
- test('single value', () => {
693
- const t = T.tuple.create(T.number)
694
- const pass = { type: 'tuple' as const, value: [{ type: 'number' as const }] }
695
- assert(analyze(options, t, [0]), pass)
696
- assert(analyze(options, t, [1]), pass)
697
- assert(analyze(options, t, true), {
698
- type: 'tuple',
699
- value: [{ type: 'number' }],
700
- fail: true
701
- })
702
- assert(analyze(options, t, []), {
703
- type: 'tuple',
704
- value: [{ type: 'number', fail: true }],
705
- fail: true
706
- })
707
- assert(analyze(options, t, ['a']), {
708
- type: 'tuple',
709
- value: [{ type: 'number', fail: true }],
710
- fail: true
711
- })
712
- })
713
- test('two values', () => {
714
- const t = T.tuple.create(T.number, T.string)
715
- const pass = { type: 'tuple' as const, value: [{ type: 'number' }, { type: 'string' }] }
716
-
717
- expect(T.satisfy(t, [0, ''])).toBe(true)
718
- expect(T.satisfy(t, [0])).toBe(false)
719
-
720
- assert(analyze(options, t, [0, '']), pass)
721
- assert(analyze(options, t, [1]), {
722
- type: 'tuple',
723
- value: [
724
- { type: 'number' },
725
- { type: 'string', fail: true }
726
- ],
727
- fail: true
728
- })
729
- assert(analyze(options, t, [1, 2]), {
730
- type: 'tuple',
731
- value: [
732
- { type: 'number' },
733
- { type: 'string', fail: true }
734
- ],
735
- fail: true
736
- })
737
- assert(analyze(options, t, ['a']), {
738
- type: 'tuple',
739
- value: [
740
- { type: 'number', fail: true },
741
- { type: 'string', fail: true }
742
- ],
743
- fail: true
744
- })
745
- })
746
- })
747
- describe('object', () => {
748
- test('only object of any kind passes', () => {
749
- const t = T.object
750
- const pass = { type: 'object' as const }
751
- assert(analyze(options, t, {}), pass)
752
- assert(analyze(options, t, { a: 1 }), pass)
753
- assert(analyze(options, t, { 0: 0 }), pass)
754
- assert(analyze(options, t, []), {
755
- type: 'object',
756
- fail: true
757
- })
758
- assert(analyze(options, t, null), {
759
- type: 'object',
760
- fail: true
761
- })
762
- analyzeFailsOtherThan(options, t, {}, { a: 1 })
763
- })
764
- test('single prop', () => {
765
- const t = T.object.create({ a: T.number })
766
- const pass = { type: 'object' as const, value: { a: { type: 'number' } } }
767
- assert(analyze(options, t, { a: 0 }), pass)
768
- assert(analyze(options, t, { a: 1 }), pass)
769
- assert(analyze(options, t, { a: 'a' }), {
770
- type: 'object',
771
- value: { a: { type: 'number', fail: true } },
772
- fail: true
773
- })
774
- assert(analyze(options, t, { a: { b: 'b' } }), {
775
- type: 'object',
776
- value: { a: { type: 'number', fail: true } },
777
- fail: true
778
- })
779
- })
780
- test('two props', () => {
781
- const t = T.object.create({ a: T.number.create(1), b: T.string })
782
- const pass = {
783
- type: 'object' as const,
784
- value: {
785
- a: { type: 'number', value: 1 },
786
- b: { type: 'string' }
787
- }
788
- }
789
- assert(analyze(options, t, { a: 1, b: '' }), pass)
790
- assert(analyze(options, t, { a: 1, b: 'b' }), pass)
791
- assert(analyze(options, t, { a: 1, b: '' }), pass)
792
- assert(analyze(options, t, { a: 1, b: '', c: 3 }), pass)
793
- assert(analyze(options, t, { a: 2, b: '' }), {
794
- type: 'object',
795
- value: {
796
- a: { type: 'number', value: 1, fail: true },
797
- b: { type: 'string' }
798
- },
799
- fail: true
800
- })
801
- })
802
- test('props with union', () => {
803
- const t = T.object.create({
804
- a: T.union.create(T.number.create(1), T.boolean.true),
805
- b: T.string
806
- })
807
- const pass = {
808
- type: 'object' as const,
809
- value: {
810
- a: {
811
- type: 'union' as const,
812
- value: [{ type: 'number', value: 1 }, { type: 'boolean', value: true }]
813
- },
814
- b: { type: 'string' }
815
- }
816
- }
817
-
818
- assert(analyze(options, t, { a: 1, b: '' }), pass)
819
- assert(analyze(options, t, { a: true, b: '' }), pass)
820
- assert(analyze(options, t, { a: false, b: '' }), {
821
- type: 'object',
822
- value: {
823
- a: {
824
- type: 'union',
825
- value: [
826
- { type: 'number', value: 1, fail: true },
827
- { type: 'boolean', value: true, fail: true }
828
- ],
829
- fail: true
830
- },
831
- b: { type: 'string' }
832
- },
833
- fail: true
834
- })
835
- })
836
- test('nested object', () => {
837
- const t = T.object.create({ a: T.object.create({ b: T.number }) })
838
- const pass = {
839
- type: 'object' as const,
840
- value: {
841
- a: { type: 'object', value: { b: { type: 'number' } } }
842
- }
843
- }
844
- assert(analyze(options, t, { a: { b: 0 } }), pass)
845
- assert(analyze(options, t, { a: { b: 'b' } }), {
846
- type: 'object',
847
- value: {
848
- a: {
849
- type: 'object',
850
- value: { b: { type: 'number', fail: true } },
851
- fail: true
852
- }
853
- },
854
- fail: true
855
- })
856
- })
857
- test('optional', () => {
858
- const t = T.object.optional
859
- const pass = { type: 'union' as const, value: [{ type: 'object' }, { type: 'undefined' }] }
860
-
861
- assert(analyze(options, t, undefined), pass)
862
- assert(analyze(options, t, {}), pass)
863
- assert(analyze(options, t, { a: 0 }), pass)
864
- })
865
- test('optional create', () => {
866
- const t = T.object.optional.create({ a: T.string })
867
- const pass = {
868
- type: 'union' as const,
869
- value: [
870
- { type: 'object', value: { a: { type: 'string' } } },
871
- { type: 'undefined' }
872
- ]
873
- }
874
-
875
- assert(analyze(options, t, undefined), pass)
876
- assert(analyze(options, t, { a: '' }), pass)
877
- assert(analyze(options, t, {}), {
878
- type: 'union' as const,
879
- value: [
880
- {
881
- type: 'object',
882
- value: {
883
- a: {
884
- type: 'string',
885
- fail: true
886
- }
887
- },
888
- fail: true
889
- },
890
- { type: 'undefined', fail: true }
891
- ],
892
- fail: true
893
- })
894
- })
895
- })
896
- describe('record', () => {
897
- test('base type', () => {
898
- const t = T.record.create(T.number)
899
- const pass = { type: 'record' as const, value: { type: 'number' } }
900
-
901
- analyzeFailsOtherThan(options, T.record.create(T.null), {}, { a: 1 })
902
- assert(analyze(options, t, { a: 1 }), pass)
903
- assert(analyze(options, t, { a: 'b' }), {
904
- type: 'record',
905
- value: { type: 'number', fail: true },
906
- fail: true
907
- })
908
- })
909
- test('nested', () => {
910
- const t = T.record.optional.create(T.record.create(T.string))
911
- const pass = {
912
- type: 'union' as const,
913
- value: [{
914
- type: 'record', value: {
915
- type: 'record', value: { type: 'string' }
916
- }
917
- },
918
- { type: 'undefined' }
919
- ]
920
- }
921
-
922
- assert(analyze(options, t, undefined), pass)
923
- assert(analyze(options, t, { a: { b: 'b' } }), pass)
924
- assert(analyze(options, t, { a: { b: true } }), {
925
- type: 'union' as const,
926
- value: [{
927
- type: 'record',
928
- value: {
929
- type: 'record',
930
- value: { type: 'string', fail: true },
931
- fail: true
932
- },
933
- fail: true
934
- }, {
935
- type: 'undefined',
936
- fail: true
937
- }],
938
- fail: true
939
- })
940
- })
941
- })
942
- })
943
-
944
- describe('strict', () => {
945
- const options = { strict: true, debug: false }
946
- describe('tuple', () => {
947
- test('have more elements then specified will fail', () => {
948
- const t = T.tuple.create(T.string)
949
- assert(analyze(options, t, ['a', 'b', 'c', 'd']), {
950
- type: 'tuple',
951
- value: [{ type: 'string' }],
952
- fail: true
953
- })
954
- })
955
- })
956
- describe('object', () => {
957
- test('have extra properties then specified will fail', () => {
958
- const t = T.object.create({ a: T.number })
959
- assert(analyze(options, t, { a: 1, b: 2, c: 'c' }), {
960
- type: 'object',
961
- value: { a: { type: 'number' } },
962
- fail: true
963
- })
964
- })
965
- })
966
- })
967
-
968
- function assert(result: analyze.Result, analysis: AllType.Analysis) {
969
- expect(result.analysis).toEqual(analysis)
970
- }
971
-
972
- function analyzeFailsOtherThan(options: analyze.Options, type: T.AllType, ...excepts: any[]) {
973
- const values = [undefined, null, true, false, -1, 0, 1, -1n, 0n, 1n, '', 'a', [], ['a'], {}, { a: 1 }, Symbol.for('a')]
974
- values.forEach(v => {
975
- if (!excepts.some(e => satisfies(v, e))) {
976
- expect(analyze(options, type, v).analysis.fail).toBe(true)
977
- }
978
- })
979
- }