bupkis 0.18.1 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (376) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +1 -4
  3. package/src/assertion/assertion-types.ts +4 -4
  4. package/src/assertion/impl/sync-parametric.ts +1 -1
  5. package/src/expect.ts +0 -4
  6. package/src/guards.ts +24 -24
  7. package/src/internal-schema.ts +16 -32
  8. package/src/value-to-schema.ts +1 -1
  9. package/dist/assertion/assertion-async.cjs +0 -268
  10. package/dist/assertion/assertion-async.cjs.map +0 -1
  11. package/dist/assertion/assertion-async.d.cts +0 -40
  12. package/dist/assertion/assertion-async.d.cts.map +0 -1
  13. package/dist/assertion/assertion-async.d.ts +0 -40
  14. package/dist/assertion/assertion-async.d.ts.map +0 -1
  15. package/dist/assertion/assertion-async.js +0 -259
  16. package/dist/assertion/assertion-async.js.map +0 -1
  17. package/dist/assertion/assertion-standard-schema-async.cjs +0 -132
  18. package/dist/assertion/assertion-standard-schema-async.cjs.map +0 -1
  19. package/dist/assertion/assertion-standard-schema-async.d.cts +0 -52
  20. package/dist/assertion/assertion-standard-schema-async.d.cts.map +0 -1
  21. package/dist/assertion/assertion-standard-schema-async.d.ts +0 -52
  22. package/dist/assertion/assertion-standard-schema-async.d.ts.map +0 -1
  23. package/dist/assertion/assertion-standard-schema-async.js +0 -128
  24. package/dist/assertion/assertion-standard-schema-async.js.map +0 -1
  25. package/dist/assertion/assertion-standard-schema-sync.cjs +0 -141
  26. package/dist/assertion/assertion-standard-schema-sync.cjs.map +0 -1
  27. package/dist/assertion/assertion-standard-schema-sync.d.cts +0 -52
  28. package/dist/assertion/assertion-standard-schema-sync.d.cts.map +0 -1
  29. package/dist/assertion/assertion-standard-schema-sync.d.ts +0 -52
  30. package/dist/assertion/assertion-standard-schema-sync.d.ts.map +0 -1
  31. package/dist/assertion/assertion-standard-schema-sync.js +0 -137
  32. package/dist/assertion/assertion-standard-schema-sync.js.map +0 -1
  33. package/dist/assertion/assertion-sync.cjs +0 -284
  34. package/dist/assertion/assertion-sync.cjs.map +0 -1
  35. package/dist/assertion/assertion-sync.d.cts +0 -60
  36. package/dist/assertion/assertion-sync.d.cts.map +0 -1
  37. package/dist/assertion/assertion-sync.d.ts +0 -60
  38. package/dist/assertion/assertion-sync.d.ts.map +0 -1
  39. package/dist/assertion/assertion-sync.js +0 -275
  40. package/dist/assertion/assertion-sync.js.map +0 -1
  41. package/dist/assertion/assertion-types.cjs +0 -20
  42. package/dist/assertion/assertion-types.cjs.map +0 -1
  43. package/dist/assertion/assertion-types.d.cts +0 -1086
  44. package/dist/assertion/assertion-types.d.cts.map +0 -1
  45. package/dist/assertion/assertion-types.d.ts +0 -1086
  46. package/dist/assertion/assertion-types.d.ts.map +0 -1
  47. package/dist/assertion/assertion-types.js +0 -19
  48. package/dist/assertion/assertion-types.js.map +0 -1
  49. package/dist/assertion/assertion.cjs +0 -382
  50. package/dist/assertion/assertion.cjs.map +0 -1
  51. package/dist/assertion/assertion.d.cts +0 -109
  52. package/dist/assertion/assertion.d.cts.map +0 -1
  53. package/dist/assertion/assertion.d.ts +0 -109
  54. package/dist/assertion/assertion.d.ts.map +0 -1
  55. package/dist/assertion/assertion.js +0 -375
  56. package/dist/assertion/assertion.js.map +0 -1
  57. package/dist/assertion/create.cjs +0 -148
  58. package/dist/assertion/create.cjs.map +0 -1
  59. package/dist/assertion/create.d.cts +0 -85
  60. package/dist/assertion/create.d.cts.map +0 -1
  61. package/dist/assertion/create.d.ts +0 -85
  62. package/dist/assertion/create.d.ts.map +0 -1
  63. package/dist/assertion/create.js +0 -143
  64. package/dist/assertion/create.js.map +0 -1
  65. package/dist/assertion/format-assertion-failure.cjs +0 -63
  66. package/dist/assertion/format-assertion-failure.cjs.map +0 -1
  67. package/dist/assertion/format-assertion-failure.d.cts +0 -21
  68. package/dist/assertion/format-assertion-failure.d.cts.map +0 -1
  69. package/dist/assertion/format-assertion-failure.d.ts +0 -21
  70. package/dist/assertion/format-assertion-failure.d.ts.map +0 -1
  71. package/dist/assertion/format-assertion-failure.js +0 -59
  72. package/dist/assertion/format-assertion-failure.js.map +0 -1
  73. package/dist/assertion/impl/assertion-util.cjs +0 -68
  74. package/dist/assertion/impl/assertion-util.cjs.map +0 -1
  75. package/dist/assertion/impl/assertion-util.d.cts +0 -36
  76. package/dist/assertion/impl/assertion-util.d.cts.map +0 -1
  77. package/dist/assertion/impl/assertion-util.d.ts +0 -36
  78. package/dist/assertion/impl/assertion-util.d.ts.map +0 -1
  79. package/dist/assertion/impl/assertion-util.js +0 -62
  80. package/dist/assertion/impl/assertion-util.js.map +0 -1
  81. package/dist/assertion/impl/async-iterable.cjs +0 -627
  82. package/dist/assertion/impl/async-iterable.cjs.map +0 -1
  83. package/dist/assertion/impl/async-iterable.d.cts +0 -406
  84. package/dist/assertion/impl/async-iterable.d.cts.map +0 -1
  85. package/dist/assertion/impl/async-iterable.d.ts +0 -406
  86. package/dist/assertion/impl/async-iterable.d.ts.map +0 -1
  87. package/dist/assertion/impl/async-iterable.js +0 -624
  88. package/dist/assertion/impl/async-iterable.js.map +0 -1
  89. package/dist/assertion/impl/async-parametric.cjs +0 -412
  90. package/dist/assertion/impl/async-parametric.cjs.map +0 -1
  91. package/dist/assertion/impl/async-parametric.d.cts +0 -278
  92. package/dist/assertion/impl/async-parametric.d.cts.map +0 -1
  93. package/dist/assertion/impl/async-parametric.d.ts +0 -278
  94. package/dist/assertion/impl/async-parametric.d.ts.map +0 -1
  95. package/dist/assertion/impl/async-parametric.js +0 -409
  96. package/dist/assertion/impl/async-parametric.js.map +0 -1
  97. package/dist/assertion/impl/async.cjs +0 -56
  98. package/dist/assertion/impl/async.cjs.map +0 -1
  99. package/dist/assertion/impl/async.d.cts +0 -179
  100. package/dist/assertion/impl/async.d.cts.map +0 -1
  101. package/dist/assertion/impl/async.d.ts +0 -179
  102. package/dist/assertion/impl/async.d.ts.map +0 -1
  103. package/dist/assertion/impl/async.js +0 -39
  104. package/dist/assertion/impl/async.js.map +0 -1
  105. package/dist/assertion/impl/index.cjs +0 -37
  106. package/dist/assertion/impl/index.cjs.map +0 -1
  107. package/dist/assertion/impl/index.d.cts +0 -21
  108. package/dist/assertion/impl/index.d.cts.map +0 -1
  109. package/dist/assertion/impl/index.d.ts +0 -21
  110. package/dist/assertion/impl/index.d.ts.map +0 -1
  111. package/dist/assertion/impl/index.js +0 -21
  112. package/dist/assertion/impl/index.js.map +0 -1
  113. package/dist/assertion/impl/iteration-util.cjs +0 -297
  114. package/dist/assertion/impl/iteration-util.cjs.map +0 -1
  115. package/dist/assertion/impl/iteration-util.d.cts +0 -12
  116. package/dist/assertion/impl/iteration-util.d.cts.map +0 -1
  117. package/dist/assertion/impl/iteration-util.d.ts +0 -12
  118. package/dist/assertion/impl/iteration-util.d.ts.map +0 -1
  119. package/dist/assertion/impl/iteration-util.js +0 -282
  120. package/dist/assertion/impl/iteration-util.js.map +0 -1
  121. package/dist/assertion/impl/snapshot.cjs +0 -276
  122. package/dist/assertion/impl/snapshot.cjs.map +0 -1
  123. package/dist/assertion/impl/snapshot.d.cts +0 -278
  124. package/dist/assertion/impl/snapshot.d.cts.map +0 -1
  125. package/dist/assertion/impl/snapshot.d.ts +0 -278
  126. package/dist/assertion/impl/snapshot.d.ts.map +0 -1
  127. package/dist/assertion/impl/snapshot.js +0 -273
  128. package/dist/assertion/impl/snapshot.js.map +0 -1
  129. package/dist/assertion/impl/sync-basic.cjs +0 -553
  130. package/dist/assertion/impl/sync-basic.cjs.map +0 -1
  131. package/dist/assertion/impl/sync-basic.d.cts +0 -528
  132. package/dist/assertion/impl/sync-basic.d.cts.map +0 -1
  133. package/dist/assertion/impl/sync-basic.d.ts +0 -528
  134. package/dist/assertion/impl/sync-basic.d.ts.map +0 -1
  135. package/dist/assertion/impl/sync-basic.js +0 -550
  136. package/dist/assertion/impl/sync-basic.js.map +0 -1
  137. package/dist/assertion/impl/sync-collection.cjs +0 -856
  138. package/dist/assertion/impl/sync-collection.cjs.map +0 -1
  139. package/dist/assertion/impl/sync-collection.d.cts +0 -607
  140. package/dist/assertion/impl/sync-collection.d.cts.map +0 -1
  141. package/dist/assertion/impl/sync-collection.d.ts +0 -607
  142. package/dist/assertion/impl/sync-collection.d.ts.map +0 -1
  143. package/dist/assertion/impl/sync-collection.js +0 -850
  144. package/dist/assertion/impl/sync-collection.js.map +0 -1
  145. package/dist/assertion/impl/sync-date.cjs +0 -341
  146. package/dist/assertion/impl/sync-date.cjs.map +0 -1
  147. package/dist/assertion/impl/sync-date.d.cts +0 -209
  148. package/dist/assertion/impl/sync-date.d.cts.map +0 -1
  149. package/dist/assertion/impl/sync-date.d.ts +0 -209
  150. package/dist/assertion/impl/sync-date.d.ts.map +0 -1
  151. package/dist/assertion/impl/sync-date.js +0 -338
  152. package/dist/assertion/impl/sync-date.js.map +0 -1
  153. package/dist/assertion/impl/sync-esoteric.cjs +0 -214
  154. package/dist/assertion/impl/sync-esoteric.cjs.map +0 -1
  155. package/dist/assertion/impl/sync-esoteric.d.cts +0 -191
  156. package/dist/assertion/impl/sync-esoteric.d.cts.map +0 -1
  157. package/dist/assertion/impl/sync-esoteric.d.ts +0 -191
  158. package/dist/assertion/impl/sync-esoteric.d.ts.map +0 -1
  159. package/dist/assertion/impl/sync-esoteric.js +0 -211
  160. package/dist/assertion/impl/sync-esoteric.js.map +0 -1
  161. package/dist/assertion/impl/sync-iterable.cjs +0 -512
  162. package/dist/assertion/impl/sync-iterable.cjs.map +0 -1
  163. package/dist/assertion/impl/sync-iterable.d.cts +0 -334
  164. package/dist/assertion/impl/sync-iterable.d.cts.map +0 -1
  165. package/dist/assertion/impl/sync-iterable.d.ts +0 -334
  166. package/dist/assertion/impl/sync-iterable.d.ts.map +0 -1
  167. package/dist/assertion/impl/sync-iterable.js +0 -509
  168. package/dist/assertion/impl/sync-iterable.js.map +0 -1
  169. package/dist/assertion/impl/sync-parametric.cjs +0 -805
  170. package/dist/assertion/impl/sync-parametric.cjs.map +0 -1
  171. package/dist/assertion/impl/sync-parametric.d.cts +0 -560
  172. package/dist/assertion/impl/sync-parametric.d.cts.map +0 -1
  173. package/dist/assertion/impl/sync-parametric.d.ts +0 -560
  174. package/dist/assertion/impl/sync-parametric.d.ts.map +0 -1
  175. package/dist/assertion/impl/sync-parametric.js +0 -802
  176. package/dist/assertion/impl/sync-parametric.js.map +0 -1
  177. package/dist/assertion/impl/sync.cjs +0 -214
  178. package/dist/assertion/impl/sync.cjs.map +0 -1
  179. package/dist/assertion/impl/sync.d.cts +0 -512
  180. package/dist/assertion/impl/sync.d.cts.map +0 -1
  181. package/dist/assertion/impl/sync.d.ts +0 -512
  182. package/dist/assertion/impl/sync.d.ts.map +0 -1
  183. package/dist/assertion/impl/sync.js +0 -197
  184. package/dist/assertion/impl/sync.js.map +0 -1
  185. package/dist/assertion/index.cjs +0 -38
  186. package/dist/assertion/index.cjs.map +0 -1
  187. package/dist/assertion/index.d.cts +0 -18
  188. package/dist/assertion/index.d.cts.map +0 -1
  189. package/dist/assertion/index.d.ts +0 -18
  190. package/dist/assertion/index.d.ts.map +0 -1
  191. package/dist/assertion/index.js +0 -17
  192. package/dist/assertion/index.js.map +0 -1
  193. package/dist/assertion/slotify.cjs +0 -165
  194. package/dist/assertion/slotify.cjs.map +0 -1
  195. package/dist/assertion/slotify.d.cts +0 -11
  196. package/dist/assertion/slotify.d.cts.map +0 -1
  197. package/dist/assertion/slotify.d.ts +0 -11
  198. package/dist/assertion/slotify.d.ts.map +0 -1
  199. package/dist/assertion/slotify.js +0 -161
  200. package/dist/assertion/slotify.js.map +0 -1
  201. package/dist/bootstrap.cjs +0 -43
  202. package/dist/bootstrap.cjs.map +0 -1
  203. package/dist/bootstrap.d.cts +0 -27
  204. package/dist/bootstrap.d.cts.map +0 -1
  205. package/dist/bootstrap.d.ts +0 -27
  206. package/dist/bootstrap.d.ts.map +0 -1
  207. package/dist/bootstrap.js +0 -40
  208. package/dist/bootstrap.js.map +0 -1
  209. package/dist/constant.cjs +0 -82
  210. package/dist/constant.cjs.map +0 -1
  211. package/dist/constant.d.cts +0 -69
  212. package/dist/constant.d.cts.map +0 -1
  213. package/dist/constant.d.ts +0 -69
  214. package/dist/constant.d.ts.map +0 -1
  215. package/dist/constant.js +0 -79
  216. package/dist/constant.js.map +0 -1
  217. package/dist/diff.cjs +0 -340
  218. package/dist/diff.cjs.map +0 -1
  219. package/dist/diff.d.cts +0 -51
  220. package/dist/diff.d.cts.map +0 -1
  221. package/dist/diff.d.ts +0 -51
  222. package/dist/diff.d.ts.map +0 -1
  223. package/dist/diff.js +0 -334
  224. package/dist/diff.js.map +0 -1
  225. package/dist/error.cjs +0 -204
  226. package/dist/error.cjs.map +0 -1
  227. package/dist/error.d.cts +0 -212
  228. package/dist/error.d.cts.map +0 -1
  229. package/dist/error.d.ts +0 -212
  230. package/dist/error.d.ts.map +0 -1
  231. package/dist/error.js +0 -191
  232. package/dist/error.js.map +0 -1
  233. package/dist/expect.cjs +0 -590
  234. package/dist/expect.cjs.map +0 -1
  235. package/dist/expect.d.cts +0 -138
  236. package/dist/expect.d.cts.map +0 -1
  237. package/dist/expect.d.ts +0 -138
  238. package/dist/expect.d.ts.map +0 -1
  239. package/dist/expect.js +0 -582
  240. package/dist/expect.js.map +0 -1
  241. package/dist/guards.cjs +0 -297
  242. package/dist/guards.cjs.map +0 -1
  243. package/dist/guards.d.cts +0 -231
  244. package/dist/guards.d.cts.map +0 -1
  245. package/dist/guards.d.ts +0 -231
  246. package/dist/guards.d.ts.map +0 -1
  247. package/dist/guards.js +0 -277
  248. package/dist/guards.js.map +0 -1
  249. package/dist/index.cjs +0 -111
  250. package/dist/index.cjs.map +0 -1
  251. package/dist/index.d.cts +0 -448
  252. package/dist/index.d.cts.map +0 -1
  253. package/dist/index.d.ts +0 -448
  254. package/dist/index.d.ts.map +0 -1
  255. package/dist/index.js +0 -71
  256. package/dist/index.js.map +0 -1
  257. package/dist/internal-schema.cjs +0 -253
  258. package/dist/internal-schema.cjs.map +0 -1
  259. package/dist/internal-schema.d.cts +0 -8
  260. package/dist/internal-schema.d.cts.map +0 -1
  261. package/dist/internal-schema.d.ts +0 -8
  262. package/dist/internal-schema.d.ts.map +0 -1
  263. package/dist/internal-schema.js +0 -248
  264. package/dist/internal-schema.js.map +0 -1
  265. package/dist/metadata.cjs +0 -57
  266. package/dist/metadata.cjs.map +0 -1
  267. package/dist/metadata.d.cts +0 -27
  268. package/dist/metadata.d.cts.map +0 -1
  269. package/dist/metadata.d.ts +0 -27
  270. package/dist/metadata.d.ts.map +0 -1
  271. package/dist/metadata.js +0 -54
  272. package/dist/metadata.js.map +0 -1
  273. package/dist/schema.cjs +0 -1522
  274. package/dist/schema.cjs.map +0 -1
  275. package/dist/schema.d.cts +0 -1196
  276. package/dist/schema.d.cts.map +0 -1
  277. package/dist/schema.d.ts +0 -1196
  278. package/dist/schema.d.ts.map +0 -1
  279. package/dist/schema.js +0 -1516
  280. package/dist/schema.js.map +0 -1
  281. package/dist/snapshot/adapter.cjs +0 -31
  282. package/dist/snapshot/adapter.cjs.map +0 -1
  283. package/dist/snapshot/adapter.d.cts +0 -258
  284. package/dist/snapshot/adapter.d.cts.map +0 -1
  285. package/dist/snapshot/adapter.d.ts +0 -258
  286. package/dist/snapshot/adapter.d.ts.map +0 -1
  287. package/dist/snapshot/adapter.js +0 -27
  288. package/dist/snapshot/adapter.js.map +0 -1
  289. package/dist/snapshot/adapters/fallback.cjs +0 -453
  290. package/dist/snapshot/adapters/fallback.cjs.map +0 -1
  291. package/dist/snapshot/adapters/fallback.d.cts +0 -185
  292. package/dist/snapshot/adapters/fallback.d.cts.map +0 -1
  293. package/dist/snapshot/adapters/fallback.d.ts +0 -185
  294. package/dist/snapshot/adapters/fallback.d.ts.map +0 -1
  295. package/dist/snapshot/adapters/fallback.js +0 -446
  296. package/dist/snapshot/adapters/fallback.js.map +0 -1
  297. package/dist/snapshot/adapters/node-test.cjs +0 -301
  298. package/dist/snapshot/adapters/node-test.cjs.map +0 -1
  299. package/dist/snapshot/adapters/node-test.d.cts +0 -131
  300. package/dist/snapshot/adapters/node-test.d.cts.map +0 -1
  301. package/dist/snapshot/adapters/node-test.d.ts +0 -131
  302. package/dist/snapshot/adapters/node-test.d.ts.map +0 -1
  303. package/dist/snapshot/adapters/node-test.js +0 -297
  304. package/dist/snapshot/adapters/node-test.js.map +0 -1
  305. package/dist/snapshot/index.cjs +0 -61
  306. package/dist/snapshot/index.cjs.map +0 -1
  307. package/dist/snapshot/index.d.cts +0 -40
  308. package/dist/snapshot/index.d.cts.map +0 -1
  309. package/dist/snapshot/index.d.ts +0 -40
  310. package/dist/snapshot/index.d.ts.map +0 -1
  311. package/dist/snapshot/index.js +0 -44
  312. package/dist/snapshot/index.js.map +0 -1
  313. package/dist/snapshot/node-version.cjs +0 -49
  314. package/dist/snapshot/node-version.cjs.map +0 -1
  315. package/dist/snapshot/node-version.d.cts +0 -34
  316. package/dist/snapshot/node-version.d.cts.map +0 -1
  317. package/dist/snapshot/node-version.d.ts +0 -34
  318. package/dist/snapshot/node-version.d.ts.map +0 -1
  319. package/dist/snapshot/node-version.js +0 -44
  320. package/dist/snapshot/node-version.js.map +0 -1
  321. package/dist/snapshot/select-adapter.cjs +0 -170
  322. package/dist/snapshot/select-adapter.cjs.map +0 -1
  323. package/dist/snapshot/select-adapter.d.cts +0 -128
  324. package/dist/snapshot/select-adapter.d.cts.map +0 -1
  325. package/dist/snapshot/select-adapter.d.ts +0 -128
  326. package/dist/snapshot/select-adapter.d.ts.map +0 -1
  327. package/dist/snapshot/select-adapter.js +0 -164
  328. package/dist/snapshot/select-adapter.js.map +0 -1
  329. package/dist/snapshot/serializer.cjs +0 -246
  330. package/dist/snapshot/serializer.cjs.map +0 -1
  331. package/dist/snapshot/serializer.d.cts +0 -126
  332. package/dist/snapshot/serializer.d.cts.map +0 -1
  333. package/dist/snapshot/serializer.d.ts +0 -126
  334. package/dist/snapshot/serializer.d.ts.map +0 -1
  335. package/dist/snapshot/serializer.js +0 -238
  336. package/dist/snapshot/serializer.js.map +0 -1
  337. package/dist/standard-schema.cjs +0 -13
  338. package/dist/standard-schema.cjs.map +0 -1
  339. package/dist/standard-schema.d.cts +0 -192
  340. package/dist/standard-schema.d.cts.map +0 -1
  341. package/dist/standard-schema.d.ts +0 -192
  342. package/dist/standard-schema.d.ts.map +0 -1
  343. package/dist/standard-schema.js +0 -12
  344. package/dist/standard-schema.js.map +0 -1
  345. package/dist/types.cjs +0 -22
  346. package/dist/types.cjs.map +0 -1
  347. package/dist/types.d.cts +0 -905
  348. package/dist/types.d.cts.map +0 -1
  349. package/dist/types.d.ts +0 -905
  350. package/dist/types.d.ts.map +0 -1
  351. package/dist/types.js +0 -21
  352. package/dist/types.js.map +0 -1
  353. package/dist/use.cjs +0 -240
  354. package/dist/use.cjs.map +0 -1
  355. package/dist/use.d.cts +0 -8
  356. package/dist/use.d.cts.map +0 -1
  357. package/dist/use.d.ts +0 -8
  358. package/dist/use.d.ts.map +0 -1
  359. package/dist/use.js +0 -236
  360. package/dist/use.js.map +0 -1
  361. package/dist/util.cjs +0 -255
  362. package/dist/util.cjs.map +0 -1
  363. package/dist/util.d.cts +0 -141
  364. package/dist/util.d.cts.map +0 -1
  365. package/dist/util.d.ts +0 -141
  366. package/dist/util.d.ts.map +0 -1
  367. package/dist/util.js +0 -234
  368. package/dist/util.js.map +0 -1
  369. package/dist/value-to-schema.cjs +0 -537
  370. package/dist/value-to-schema.cjs.map +0 -1
  371. package/dist/value-to-schema.d.cts +0 -144
  372. package/dist/value-to-schema.d.cts.map +0 -1
  373. package/dist/value-to-schema.d.ts +0 -144
  374. package/dist/value-to-schema.d.ts.map +0 -1
  375. package/dist/value-to-schema.js +0 -533
  376. package/dist/value-to-schema.js.map +0 -1
@@ -1,802 +0,0 @@
1
- /**
2
- * Parameterized assertions for comparisons, function behavior, and complex
3
- * validation.
4
- *
5
- * These assertions accept additional parameters to customize their behavior,
6
- * including numeric comparisons, string matching, object satisfaction, function
7
- * throwing behavior, and deep equality checks.
8
- *
9
- * @packageDocumentation
10
- * @groupDescription Parametric Assertions (Sync)
11
- * Complex assertions that accept parameters for customized validation behavior.
12
- *
13
- * @showGroups
14
- */
15
- import { inspect } from 'node:util';
16
- import { z } from 'zod';
17
- import { BupkisError } from "../../error.js";
18
- import { isA, isError, isNonNullObject, isString } from "../../guards.js";
19
- import { AnyObjectSchema, BigintSchema, BooleanSchema, ConstructibleSchema, createErrorMessageRegexSchema, createErrorMessageSchema, DateSchema, ErrorSchema, FunctionSchema, MapSchema, NonNegativeIntegerSchema, NullSchema, NumberSchema, RegExpSchema, SetSchema, StringSchema, SymbolSchema, UndefinedSchema, UnknownArraySchema, UnknownSchema, WeakMapSchema, WeakRefSchema, WeakSetSchema, WrappedPromiseLikeSchema, } from "../../schema.js";
20
- import { valueToSchema, valueToSchemaOptionsForDeepEqual, valueToSchemaOptionsForSatisfies, } from "../../value-to-schema.js";
21
- import { createAssertion } from "../create.js";
22
- import { trapError } from "./assertion-util.js";
23
- const { freeze } = Object;
24
- const { abs } = Math;
25
- /**
26
- * For {@link typeOfAssertion}
27
- */
28
- const knownTypes = freeze(new Set([
29
- 'string',
30
- 'number',
31
- 'boolean',
32
- 'undefined',
33
- 'null',
34
- 'BigInt',
35
- 'Symbol',
36
- 'Object',
37
- 'Function',
38
- 'Array',
39
- 'Date',
40
- 'Map',
41
- 'Set',
42
- 'WeakMap',
43
- 'WeakSet',
44
- 'RegExp',
45
- 'Promise',
46
- 'Error',
47
- 'WeakRef',
48
- ]));
49
- /**
50
- * Assertion for testing if a value is an instance of a specific constructor.
51
- *
52
- * @example
53
- *
54
- * ```typescript
55
- * expect(new Date(), 'to be an instance of', Date); // passes
56
- * expect('hello', 'to be a', String); // fails
57
- * ```
58
- *
59
- * @group Parametric Assertions (Sync)
60
- */
61
- export const instanceOfAssertion = createAssertion([['to be an instance of', 'to be a', 'to be an'], ConstructibleSchema], (_, ctor) => createInstanceOfSchema(ctor));
62
- /**
63
- * Assertion for testing if a value is of a specific built-in type.
64
- *
65
- * @example
66
- *
67
- * ```typescript
68
- * expect('hello', 'to be a', 'string'); // passes
69
- * expect(42, 'to be an', 'Array'); // fails
70
- * expect([], 'to be a', 'array'); // passes
71
- * ```
72
- *
73
- * @group Parametric Assertions (Sync)
74
- */
75
- export const typeOfAssertion = createAssertion([
76
- UnknownSchema,
77
- ['to be a', 'to be an', 'to have type'],
78
- z.enum([...knownTypes].flatMap((t) => [t, t.toLowerCase()])),
79
- ], (_, type) => {
80
- type = type.toLowerCase();
81
- // these first three are names that are _not_ results of the `typeof` operator; i.e. `typeof x` will never return these strings
82
- switch (type) {
83
- case 'array':
84
- return UnknownArraySchema;
85
- case 'bigint':
86
- return BigintSchema;
87
- case 'boolean':
88
- return BooleanSchema;
89
- case 'date':
90
- return DateSchema;
91
- case 'error':
92
- return ErrorSchema;
93
- case 'function':
94
- return FunctionSchema;
95
- case 'map':
96
- return MapSchema;
97
- case 'null':
98
- return NullSchema;
99
- case 'number':
100
- return NumberSchema;
101
- case 'object':
102
- return AnyObjectSchema;
103
- case 'promise':
104
- return WrappedPromiseLikeSchema;
105
- case 'regex': // fallthrough
106
- case 'regexp':
107
- return RegExpSchema;
108
- case 'set':
109
- return SetSchema;
110
- case 'string':
111
- return StringSchema;
112
- case 'symbol':
113
- return SymbolSchema;
114
- case 'undefined':
115
- return UndefinedSchema;
116
- case 'weakmap':
117
- return WeakMapSchema;
118
- case 'weakref':
119
- return WeakRefSchema;
120
- case 'weakset':
121
- return WeakSetSchema;
122
- // c8 ignore next 2
123
- default:
124
- throw new BupkisError(`Unknown "type": "${type}"`);
125
- }
126
- });
127
- /**
128
- * Assertion for testing if a number is greater than another number.
129
- *
130
- * @example
131
- *
132
- * ```typescript
133
- * expect(5, 'to be greater than', 3); // passes
134
- * expect(2, 'to be greater than', 5); // fails
135
- * ```
136
- *
137
- * @group Parametric Assertions (Sync)
138
- */
139
- export const numberGreaterThanAssertion = createAssertion([NumberSchema, 'to be greater than', NumberSchema], (_, other) => NumberSchema.gt(other));
140
- /**
141
- * Assertion for testing if a number is less than another number.
142
- *
143
- * @example
144
- *
145
- * ```typescript
146
- * expect(3, 'to be less than', 5); // passes
147
- * expect(5, 'to be less than', 2); // fails
148
- * ```
149
- *
150
- * @group Parametric Assertions (Sync)
151
- */
152
- export const numberLessThanAssertion = createAssertion([NumberSchema, ['to be less than', 'to be lt'], NumberSchema], (_, other) => NumberSchema.lt(other));
153
- /**
154
- * Assertion for testing if a number is greater than or equal to another number.
155
- *
156
- * @example
157
- *
158
- * ```typescript
159
- * expect(5, 'to be greater than or equal to', 5); // passes
160
- * expect(5, 'to be at least', 3); // passes
161
- * expect(2, 'to be at least', 5); // fails
162
- * ```
163
- *
164
- * @group Parametric Assertions (Sync)
165
- */
166
- export const numberGreaterThanOrEqualAssertion = createAssertion([
167
- NumberSchema,
168
- ['to be greater than or equal to', 'to be at least', 'to be gte'],
169
- NumberSchema,
170
- ], (_, other) => NumberSchema.gte(other));
171
- /**
172
- * Assertion for testing if a number is less than or equal to another number.
173
- *
174
- * @example
175
- *
176
- * ```typescript
177
- * expect(3, 'to be less than or equal to', 5); // passes
178
- * expect(5, 'to be at most', 5); // passes
179
- * expect(7, 'to be at most', 5); // fails
180
- * ```
181
- *
182
- * @group Parametric Assertions (Sync)
183
- */
184
- export const numberLessThanOrEqualAssertion = createAssertion([
185
- NumberSchema,
186
- ['to be less than or equal to', 'to be at most', 'to be lte'],
187
- NumberSchema,
188
- ], (_, other) => NumberSchema.lte(other));
189
- /**
190
- * Assertion for testing if a number is within a specific range (inclusive).
191
- *
192
- * @example
193
- *
194
- * ```typescript
195
- * expect(5, 'to be within', 1, 10); // passes
196
- * expect(15, 'to be between', 1, 10); // fails
197
- * ```
198
- *
199
- * @group Parametric Assertions (Sync)
200
- */
201
- export const numberWithinRangeAssertion = createAssertion([NumberSchema, ['to be within', 'to be between'], NumberSchema, NumberSchema], (subject, min, max) => {
202
- if (subject < min || subject > max) {
203
- return {
204
- message: `Expected ${subject} to be within range [${min}, ${max}]`,
205
- };
206
- }
207
- });
208
- /**
209
- * Assertion for testing if a number is close to another number within a
210
- * tolerance.
211
- *
212
- * @example
213
- *
214
- * ```typescript
215
- * expect(1.0001, 'to be close to', 1.0, 0.001); // passes
216
- * expect(1.1, 'to be close to', 1.0, 0.01); // fails
217
- * ```
218
- *
219
- * @group Parametric Assertions (Sync)
220
- */
221
- export const numberCloseToAssertion = createAssertion([NumberSchema, 'to be close to', NumberSchema, NumberSchema.optional()], (subject, expected, tolerance = 1e-9) => {
222
- const diff = abs(subject - expected);
223
- if (diff > tolerance) {
224
- return {
225
- actual: subject,
226
- expected,
227
- message: `Expected ${subject} to be close to ${expected} (within ${tolerance}), but difference was ${diff}`,
228
- };
229
- }
230
- });
231
- /**
232
- * Assertion for testing if a string is lexicographically greater than another
233
- * string.
234
- *
235
- * @example
236
- *
237
- * ```typescript
238
- * expect('b', 'to be greater than', 'a'); // passes
239
- * expect('apple', 'to be greater than', 'banana'); // fails
240
- * ```
241
- *
242
- * @group Parametric Assertions (Sync)
243
- */
244
- export const stringGreaterThanAssertion = createAssertion([StringSchema, 'to be greater than', StringSchema], (subject, other) => {
245
- if (!(subject > other)) {
246
- return {
247
- message: `Expected "${subject}" to be greater than "${other}"`,
248
- };
249
- }
250
- });
251
- /**
252
- * Assertion for testing if a string is lexicographically less than another
253
- * string.
254
- *
255
- * @example
256
- *
257
- * ```typescript
258
- * expect('a', 'to be less than', 'b'); // passes
259
- * expect('banana', 'to be less than', 'apple'); // fails
260
- * ```
261
- *
262
- * @group Parametric Assertions (Sync)
263
- */
264
- export const stringLessThanAssertion = createAssertion([StringSchema, 'to be less than', StringSchema], (subject, other) => {
265
- if (!(subject < other)) {
266
- return {
267
- message: `Expected "${subject}" to be less than "${other}"`,
268
- };
269
- }
270
- });
271
- /**
272
- * Assertion for testing if a string is lexicographically greater than or equal
273
- * to another string.
274
- *
275
- * @example
276
- *
277
- * ```typescript
278
- * expect('b', 'to be greater than or equal to', 'a'); // passes
279
- * expect('a', 'to be greater than or equal to', 'a'); // passes
280
- * expect('a', 'to be greater than or equal to', 'b'); // fails
281
- * ```
282
- *
283
- * @group Parametric Assertions (Sync)
284
- */
285
- export const stringGreaterThanOrEqualAssertion = createAssertion([StringSchema, 'to be greater than or equal to', StringSchema], (subject, other) => {
286
- if (!(subject >= other)) {
287
- return {
288
- message: `Expected "${subject}" to be greater than or equal to "${other}"`,
289
- };
290
- }
291
- });
292
- /**
293
- * Assertion for testing if a string is lexicographically less than or equal to
294
- * another string.
295
- *
296
- * @example
297
- *
298
- * ```typescript
299
- * expect('a', 'to be less than or equal to', 'b'); // passes
300
- * expect('a', 'to be less than or equal to', 'a'); // passes
301
- * expect('b', 'to be less than or equal to', 'a'); // fails
302
- * ```
303
- *
304
- * @group Parametric Assertions (Sync)
305
- */
306
- export const stringLessThanOrEqualAssertion = createAssertion([StringSchema, 'to be less than or equal to', StringSchema], (subject, other) => {
307
- if (!(subject <= other)) {
308
- return {
309
- message: `Expected "${subject}" to be less than or equal to "${other}"`,
310
- };
311
- }
312
- });
313
- /**
314
- * Assertion for testing if a string begins with a specific prefix.
315
- *
316
- * @example
317
- *
318
- * ```typescript
319
- * expect('hello world', 'to begin with', 'hello'); // passes
320
- * expect('hello world', 'to start with', 'world'); // fails
321
- * ```
322
- *
323
- * @group Parametric Assertions (Sync)
324
- */
325
- export const stringBeginsWithAssertion = createAssertion([StringSchema, ['to begin with', 'to start with'], StringSchema], (subject, prefix) => {
326
- if (!subject.startsWith(prefix)) {
327
- return {
328
- message: `Expected "${subject}" to begin with "${prefix}"`,
329
- };
330
- }
331
- });
332
- /**
333
- * Assertion for testing if a string ends with a specific suffix.
334
- *
335
- * @example
336
- *
337
- * ```typescript
338
- * expect('hello world', 'to end with', 'world'); // passes
339
- * expect('hello world', 'to end with', 'hello'); // fails
340
- * ```
341
- *
342
- * @group Parametric Assertions (Sync)
343
- */
344
- export const stringEndsWithAssertion = createAssertion([StringSchema, 'to end with', StringSchema], (subject, suffix) => {
345
- if (!subject.endsWith(suffix)) {
346
- return {
347
- message: `Expected "${subject}" to end with "${suffix}"`,
348
- };
349
- }
350
- });
351
- /**
352
- * Assertion for testing if a value is one of a specific set of values.
353
- *
354
- * @example
355
- *
356
- * ```typescript
357
- * expect('red', 'to be one of', ['red', 'green', 'blue']); // passes
358
- * expect('yellow', 'to be one of', ['red', 'green', 'blue']); // fails
359
- * ```
360
- *
361
- * @group Parametric Assertions (Sync)
362
- */
363
- export const oneOfAssertion = createAssertion(['to be one of', UnknownArraySchema], (subject, values) => {
364
- if (!values.includes(subject)) {
365
- return {
366
- actual: subject,
367
- expected: values,
368
- message: `Expected ${inspect(subject)} to be one of [${values.map((v) => inspect(v)).join(', ')}]`,
369
- };
370
- }
371
- });
372
- /**
373
- * Assertion for testing if a function has a specific arity (number of
374
- * parameters).
375
- *
376
- * @example
377
- *
378
- * ```typescript
379
- * expect((a, b) => a + b, 'to have arity', 2); // passes
380
- * expect((a, b, c) => a + b + c, 'to have arity', 2); // fails
381
- * ```
382
- *
383
- * @group Parametric Assertions (Sync)
384
- */
385
- export const functionArityAssertion = createAssertion([FunctionSchema, 'to have arity', NonNegativeIntegerSchema], (subject, expectedArity) => {
386
- if (subject.length !== expectedArity) {
387
- return {
388
- actual: subject.length,
389
- expected: expectedArity,
390
- message: `Expected function to have arity ${expectedArity}, but it has arity ${subject.length}`,
391
- };
392
- }
393
- });
394
- /**
395
- * Assertion for testing if an Error has a specific message.
396
- *
397
- * @example
398
- *
399
- * ```typescript
400
- * expect(new Error('oops'), 'to have message', 'oops'); // passes
401
- * expect(new Error('oops'), 'to have message', 'wrong'); // fails
402
- * ```
403
- *
404
- * @group Parametric Assertions (Sync)
405
- */
406
- export const errorMessageAssertion = createAssertion([ErrorSchema, 'to have message', StringSchema], (subject, expectedMessage) => {
407
- if (subject.message !== expectedMessage) {
408
- return {
409
- actual: subject.message,
410
- expected: expectedMessage,
411
- message: `Expected error message "${subject.message}" to equal "${expectedMessage}"`,
412
- };
413
- }
414
- });
415
- /**
416
- * Assertion for testing if an Error has a message matching a regular
417
- * expression.
418
- *
419
- * @example
420
- *
421
- * ```typescript
422
- * expect(
423
- * new Error('Error: something went wrong'),
424
- * 'to have message matching',
425
- * /something/,
426
- * ); // passes
427
- * expect(new Error('All good'), 'to have message matching', /error/i); // fails
428
- * ```
429
- *
430
- * @group Parametric Assertions (Sync)
431
- */
432
- export const errorMessageMatchingAssertion = createAssertion([ErrorSchema, 'to have message matching', RegExpSchema], (subject, pattern) => {
433
- if (!pattern.test(subject.message)) {
434
- return {
435
- message: `Expected error message "${subject.message}" to match ${pattern}`,
436
- };
437
- }
438
- });
439
- /**
440
- * Assertion for testing strict equality between two values.
441
- *
442
- * @example
443
- *
444
- * ```typescript
445
- * expect(42, 'to be', 42); // passes
446
- * expect('hello', 'to equal', 'hello'); // passes
447
- * expect({}, 'to be', {}); // fails (different object references)
448
- * ```
449
- *
450
- * @group Parametric Assertions (Sync)
451
- */
452
- export const strictEqualityAssertion = createAssertion([
453
- [
454
- 'to be',
455
- 'to equal',
456
- 'equals',
457
- 'is',
458
- 'is equal to',
459
- 'to strictly equal',
460
- 'is strictly equal to',
461
- ],
462
- UnknownSchema,
463
- ], (subject, value) => {
464
- if (subject !== value) {
465
- return {
466
- actual: subject,
467
- expected: value,
468
- message: `Expected ${inspect(subject)} to equal ${inspect(value)}`,
469
- };
470
- }
471
- });
472
- /**
473
- * Assertion for testing deep equality between any values.
474
- *
475
- * Works with primitives, objects, arrays, Maps, Sets, and other types.
476
- *
477
- * @example
478
- *
479
- * ```typescript
480
- * // Primitives
481
- * expect(42, 'to deep equal', 42); // passes
482
- * expect('hello', 'to deeply equal', 'world'); // fails
483
- *
484
- * // Objects
485
- * expect({ a: 1, b: 2 }, 'to deep equal', { a: 1, b: 2 }); // passes
486
- * expect({ a: 1 }, 'to deeply equal', { a: 1, b: 2 }); // fails
487
- *
488
- * // Arrays
489
- * expect([1, 2, 3], 'to deep equal', [1, 2, 3]); // passes
490
- *
491
- * // Maps and Sets
492
- * expect(new Map([['a', 1]]), 'to deep equal', new Map([['a', 1]])); // passes
493
- * expect(new Set([1, 2]), 'to deeply equal', new Set([1, 2])); // passes
494
- * ```
495
- *
496
- * @group Parametric Assertions (Sync)
497
- * @bupkisAnchor unknown-to-deep-equal-any
498
- * @bupkisAssertionCategory equality
499
- */
500
- export const deepEqualAssertion = createAssertion([['to deep equal', 'to deeply equal'], UnknownSchema], (_, expected) => valueToSchema(expected, valueToSchemaOptionsForDeepEqual));
501
- /**
502
- * Assertion for testing if a function throws an error when called.
503
- *
504
- * @example
505
- *
506
- * ```typescript
507
- * expect(() => {
508
- * throw new Error('oops');
509
- * }, 'to throw'); // passes
510
- * expect(() => 'hello', 'to throw'); // fails
511
- * ```
512
- *
513
- * @group Parametric Assertions (Sync)
514
- * @bupkisAnchor function-to-throw-any
515
- * @bupkisAssertionCategory function
516
- * @bupkisRedirect to-throw
517
- */
518
- export const functionThrowsAssertion = createAssertion([FunctionSchema, 'to throw'], (subject) => {
519
- const { error, result } = trapError(subject);
520
- if (error === undefined) {
521
- return {
522
- message: `Expected function to throw, but it fulfilled with ${inspect(result)}`,
523
- };
524
- }
525
- });
526
- /**
527
- * Assertion for testing if a function throws an error of a specific type.
528
- *
529
- * @example
530
- *
531
- * ```typescript
532
- * expect(
533
- * () => {
534
- * throw new TypeError('wrong type');
535
- * },
536
- * 'to throw a',
537
- * TypeError,
538
- * ); // passes
539
- * expect(
540
- * () => {
541
- * throw new Error('oops');
542
- * },
543
- * 'to throw an',
544
- * TypeError,
545
- * ); // fails
546
- * ```
547
- *
548
- * @group Parametric Assertions (Sync)
549
- */
550
- export const functionThrowsTypeAssertion = createAssertion([FunctionSchema, ['to throw a', 'to throw an'], ConstructibleSchema], (subject, ctor) => {
551
- const { error, result } = trapError(subject);
552
- if (error === undefined) {
553
- return {
554
- message: `Expected function to throw, but fulfilled with ${inspect(result)}`,
555
- };
556
- }
557
- if (!isA(error, ctor)) {
558
- if (isNonNullObject(error)) {
559
- const err = error;
560
- return {
561
- actual: err.constructor.name,
562
- expected: ctor.name,
563
- message: `Expected function to throw with an instance of ${ctor.name}, but it threw with a ${err.constructor.name}`,
564
- };
565
- }
566
- return {
567
- actual: typeof error,
568
- expected: ctor.name,
569
- message: `Expected function to throw with an instance of ${ctor.name}, but it threw a value of type ${typeof error}: ${inspect(error)}`,
570
- };
571
- }
572
- });
573
- /**
574
- * Assertion for testing if a function throws an error matching specific
575
- * criteria.
576
- *
577
- * @example
578
- *
579
- * ```typescript
580
- * expect(
581
- * () => {
582
- * throw new Error('oops');
583
- * },
584
- * 'to throw',
585
- * 'oops',
586
- * ); // passes
587
- * expect(
588
- * () => {
589
- * throw new Error('fail');
590
- * },
591
- * 'to throw',
592
- * /error/i,
593
- * ); // passes
594
- * expect(
595
- * () => {
596
- * throw new Error('oops');
597
- * },
598
- * 'to throw',
599
- * { message: 'oops' },
600
- * ); // passes
601
- * ```
602
- *
603
- * @group Parametric Assertions (Sync)
604
- */
605
- export const functionThrowsSatisfyingAssertion = createAssertion([FunctionSchema, ['to throw', 'to throw error satisfying'], UnknownSchema], (subject, param) => {
606
- const { error } = trapError(subject);
607
- if (error === undefined) {
608
- return {
609
- message: 'Expected function to throw, but it did not',
610
- };
611
- }
612
- if (isString(param)) {
613
- return {
614
- schema: createErrorMessageSchema(param),
615
- subject: error,
616
- };
617
- }
618
- else if (isA(param, RegExp)) {
619
- return {
620
- schema: createErrorMessageRegexSchema(param),
621
- subject: error,
622
- };
623
- }
624
- else {
625
- const schema = valueToSchema(param, valueToSchemaOptionsForSatisfies);
626
- return { schema, subject: error };
627
- }
628
- });
629
- /**
630
- * Assertion for testing if a function throws an error of a specific type that
631
- * also matches criteria.
632
- *
633
- * @example
634
- *
635
- * ```typescript
636
- * expect(
637
- * () => {
638
- * throw new TypeError('wrong type');
639
- * },
640
- * 'to throw a',
641
- * TypeError,
642
- * 'satisfying',
643
- * { message: 'wrong type' },
644
- * ); // passes
645
- * expect(
646
- * () => {
647
- * throw new Error('oops');
648
- * },
649
- * 'to throw an',
650
- * TypeError,
651
- * 'satisfying',
652
- * /type/,
653
- * ); // fails
654
- * ```
655
- *
656
- * @group Parametric Assertions (Sync)
657
- */
658
- export const functionThrowsTypeSatisfyingAssertion = createAssertion([
659
- FunctionSchema,
660
- ['to throw a', 'to throw an'],
661
- ConstructibleSchema,
662
- 'satisfying',
663
- UnknownSchema,
664
- ], (subject, ctor, param) => {
665
- const { error, result } = trapError(subject);
666
- if (error === undefined) {
667
- return {
668
- message: `Expected function to throw, but it fulfilled with ${inspect(result)}`,
669
- };
670
- }
671
- if (!isA(error, ctor)) {
672
- return {
673
- message: isError(error)
674
- ? `Expected function to throw an instance of ${ctor.name}, but it threw ${error.constructor.name}`
675
- : `Expected function to throw an instance of ${ctor.name}, but it threw a non-object value: ${inspect(error)}`,
676
- };
677
- }
678
- let schema;
679
- if (isString(param)) {
680
- schema = createErrorMessageSchema(param);
681
- }
682
- else if (isA(param, RegExp)) {
683
- schema = createErrorMessageRegexSchema(param);
684
- }
685
- else {
686
- schema = valueToSchema(param, valueToSchemaOptionsForSatisfies);
687
- }
688
- return {
689
- schema,
690
- subject: error,
691
- };
692
- });
693
- /**
694
- * Assertion for testing if a string includes/contains another string.
695
- *
696
- * @example
697
- *
698
- * ```typescript
699
- * expect('hello world', 'includes', 'world'); // passes
700
- * expect('hello world', 'contains', 'foo'); // fails
701
- * expect('hello world', 'to include', 'hello'); // passes
702
- * expect('hello world', 'to contain', 'bar'); // fails
703
- * ```
704
- *
705
- * @group Parametric Assertions (Sync)
706
- */
707
- export const stringIncludesAssertion = createAssertion([
708
- StringSchema,
709
- ['includes', 'contains', 'to include', 'to contain'],
710
- StringSchema,
711
- ], (subject, expected) => {
712
- if (!subject.includes(expected)) {
713
- return {
714
- message: `Expected "${subject}" to include "${expected}"`,
715
- };
716
- }
717
- });
718
- /**
719
- * Assertion for testing if a string matches a regular expression.
720
- *
721
- * @example
722
- *
723
- * ```typescript
724
- * expect('hello123', 'to match', /\d+/); // passes
725
- * expect('hello', 'to match', /\d+/); // fails
726
- * ```
727
- *
728
- * @group Parametric Assertions (Sync)
729
- */
730
- export const stringMatchesAssertion = createAssertion([StringSchema, 'to match', RegExpSchema], (subject, regex) => regex.test(subject));
731
- /**
732
- * Assertion for testing if a string has a specific length.
733
- *
734
- * @example
735
- *
736
- * ```typescript
737
- * expect('hello', 'to have length', 5); // passes
738
- * expect('hi', 'to have length', 5); // fails
739
- * ```
740
- *
741
- * @group Parametric Assertions (Sync)
742
- * @bupkisAnchor string-to-have-length
743
- * @bupkisAssertionCategory strings
744
- */
745
- export const stringLengthAssertion = createAssertion([StringSchema, 'to have length', NonNegativeIntegerSchema],
746
- // StringSchema.length() produces a ZodError with a string diff (e.g., "hel"
747
- // vs "hello") rather than comparing numeric lengths, which is confusing
748
- (subject, expectedLength) => {
749
- if (subject.length !== expectedLength) {
750
- return {
751
- actual: subject.length,
752
- expected: expectedLength,
753
- message: `Expected string to have length ${expectedLength}, but it has length ${subject.length}`,
754
- };
755
- }
756
- });
757
- /**
758
- * Assertion for testing if a value satisfies a pattern or shape.
759
- *
760
- * Works with any value type: primitives, objects, arrays, or cross-type checks.
761
- * Uses partial matching semantics - extra properties are allowed in objects.
762
- *
763
- * @example
764
- *
765
- * ```typescript
766
- * // Primitives
767
- * expect(42, 'to satisfy', 42); // passes
768
- * expect('hello', 'satisfies', 'hello'); // passes
769
- *
770
- * // Objects (partial matching)
771
- * expect({ name: 'John', age: 30 }, 'to satisfy', { name: 'John' }); // passes
772
- * expect({ name: 'John' }, 'to be like', { name: 'John', age: 30 }); // fails
773
- *
774
- * // Arrays
775
- * expect([1, 2, 3], 'to satisfy', [1, 2, 3]); // passes
776
- *
777
- * // Cross-type satisfaction
778
- * expect([1, 2, 3], 'to satisfy', { length: 3 }); // passes
779
- * ```
780
- *
781
- * @group Parametric Assertions (Sync)
782
- * @bupkisAnchor unknown-to-satisfy-any
783
- * @bupkisAssertionCategory equality
784
- */
785
- export const satisfiesAssertion = createAssertion([['to satisfy', 'to be like', 'satisfies'], UnknownSchema], (_subject, shape) => valueToSchema(shape, valueToSchemaOptionsForSatisfies));
786
- /**
787
- * Memoizes {@link createInstanceOfSchema}
788
- */
789
- const createInstanceOfSchemaCache = new WeakMap();
790
- /**
791
- * @function
792
- */
793
- const createInstanceOfSchema = (ctor) => {
794
- const cached = createInstanceOfSchemaCache.get(ctor);
795
- if (cached) {
796
- return cached;
797
- }
798
- const schema = z.instanceof(ctor);
799
- createInstanceOfSchemaCache.set(ctor, schema);
800
- return schema;
801
- };
802
- //# sourceMappingURL=sync-parametric.js.map