@kensio/smartass 1.16.0 → 1.17.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.
- package/dist/assert/array-includes/array-includes.assert.d.ts +3 -8
- package/dist/assert/array-includes/array-includes.assert.d.ts.map +1 -1
- package/dist/assert/array-includes/array-includes.assert.js.map +1 -1
- package/dist/assert/array-includes/array-includes.match.d.ts +1 -6
- package/dist/assert/array-includes/array-includes.match.d.ts.map +1 -1
- package/dist/assert/array-includes/array-includes.match.js +7 -1
- package/dist/assert/array-includes/array-includes.match.js.map +1 -1
- package/dist/assert/array-includes/array-includes.type.d.ts +44 -0
- package/dist/assert/array-includes/array-includes.type.d.ts.map +1 -0
- package/dist/assert/array-includes/array-includes.type.js +8 -0
- package/dist/assert/array-includes/array-includes.type.js.map +1 -0
- package/dist/assert/array-includes-all/array-includes-all.assert.d.ts +3 -7
- package/dist/assert/array-includes-all/array-includes-all.assert.d.ts.map +1 -1
- package/dist/assert/array-includes-all/array-includes-all.assert.js +27 -5
- package/dist/assert/array-includes-all/array-includes-all.assert.js.map +1 -1
- package/dist/assert/array-includes-all/array-includes-all.match.d.ts +3 -8
- package/dist/assert/array-includes-all/array-includes-all.match.d.ts.map +1 -1
- package/dist/assert/array-includes-all/array-includes-all.match.js +16 -3
- package/dist/assert/array-includes-all/array-includes-all.match.js.map +1 -1
- package/dist/assert/array-includes-all/array-includes-all.type.d.ts +51 -0
- package/dist/assert/array-includes-all/array-includes-all.type.d.ts.map +1 -0
- package/dist/assert/array-includes-all/array-includes-all.type.js +2 -0
- package/dist/assert/array-includes-all/array-includes-all.type.js.map +1 -0
- package/dist/assert/array-length/array-length.assert.d.ts +3 -9
- package/dist/assert/array-length/array-length.assert.d.ts.map +1 -1
- package/dist/assert/array-length/array-length.assert.js +7 -4
- package/dist/assert/array-length/array-length.assert.js.map +1 -1
- package/dist/assert/array-length/array-length.match.d.ts +1 -9
- package/dist/assert/array-length/array-length.match.d.ts.map +1 -1
- package/dist/assert/array-length/array-length.match.js +8 -2
- package/dist/assert/array-length/array-length.match.js.map +1 -1
- package/dist/assert/array-length/array-length.type.d.ts +37 -0
- package/dist/assert/array-length/array-length.type.d.ts.map +1 -0
- package/dist/assert/array-length/array-length.type.js +8 -0
- package/dist/assert/array-length/array-length.type.js.map +1 -0
- package/dist/assert/array-min-length/array-min-length.assert.d.ts +3 -9
- package/dist/assert/array-min-length/array-min-length.assert.d.ts.map +1 -1
- package/dist/assert/array-min-length/array-min-length.assert.js +10 -6
- package/dist/assert/array-min-length/array-min-length.assert.js.map +1 -1
- package/dist/assert/array-min-length/array-min-length.match.d.ts +1 -3
- package/dist/assert/array-min-length/array-min-length.match.d.ts.map +1 -1
- package/dist/assert/array-min-length/array-min-length.match.js +7 -1
- package/dist/assert/array-min-length/array-min-length.match.js.map +1 -1
- package/dist/assert/array-min-length/array-min-length.type.d.ts +35 -0
- package/dist/assert/array-min-length/array-min-length.type.d.ts.map +1 -0
- package/dist/assert/array-min-length/array-min-length.type.js +8 -0
- package/dist/assert/array-min-length/array-min-length.type.js.map +1 -0
- package/dist/assert/array-not-empty/array-not-empty.assert.d.ts +3 -5
- package/dist/assert/array-not-empty/array-not-empty.assert.d.ts.map +1 -1
- package/dist/assert/array-not-empty/array-not-empty.assert.js +8 -3
- package/dist/assert/array-not-empty/array-not-empty.assert.js.map +1 -1
- package/dist/assert/array-not-empty/array-not-empty.match.d.ts +1 -3
- package/dist/assert/array-not-empty/array-not-empty.match.d.ts.map +1 -1
- package/dist/assert/array-not-empty/array-not-empty.match.js +7 -1
- package/dist/assert/array-not-empty/array-not-empty.match.js.map +1 -1
- package/dist/assert/array-not-empty/array-not-empty.type.d.ts +35 -0
- package/dist/assert/array-not-empty/array-not-empty.type.d.ts.map +1 -0
- package/dist/assert/array-not-empty/array-not-empty.type.js +8 -0
- package/dist/assert/array-not-empty/array-not-empty.type.js.map +1 -0
- package/dist/assert/buffer-equal/buffer-equal.assert.d.ts +1 -1
- package/dist/assert/buffer-equal/buffer-equal.assert.d.ts.map +1 -1
- package/dist/assert/buffer-equal/buffer-equal.assert.js.map +1 -1
- package/dist/assert/buffer-equal/buffer-equal.match.d.ts +3 -3
- package/dist/assert/buffer-equal/buffer-equal.match.d.ts.map +1 -1
- package/dist/assert/buffer-equal/buffer-equal.match.js +20 -11
- package/dist/assert/buffer-equal/buffer-equal.match.js.map +1 -1
- package/dist/assert/buffer-equal/buffer-equal.type.d.ts +32 -0
- package/dist/assert/buffer-equal/buffer-equal.type.d.ts.map +1 -0
- package/dist/assert/buffer-equal/buffer-equal.type.js +8 -0
- package/dist/assert/buffer-equal/buffer-equal.type.js.map +1 -0
- package/dist/assert/identical/identical.assert.d.ts +1 -1
- package/dist/assert/identical/identical.assert.d.ts.map +1 -1
- package/dist/assert/instance-of/instance-of.assert.d.ts +3 -5
- package/dist/assert/instance-of/instance-of.assert.d.ts.map +1 -1
- package/dist/assert/instance-of/instance-of.assert.js.map +1 -1
- package/dist/assert/instance-of/instance-of.match.d.ts +2 -3
- package/dist/assert/instance-of/instance-of.match.d.ts.map +1 -1
- package/dist/assert/instance-of/instance-of.match.js +7 -1
- package/dist/assert/instance-of/instance-of.match.js.map +1 -1
- package/dist/assert/instance-of/instance-of.type.d.ts +42 -0
- package/dist/assert/instance-of/instance-of.type.d.ts.map +1 -0
- package/dist/assert/instance-of/instance-of.type.js +8 -0
- package/dist/assert/instance-of/instance-of.type.js.map +1 -0
- package/dist/assert/map-size/map-size.assert.d.ts +4 -0
- package/dist/assert/map-size/map-size.assert.d.ts.map +1 -0
- package/dist/assert/map-size/map-size.assert.js +19 -0
- package/dist/assert/map-size/map-size.assert.js.map +1 -0
- package/dist/assert/map-size/map-size.match.d.ts +6 -0
- package/dist/assert/map-size/map-size.match.d.ts.map +1 -0
- package/dist/assert/map-size/map-size.match.js +15 -0
- package/dist/assert/map-size/map-size.match.js.map +1 -0
- package/dist/assert/map-size/map-size.type.d.ts +33 -0
- package/dist/assert/map-size/map-size.type.d.ts.map +1 -0
- package/dist/assert/map-size/map-size.type.js +8 -0
- package/dist/assert/map-size/map-size.type.js.map +1 -0
- package/dist/assert/non-nullable/non-nullable.match.d.ts +2 -2
- package/dist/assert/non-nullable/non-nullable.match.d.ts.map +1 -1
- package/dist/assert/non-nullable/non-nullable.match.js.map +1 -1
- package/dist/assert/non-nullable/non-nullable.type.d.ts +5 -0
- package/dist/assert/non-nullable/non-nullable.type.d.ts.map +1 -0
- package/dist/assert/non-nullable/non-nullable.type.js +2 -0
- package/dist/assert/non-nullable/non-nullable.type.js.map +1 -0
- package/dist/assert/number-to-nearest/number-to-nearest.assert.d.ts +1 -1
- package/dist/assert/number-to-nearest/number-to-nearest.assert.d.ts.map +1 -1
- package/dist/assert/number-to-nearest/number-to-nearest.assert.js +2 -2
- package/dist/assert/number-to-nearest/number-to-nearest.assert.js.map +1 -1
- package/dist/assert/number-to-nearest/number-to-nearest.match.d.ts +1 -1
- package/dist/assert/number-to-nearest/number-to-nearest.match.d.ts.map +1 -1
- package/dist/assert/number-to-nearest/number-to-nearest.match.js +1 -1
- package/dist/assert/number-to-nearest/number-to-nearest.match.js.map +1 -1
- package/dist/assert/object-has-property/object-has-property.assert.d.ts +3 -6
- package/dist/assert/object-has-property/object-has-property.assert.d.ts.map +1 -1
- package/dist/assert/object-has-property/object-has-property.assert.js +1 -1
- package/dist/assert/object-has-property/object-has-property.assert.js.map +1 -1
- package/dist/assert/object-has-property/object-has-property.match.d.ts +1 -7
- package/dist/assert/object-has-property/object-has-property.match.d.ts.map +1 -1
- package/dist/assert/object-has-property/object-has-property.match.js +1 -1
- package/dist/assert/object-has-property/object-has-property.match.js.map +1 -1
- package/dist/assert/object-has-property/object-has-property.type.d.ts +8 -0
- package/dist/assert/object-has-property/object-has-property.type.d.ts.map +1 -0
- package/dist/assert/object-has-property/object-has-property.type.js +2 -0
- package/dist/assert/object-has-property/object-has-property.type.js.map +1 -0
- package/dist/assert/object-matches/object-matches.assert.d.ts +1 -28
- package/dist/assert/object-matches/object-matches.assert.d.ts.map +1 -1
- package/dist/assert/object-matches/object-matches.assert.js.map +1 -1
- package/dist/assert/object-matches/object-matches.type.d.ts +155 -0
- package/dist/assert/object-matches/object-matches.type.d.ts.map +1 -0
- package/dist/assert/object-matches/object-matches.type.js +2 -0
- package/dist/assert/object-matches/object-matches.type.js.map +1 -0
- package/dist/assert/one-of/one-of.assert.d.ts +5 -3
- package/dist/assert/one-of/one-of.assert.d.ts.map +1 -1
- package/dist/assert/one-of/one-of.assert.js.map +1 -1
- package/dist/assert/one-of/one-of.match.d.ts +2 -2
- package/dist/assert/one-of/one-of.match.d.ts.map +1 -1
- package/dist/assert/one-of/one-of.match.js +7 -1
- package/dist/assert/one-of/one-of.match.js.map +1 -1
- package/dist/assert/one-of/one-of.type.d.ts +33 -0
- package/dist/assert/one-of/one-of.type.d.ts.map +1 -0
- package/dist/assert/one-of/one-of.type.js +8 -0
- package/dist/assert/one-of/one-of.type.js.map +1 -0
- package/dist/assert/string-ends-with/string-ends-with.assert.d.ts +3 -4
- package/dist/assert/string-ends-with/string-ends-with.assert.d.ts.map +1 -1
- package/dist/assert/string-ends-with/string-ends-with.assert.js.map +1 -1
- package/dist/assert/string-ends-with/string-ends-with.match.d.ts +2 -2
- package/dist/assert/string-ends-with/string-ends-with.match.d.ts.map +1 -1
- package/dist/assert/string-ends-with/string-ends-with.match.js +7 -1
- package/dist/assert/string-ends-with/string-ends-with.match.js.map +1 -1
- package/dist/assert/string-ends-with/string-ends-with.type.d.ts +39 -0
- package/dist/assert/string-ends-with/string-ends-with.type.d.ts.map +1 -0
- package/dist/assert/string-ends-with/string-ends-with.type.js +8 -0
- package/dist/assert/string-ends-with/string-ends-with.type.js.map +1 -0
- package/dist/assert/string-includes/string-includes.assert.d.ts +3 -4
- package/dist/assert/string-includes/string-includes.assert.d.ts.map +1 -1
- package/dist/assert/string-includes/string-includes.assert.js.map +1 -1
- package/dist/assert/string-includes/string-includes.match.d.ts +2 -2
- package/dist/assert/string-includes/string-includes.match.d.ts.map +1 -1
- package/dist/assert/string-includes/string-includes.match.js +7 -1
- package/dist/assert/string-includes/string-includes.match.js.map +1 -1
- package/dist/assert/string-includes/string-includes.type.d.ts +39 -0
- package/dist/assert/string-includes/string-includes.type.d.ts.map +1 -0
- package/dist/assert/string-includes/string-includes.type.js +8 -0
- package/dist/assert/string-includes/string-includes.type.js.map +1 -0
- package/dist/assert/string-length/string-length.assert.d.ts +3 -14
- package/dist/assert/string-length/string-length.assert.d.ts.map +1 -1
- package/dist/assert/string-length/string-length.assert.js +7 -2
- package/dist/assert/string-length/string-length.assert.js.map +1 -1
- package/dist/assert/string-length/string-length.match.d.ts +1 -93
- package/dist/assert/string-length/string-length.match.d.ts.map +1 -1
- package/dist/assert/string-length/string-length.match.js +8 -2
- package/dist/assert/string-length/string-length.match.js.map +1 -1
- package/dist/assert/string-length/string-length.type.d.ts +132 -0
- package/dist/assert/string-length/string-length.type.d.ts.map +1 -0
- package/dist/assert/string-length/string-length.type.js +8 -0
- package/dist/assert/string-length/string-length.type.js.map +1 -0
- package/dist/assert/string-not-includes/string-not-includes.assert.d.ts +4 -4
- package/dist/assert/string-not-includes/string-not-includes.assert.d.ts.map +1 -1
- package/dist/assert/string-not-includes/string-not-includes.assert.js +7 -2
- package/dist/assert/string-not-includes/string-not-includes.assert.js.map +1 -1
- package/dist/assert/string-not-includes/string-not-includes.match.d.ts +2 -2
- package/dist/assert/string-not-includes/string-not-includes.match.d.ts.map +1 -1
- package/dist/assert/string-not-includes/string-not-includes.match.js +8 -2
- package/dist/assert/string-not-includes/string-not-includes.match.js.map +1 -1
- package/dist/assert/string-not-includes/string-not-includes.type.d.ts +30 -0
- package/dist/assert/string-not-includes/string-not-includes.type.d.ts.map +1 -0
- package/dist/assert/string-not-includes/string-not-includes.type.js +8 -0
- package/dist/assert/string-not-includes/string-not-includes.type.js.map +1 -0
- package/dist/assert/string-starts-with/string-starts-with.assert.d.ts +4 -4
- package/dist/assert/string-starts-with/string-starts-with.assert.d.ts.map +1 -1
- package/dist/assert/string-starts-with/string-starts-with.assert.js +7 -2
- package/dist/assert/string-starts-with/string-starts-with.assert.js.map +1 -1
- package/dist/assert/string-starts-with/string-starts-with.match.d.ts +2 -2
- package/dist/assert/string-starts-with/string-starts-with.match.d.ts.map +1 -1
- package/dist/assert/string-starts-with/string-starts-with.match.js +7 -1
- package/dist/assert/string-starts-with/string-starts-with.match.js.map +1 -1
- package/dist/assert/string-starts-with/string-starts-with.type.d.ts +39 -0
- package/dist/assert/string-starts-with/string-starts-with.type.d.ts.map +1 -0
- package/dist/assert/string-starts-with/string-starts-with.type.js +8 -0
- package/dist/assert/string-starts-with/string-starts-with.type.js.map +1 -0
- package/dist/assert/throws-error-like/throws-error-like.assert.d.ts +1 -5
- package/dist/assert/throws-error-like/throws-error-like.assert.d.ts.map +1 -1
- package/dist/assert/throws-error-like/throws-error-like.assert.js.map +1 -1
- package/dist/assert/throws-error-like/throws-error-like.type.d.ts +6 -0
- package/dist/assert/throws-error-like/throws-error-like.type.d.ts.map +1 -0
- package/dist/assert/throws-error-like/throws-error-like.type.js +2 -0
- package/dist/assert/throws-error-like/throws-error-like.type.js.map +1 -0
- package/dist/assert/type-bigint/type-bigint.match.d.ts +2 -2
- package/dist/assert/type-bigint/type-bigint.match.d.ts.map +1 -1
- package/dist/assert/type-bigint/type-bigint.match.js.map +1 -1
- package/dist/assert/type-bigint/type-bigint.type.d.ts +21 -0
- package/dist/assert/type-bigint/type-bigint.type.d.ts.map +1 -0
- package/dist/assert/type-bigint/type-bigint.type.js +2 -0
- package/dist/assert/type-bigint/type-bigint.type.js.map +1 -0
- package/dist/assert/type-boolean/type-boolean.match.d.ts +2 -2
- package/dist/assert/type-boolean/type-boolean.match.d.ts.map +1 -1
- package/dist/assert/type-boolean/type-boolean.match.js +7 -1
- package/dist/assert/type-boolean/type-boolean.match.js.map +1 -1
- package/dist/assert/type-boolean/type-boolean.type.d.ts +30 -0
- package/dist/assert/type-boolean/type-boolean.type.d.ts.map +1 -0
- package/dist/assert/type-boolean/type-boolean.type.js +9 -0
- package/dist/assert/type-boolean/type-boolean.type.js.map +1 -0
- package/dist/assert/type-function/type-function.assert.d.ts.map +1 -1
- package/dist/assert/type-function/type-function.assert.js.map +1 -1
- package/dist/assert/type-function/type-function.match.d.ts +2 -2
- package/dist/assert/type-function/type-function.match.d.ts.map +1 -1
- package/dist/assert/type-function/type-function.match.js +7 -4
- package/dist/assert/type-function/type-function.match.js.map +1 -1
- package/dist/assert/type-function/type-function.type.d.ts +29 -0
- package/dist/assert/type-function/type-function.type.d.ts.map +1 -0
- package/dist/assert/type-function/type-function.type.js +8 -0
- package/dist/assert/type-function/type-function.type.js.map +1 -0
- package/dist/assert/type-number/type-number.match.d.ts +2 -2
- package/dist/assert/type-number/type-number.match.d.ts.map +1 -1
- package/dist/assert/type-number/type-number.match.js +7 -1
- package/dist/assert/type-number/type-number.match.js.map +1 -1
- package/dist/assert/type-number/type-number.type.d.ts +30 -0
- package/dist/assert/type-number/type-number.type.d.ts.map +1 -0
- package/dist/assert/type-number/type-number.type.js +9 -0
- package/dist/assert/type-number/type-number.type.js.map +1 -0
- package/dist/assert/type-numeric/type-numeric.match.d.ts +2 -2
- package/dist/assert/type-numeric/type-numeric.match.d.ts.map +1 -1
- package/dist/assert/type-numeric/type-numeric.match.js +7 -1
- package/dist/assert/type-numeric/type-numeric.match.js.map +1 -1
- package/dist/assert/type-numeric/type-numeric.type.d.ts +33 -0
- package/dist/assert/type-numeric/type-numeric.type.d.ts.map +1 -0
- package/dist/assert/type-numeric/type-numeric.type.js +9 -0
- package/dist/assert/type-numeric/type-numeric.type.js.map +1 -0
- package/dist/assert/type-object/type-object.match.d.ts +2 -2
- package/dist/assert/type-object/type-object.match.d.ts.map +1 -1
- package/dist/assert/type-object/type-object.match.js +7 -1
- package/dist/assert/type-object/type-object.match.js.map +1 -1
- package/dist/assert/type-object/type-object.type.d.ts +33 -0
- package/dist/assert/type-object/type-object.type.d.ts.map +1 -0
- package/dist/assert/type-object/type-object.type.js +8 -0
- package/dist/assert/type-object/type-object.type.js.map +1 -0
- package/dist/assert/type-string/type-string.match.d.ts +2 -2
- package/dist/assert/type-string/type-string.match.d.ts.map +1 -1
- package/dist/assert/type-string/type-string.match.js +7 -1
- package/dist/assert/type-string/type-string.match.js.map +1 -1
- package/dist/assert/type-string/type-string.type.d.ts +30 -0
- package/dist/assert/type-string/type-string.type.d.ts.map +1 -0
- package/dist/assert/type-string/type-string.type.js +9 -0
- package/dist/assert/type-string/type-string.type.js.map +1 -0
- package/dist/assert/type-symbol/type-symbol.assert.d.ts +5 -0
- package/dist/assert/type-symbol/type-symbol.assert.d.ts.map +1 -0
- package/dist/assert/type-symbol/type-symbol.assert.js +13 -0
- package/dist/assert/type-symbol/type-symbol.assert.js.map +1 -0
- package/dist/assert/type-symbol/type-symbol.match.d.ts +6 -0
- package/dist/assert/type-symbol/type-symbol.match.d.ts.map +1 -0
- package/dist/assert/type-symbol/type-symbol.match.js +14 -0
- package/dist/assert/type-symbol/type-symbol.match.js.map +1 -0
- package/dist/assert/type-symbol/type-symbol.type.d.ts +30 -0
- package/dist/assert/type-symbol/type-symbol.type.d.ts.map +1 -0
- package/dist/assert/type-symbol/type-symbol.type.js +9 -0
- package/dist/assert/type-symbol/type-symbol.type.js.map +1 -0
- package/dist/assert/type-typed-array/type-typed-array.assert.d.ts +1 -1
- package/dist/assert/type-typed-array/type-typed-array.assert.d.ts.map +1 -1
- package/dist/assert/type-typed-array/type-typed-array.assert.js.map +1 -1
- package/dist/assert/type-typed-array/type-typed-array.match.d.ts +2 -6
- package/dist/assert/type-typed-array/type-typed-array.match.d.ts.map +1 -1
- package/dist/assert/type-typed-array/type-typed-array.match.js +7 -1
- package/dist/assert/type-typed-array/type-typed-array.match.js.map +1 -1
- package/dist/assert/type-typed-array/type-typed-array.type.d.ts +33 -0
- package/dist/assert/type-typed-array/type-typed-array.type.d.ts.map +1 -0
- package/dist/assert/type-typed-array/type-typed-array.type.js +8 -0
- package/dist/assert/type-typed-array/type-typed-array.type.js.map +1 -0
- package/dist/assert/uuid/uuid-v4.assert.d.ts +2 -4
- package/dist/assert/uuid/uuid-v4.assert.d.ts.map +1 -1
- package/dist/assert/uuid/uuid-v4.assert.js +2 -2
- package/dist/assert/uuid/uuid-v4.assert.js.map +1 -1
- package/dist/assert/uuid/uuid-v4.match.d.ts +2 -4
- package/dist/assert/uuid/uuid-v4.match.d.ts.map +1 -1
- package/dist/assert/uuid/uuid-v4.match.js +7 -1
- package/dist/assert/uuid/uuid-v4.match.js.map +1 -1
- package/dist/assert/uuid/uuid-v4.type.d.ts +34 -0
- package/dist/assert/uuid/uuid-v4.type.d.ts.map +1 -0
- package/dist/assert/uuid/uuid-v4.type.js +8 -0
- package/dist/assert/uuid/uuid-v4.type.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/match/match.d.ts +37 -1
- package/dist/match/match.d.ts.map +1 -1
- package/dist/match/match.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AssertionMatcher, refinement } from "../../match/match.js";
|
|
2
|
+
/**
|
|
3
|
+
* Unique symbol to reliably identify the OneOfMatcher type.
|
|
4
|
+
*
|
|
5
|
+
* TypeScript is structurally typed, so matcher types with similar predicates
|
|
6
|
+
* can otherwise accidentally satisfy each other's conditional branches.
|
|
7
|
+
*/
|
|
8
|
+
export declare const oneOfMatcher: unique symbol;
|
|
9
|
+
type OneOfElement<TAllowed extends readonly unknown[]> = TAllowed[number];
|
|
10
|
+
/**
|
|
11
|
+
* Type produced when an actual value is matched by oneOf().
|
|
12
|
+
*
|
|
13
|
+
* The primary goal is to expose clean, readable user-facing types in IDE
|
|
14
|
+
* tooltips and TypeScript errors. When the calling scope already has overlap
|
|
15
|
+
* with the allowed values, we preserve that overlap. Otherwise, we fall back to
|
|
16
|
+
* the allowed value union.
|
|
17
|
+
*/
|
|
18
|
+
export type OneOfMatch<TActual, TAllowed extends readonly unknown[]> = [
|
|
19
|
+
Extract<TActual, OneOfElement<TAllowed>>
|
|
20
|
+
] extends [never] ? OneOfElement<TAllowed> : Extract<TActual, OneOfElement<TAllowed>>;
|
|
21
|
+
export type OneOfMatcher<TAllowed extends readonly unknown[]> = AssertionMatcher<OneOfElement<TAllowed>> & {
|
|
22
|
+
readonly [oneOfMatcher]: TAllowed;
|
|
23
|
+
/**
|
|
24
|
+
* Optional type-level hook used by compositional assertions such as
|
|
25
|
+
* assertObjectMatches().
|
|
26
|
+
*
|
|
27
|
+
* This lets the matcher describe how it refines an existing actual type,
|
|
28
|
+
* rather than only exposing the standalone matches() predicate type.
|
|
29
|
+
*/
|
|
30
|
+
readonly [refinement]?: <TActual>(actual: TActual) => OneOfMatch<TActual, TAllowed>;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=one-of.type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"one-of.type.d.ts","sourceRoot":"","sources":["../../../src/assert/one-of/one-of.type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEzE;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAkC,CAAC;AAE5D,KAAK,YAAY,CAAC,QAAQ,SAAS,SAAS,OAAO,EAAE,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;AAE1E;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,CAAC,OAAO,EAAE,QAAQ,SAAS,SAAS,OAAO,EAAE,IAAI;IACrE,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;CACzC,SAAS,CAAC,KAAK,CAAC,GACb,YAAY,CAAC,QAAQ,CAAC,GACtB,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;AAE7C,MAAM,MAAM,YAAY,CAAC,QAAQ,SAAS,SAAS,OAAO,EAAE,IAC1D,gBAAgB,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,GAAG;IACzC,QAAQ,CAAC,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC;IAElC;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,OAAO,EAC9B,MAAM,EAAE,OAAO,KACZ,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;CACpC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unique symbol to reliably identify the OneOfMatcher type.
|
|
3
|
+
*
|
|
4
|
+
* TypeScript is structurally typed, so matcher types with similar predicates
|
|
5
|
+
* can otherwise accidentally satisfy each other's conditional branches.
|
|
6
|
+
*/
|
|
7
|
+
export const oneOfMatcher = Symbol("smartass.oneOfMatcher");
|
|
8
|
+
//# sourceMappingURL=one-of.type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"one-of.type.js","sourceRoot":"","sources":["../../../src/assert/one-of/one-of.type.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare function assertStringEndsWith<const T extends string>(value: string, suffix: T, message?: string): asserts value is `${string}${T}`;
|
|
1
|
+
import type { StringEndingWithAssertion } from "./string-ends-with.type.js";
|
|
2
|
+
export declare function assertStringEndsWith<TActual extends string, const TSuffix extends string>(value: TActual, suffix: TSuffix, message?: string): asserts value is StringEndingWithAssertion<TActual, TSuffix>;
|
|
3
|
+
export declare function assertStringEndsWith<const TSuffix extends string>(value: unknown, suffix: TSuffix, message?: string): asserts value is `${string}${TSuffix}`;
|
|
5
4
|
//# sourceMappingURL=string-ends-with.assert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-ends-with.assert.d.ts","sourceRoot":"","sources":["../../../src/assert/string-ends-with/string-ends-with.assert.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"string-ends-with.assert.d.ts","sourceRoot":"","sources":["../../../src/assert/string-ends-with/string-ends-with.assert.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAE5E,wBAAgB,oBAAoB,CAClC,OAAO,SAAS,MAAM,EACtB,KAAK,CAAC,OAAO,SAAS,MAAM,EAE5B,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,KAAK,IAAI,yBAAyB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAEhE,wBAAgB,oBAAoB,CAAC,KAAK,CAAC,OAAO,SAAS,MAAM,EAC/D,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,KAAK,IAAI,GAAG,MAAM,GAAG,OAAO,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-ends-with.assert.js","sourceRoot":"","sources":["../../../src/assert/string-ends-with/string-ends-with.assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"string-ends-with.assert.js","sourceRoot":"","sources":["../../../src/assert/string-ends-with/string-ends-with.assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAkB/D;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAc,EACd,MAAc,EACd,OAAgB;IAEhB,MAAM,OAAO,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACzC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,cAAc,CACtB,OAAO;YACL,YAAY,IAAI,CAAC,KAAK,CAAC,gBAAgB,IAAI,CAAC,MAAM,CAAC,mBAAmB,EACxE,KAAK,EACL,OAAO,CAAC,SAAS,EAAE,CACpB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type StringEndingWithMatcher } from "./string-ends-with.type.js";
|
|
2
2
|
/**
|
|
3
3
|
* Matcher for a string that ends with a given suffix.
|
|
4
4
|
*/
|
|
5
|
-
export declare function stringEndingWith<const T extends string>(suffix: T):
|
|
5
|
+
export declare function stringEndingWith<const T extends string>(suffix: T): StringEndingWithMatcher<T>;
|
|
6
6
|
//# sourceMappingURL=string-ends-with.match.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-ends-with.match.d.ts","sourceRoot":"","sources":["../../../src/assert/string-ends-with/string-ends-with.match.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"string-ends-with.match.d.ts","sourceRoot":"","sources":["../../../src/assert/string-ends-with/string-ends-with.match.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,4BAA4B,CAAC;AAEpC;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EACrD,MAAM,EAAE,CAAC,GACR,uBAAuB,CAAC,CAAC,CAAC,CAY5B"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { repr } from "../../describe/describe.js";
|
|
2
2
|
import { createMatcher } from "../../match/match.js";
|
|
3
|
+
import { stringEndingWithMatcher, } from "./string-ends-with.type.js";
|
|
3
4
|
/**
|
|
4
5
|
* Matcher for a string that ends with a given suffix.
|
|
5
6
|
*/
|
|
6
7
|
export function stringEndingWith(suffix) {
|
|
7
|
-
return
|
|
8
|
+
return {
|
|
9
|
+
...createMatcher((value) => typeof value === "string" && value.endsWith(suffix), () => `string ending with ${repr(suffix)}`, () => `"…${suffix}"`),
|
|
10
|
+
// Runtime marker used only to make the matcher type nominal for type-level
|
|
11
|
+
// refinement dispatch. It is not part of the user-facing matcher behaviour.
|
|
12
|
+
[stringEndingWithMatcher]: suffix,
|
|
13
|
+
};
|
|
8
14
|
}
|
|
9
15
|
//# sourceMappingURL=string-ends-with.match.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-ends-with.match.js","sourceRoot":"","sources":["../../../src/assert/string-ends-with/string-ends-with.match.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,
|
|
1
|
+
{"version":3,"file":"string-ends-with.match.js","sourceRoot":"","sources":["../../../src/assert/string-ends-with/string-ends-with.match.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EACL,uBAAuB,GAExB,MAAM,4BAA4B,CAAC;AAEpC;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAS;IAET,OAAO;QACL,GAAG,aAAa,CACd,CAAC,KAAK,EAA4B,EAAE,CAClC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EACrD,GAAG,EAAE,CAAC,sBAAsB,IAAI,CAAC,MAAM,CAAC,EAAE,EAC1C,GAAG,EAAE,CAAC,KAAK,MAAM,GAAG,CACrB;QACD,2EAA2E;QAC3E,4EAA4E;QAC5E,CAAC,uBAAuB,CAAC,EAAE,MAAM;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AssertionMatcher, refinement } from "../../match/match.js";
|
|
2
|
+
/**
|
|
3
|
+
* Unique symbol to reliably identify the StringEndingWithMatcher type.
|
|
4
|
+
*
|
|
5
|
+
* TypeScript is structurally typed, so matcher types with similar predicates can
|
|
6
|
+
* otherwise accidentally satisfy each other's conditional branches.
|
|
7
|
+
*/
|
|
8
|
+
export declare const stringEndingWithMatcher: unique symbol;
|
|
9
|
+
/**
|
|
10
|
+
* Type produced when an actual value is matched by stringEndingWith().
|
|
11
|
+
*
|
|
12
|
+
* The primary goal is to expose clean, readable user-facing types in IDE
|
|
13
|
+
* tooltips and TypeScript errors. When the calling scope already has string
|
|
14
|
+
* literal overlap with the requested suffix, we preserve that overlap.
|
|
15
|
+
* Otherwise, we fall back to a readable template-literal string type.
|
|
16
|
+
*/
|
|
17
|
+
export type StringEndingWithMatch<TActual, TSuffix extends string> = [
|
|
18
|
+
Extract<NonNullable<TActual>, `${string}${TSuffix}`>
|
|
19
|
+
] extends [never] ? `${string}${TSuffix}` : Extract<NonNullable<TActual>, `${string}${TSuffix}`>;
|
|
20
|
+
/**
|
|
21
|
+
* Type produced when assertStringEndsWith() narrows a value.
|
|
22
|
+
*
|
|
23
|
+
* Assertion functions must assert a type assignable to the asserted parameter's
|
|
24
|
+
* original type. So unlike StringEndingWithMatch, the no-overlap fallback keeps
|
|
25
|
+
* the original actual string type in an intersection.
|
|
26
|
+
*/
|
|
27
|
+
export type StringEndingWithAssertion<TActual extends string, TSuffix extends string> = [Extract<TActual, `${string}${TSuffix}`>] extends [never] ? TActual & `${string}${TSuffix}` : Extract<TActual, `${string}${TSuffix}`>;
|
|
28
|
+
export type StringEndingWithMatcher<TSuffix extends string> = AssertionMatcher<`${string}${TSuffix}`> & {
|
|
29
|
+
readonly [stringEndingWithMatcher]: TSuffix;
|
|
30
|
+
/**
|
|
31
|
+
* Optional type-level hook used by compositional assertions such as
|
|
32
|
+
* assertObjectMatches().
|
|
33
|
+
*
|
|
34
|
+
* This lets the matcher describe how it refines an existing actual type,
|
|
35
|
+
* rather than only exposing the standalone matches() predicate type.
|
|
36
|
+
*/
|
|
37
|
+
readonly [refinement]?: <TActual>(actual: TActual) => StringEndingWithMatch<TActual, TSuffix>;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=string-ends-with.type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-ends-with.type.d.ts","sourceRoot":"","sources":["../../../src/assert/string-ends-with/string-ends-with.type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEzE;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,eAEnC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,qBAAqB,CAAC,OAAO,EAAE,OAAO,SAAS,MAAM,IAAI;IACnE,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,MAAM,GAAG,OAAO,EAAE,CAAC;CACrD,SAAS,CAAC,KAAK,CAAC,GACb,GAAG,MAAM,GAAG,OAAO,EAAE,GACrB,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,MAAM,GAAG,OAAO,EAAE,CAAC,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,MAAM,yBAAyB,CACnC,OAAO,SAAS,MAAM,EACtB,OAAO,SAAS,MAAM,IACpB,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,MAAM,GAAG,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACzD,OAAO,GAAG,GAAG,MAAM,GAAG,OAAO,EAAE,GAC/B,OAAO,CAAC,OAAO,EAAE,GAAG,MAAM,GAAG,OAAO,EAAE,CAAC,CAAC;AAE5C,MAAM,MAAM,uBAAuB,CAAC,OAAO,SAAS,MAAM,IACxD,gBAAgB,CAAC,GAAG,MAAM,GAAG,OAAO,EAAE,CAAC,GAAG;IACxC,QAAQ,CAAC,CAAC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAE5C;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,OAAO,EAC9B,MAAM,EAAE,OAAO,KACZ,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;CAC9C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unique symbol to reliably identify the StringEndingWithMatcher type.
|
|
3
|
+
*
|
|
4
|
+
* TypeScript is structurally typed, so matcher types with similar predicates can
|
|
5
|
+
* otherwise accidentally satisfy each other's conditional branches.
|
|
6
|
+
*/
|
|
7
|
+
export const stringEndingWithMatcher = Symbol("smartass.stringEndingWithMatcher");
|
|
8
|
+
//# sourceMappingURL=string-ends-with.type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-ends-with.type.js","sourceRoot":"","sources":["../../../src/assert/string-ends-with/string-ends-with.type.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAC3C,kCAAkC,CACnC,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare function assertStringIncludes<const T extends string>(value: string, substring: T, message?: string): asserts value is `${string}${T}${string}`;
|
|
1
|
+
import type { StringIncludingAssertion } from "./string-includes.type.js";
|
|
2
|
+
export declare function assertStringIncludes<TActual extends string, const TSubstring extends string>(value: TActual, substring: TSubstring, message?: string): asserts value is StringIncludingAssertion<TActual, TSubstring>;
|
|
3
|
+
export declare function assertStringIncludes<const TSubstring extends string>(value: unknown, substring: TSubstring, message?: string): asserts value is `${string}${TSubstring}${string}`;
|
|
5
4
|
//# sourceMappingURL=string-includes.assert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-includes.assert.d.ts","sourceRoot":"","sources":["../../../src/assert/string-includes/string-includes.assert.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"string-includes.assert.d.ts","sourceRoot":"","sources":["../../../src/assert/string-includes/string-includes.assert.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAE1E,wBAAgB,oBAAoB,CAClC,OAAO,SAAS,MAAM,EACtB,KAAK,CAAC,UAAU,SAAS,MAAM,EAE/B,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,UAAU,EACrB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,KAAK,IAAI,wBAAwB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAElE,wBAAgB,oBAAoB,CAAC,KAAK,CAAC,UAAU,SAAS,MAAM,EAClE,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,UAAU,EACrB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,KAAK,IAAI,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-includes.assert.js","sourceRoot":"","sources":["../../../src/assert/string-includes/string-includes.assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"string-includes.assert.js","sourceRoot":"","sources":["../../../src/assert/string-includes/string-includes.assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAkB7D;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAc,EACd,SAAiB,EACjB,OAAgB;IAEhB,MAAM,OAAO,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IAE3C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,cAAc,CACtB,OAAO;YACL,YAAY,IAAI,CAAC,KAAK,CAAC,eAAe,IAAI,CAAC,SAAS,CAAC,mBAAmB,EAC1E,KAAK,EACL,OAAO,CAAC,SAAS,EAAE,CACpB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type StringIncludingMatcher } from "./string-includes.type.js";
|
|
2
2
|
/**
|
|
3
3
|
* Matcher for a string that includes a given substring.
|
|
4
4
|
*/
|
|
5
|
-
export declare function stringIncluding<const T extends string>(substring: T):
|
|
5
|
+
export declare function stringIncluding<const T extends string>(substring: T): StringIncludingMatcher<T>;
|
|
6
6
|
//# sourceMappingURL=string-includes.match.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-includes.match.d.ts","sourceRoot":"","sources":["../../../src/assert/string-includes/string-includes.match.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"string-includes.match.d.ts","sourceRoot":"","sources":["../../../src/assert/string-includes/string-includes.match.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EACpD,SAAS,EAAE,CAAC,GACX,sBAAsB,CAAC,CAAC,CAAC,CAY3B"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { repr } from "../../describe/describe.js";
|
|
2
2
|
import { createMatcher } from "../../match/match.js";
|
|
3
|
+
import { stringIncludingMatcher, } from "./string-includes.type.js";
|
|
3
4
|
/**
|
|
4
5
|
* Matcher for a string that includes a given substring.
|
|
5
6
|
*/
|
|
6
7
|
export function stringIncluding(substring) {
|
|
7
|
-
return
|
|
8
|
+
return {
|
|
9
|
+
...createMatcher((value) => typeof value === "string" && value.includes(substring), () => `string including ${repr(substring)}`, () => `"…${substring}…"`),
|
|
10
|
+
// Runtime marker used only to make the matcher type nominal for type-level
|
|
11
|
+
// refinement dispatch. It is not part of the user-facing matcher behaviour.
|
|
12
|
+
[stringIncludingMatcher]: substring,
|
|
13
|
+
};
|
|
8
14
|
}
|
|
9
15
|
//# sourceMappingURL=string-includes.match.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-includes.match.js","sourceRoot":"","sources":["../../../src/assert/string-includes/string-includes.match.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,
|
|
1
|
+
{"version":3,"file":"string-includes.match.js","sourceRoot":"","sources":["../../../src/assert/string-includes/string-includes.match.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EACL,sBAAsB,GAEvB,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AACH,MAAM,UAAU,eAAe,CAC7B,SAAY;IAEZ,OAAO;QACL,GAAG,aAAa,CACd,CAAC,KAAK,EAAqC,EAAE,CAC3C,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,EACxD,GAAG,EAAE,CAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,EAAE,EAC3C,GAAG,EAAE,CAAC,KAAK,SAAS,IAAI,CACzB;QACD,2EAA2E;QAC3E,4EAA4E;QAC5E,CAAC,sBAAsB,CAAC,EAAE,SAAS;KACpC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AssertionMatcher, refinement } from "../../match/match.js";
|
|
2
|
+
/**
|
|
3
|
+
* Unique symbol to reliably identify the StringIncludingMatcher type.
|
|
4
|
+
*
|
|
5
|
+
* TypeScript is structurally typed, so matcher types with similar predicates can
|
|
6
|
+
* otherwise accidentally satisfy each other's conditional branches.
|
|
7
|
+
*/
|
|
8
|
+
export declare const stringIncludingMatcher: unique symbol;
|
|
9
|
+
/**
|
|
10
|
+
* Type produced when an actual value is matched by stringIncluding().
|
|
11
|
+
*
|
|
12
|
+
* The primary goal is to expose clean, readable user-facing types in IDE
|
|
13
|
+
* tooltips and TypeScript errors. When the calling scope already has string
|
|
14
|
+
* literal overlap with the requested substring, we preserve that overlap.
|
|
15
|
+
* Otherwise, we fall back to a readable template-literal string type.
|
|
16
|
+
*/
|
|
17
|
+
export type StringIncludingMatch<TActual, TSubstring extends string> = [
|
|
18
|
+
Extract<NonNullable<TActual>, `${string}${TSubstring}${string}`>
|
|
19
|
+
] extends [never] ? `${string}${TSubstring}${string}` : Extract<NonNullable<TActual>, `${string}${TSubstring}${string}`>;
|
|
20
|
+
/**
|
|
21
|
+
* Type produced when assertStringIncludes() narrows a value.
|
|
22
|
+
*
|
|
23
|
+
* Assertion functions must assert a type assignable to the asserted parameter's
|
|
24
|
+
* original type. So unlike StringIncludingMatch, the no-overlap fallback keeps
|
|
25
|
+
* the original actual string type in an intersection.
|
|
26
|
+
*/
|
|
27
|
+
export type StringIncludingAssertion<TActual extends string, TSubstring extends string> = [Extract<TActual, `${string}${TSubstring}${string}`>] extends [never] ? TActual & `${string}${TSubstring}${string}` : Extract<TActual, `${string}${TSubstring}${string}`>;
|
|
28
|
+
export type StringIncludingMatcher<TSubstring extends string> = AssertionMatcher<`${string}${TSubstring}${string}`> & {
|
|
29
|
+
readonly [stringIncludingMatcher]: TSubstring;
|
|
30
|
+
/**
|
|
31
|
+
* Optional type-level hook used by compositional assertions such as
|
|
32
|
+
* assertObjectMatches().
|
|
33
|
+
*
|
|
34
|
+
* This lets the matcher describe how it refines an existing actual type,
|
|
35
|
+
* rather than only exposing the standalone matches() predicate type.
|
|
36
|
+
*/
|
|
37
|
+
readonly [refinement]?: <TActual>(actual: TActual) => StringIncludingMatch<TActual, TSubstring>;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=string-includes.type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-includes.type.d.ts","sourceRoot":"","sources":["../../../src/assert/string-includes/string-includes.type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEzE;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,eAA4C,CAAC;AAEhF;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,CAAC,OAAO,EAAE,UAAU,SAAS,MAAM,IAAI;IACrE,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,EAAE,CAAC;CACjE,SAAS,CAAC,KAAK,CAAC,GACb,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,EAAE,GACjC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,EAAE,CAAC,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,MAAM,wBAAwB,CAClC,OAAO,SAAS,MAAM,EACtB,UAAU,SAAS,MAAM,IACvB,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACrE,OAAO,GAAG,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,EAAE,GAC3C,OAAO,CAAC,OAAO,EAAE,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,EAAE,CAAC,CAAC;AAExD,MAAM,MAAM,sBAAsB,CAAC,UAAU,SAAS,MAAM,IAC1D,gBAAgB,CAAC,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,EAAE,CAAC,GAAG;IACpD,QAAQ,CAAC,CAAC,sBAAsB,CAAC,EAAE,UAAU,CAAC;IAE9C;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,OAAO,EAC9B,MAAM,EAAE,OAAO,KACZ,oBAAoB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;CAChD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unique symbol to reliably identify the StringIncludingMatcher type.
|
|
3
|
+
*
|
|
4
|
+
* TypeScript is structurally typed, so matcher types with similar predicates can
|
|
5
|
+
* otherwise accidentally satisfy each other's conditional branches.
|
|
6
|
+
*/
|
|
7
|
+
export const stringIncludingMatcher = Symbol("smartass.stringIncludingMatcher");
|
|
8
|
+
//# sourceMappingURL=string-includes.type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-includes.type.js","sourceRoot":"","sources":["../../../src/assert/string-includes/string-includes.type.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,iCAAiC,CAAC,CAAC"}
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* The type narrowing indicates:
|
|
6
|
-
* - An empty string for 0
|
|
7
|
-
* - An exact length and safe indexing of known character positions up to 10
|
|
8
|
-
* - For >10, an exact length and safe indexing of known character positions up
|
|
9
|
-
* to 10 when those positions are guaranteed to exist.
|
|
10
|
-
*
|
|
11
|
-
* Note that this models JavaScript string indexing and length (UTF-16 code units),
|
|
12
|
-
* not Unicode grapheme clusters.
|
|
13
|
-
*/
|
|
14
|
-
export declare function assertStringLength<const N extends number>(value: string, expectedLength: N, message?: string): asserts value is StringOfLength<N>;
|
|
1
|
+
import type { StringOfLength, StringOfLengthAssertion } from "./string-length.type.js";
|
|
2
|
+
export declare function assertStringLength<TActual extends string, const N extends number>(value: TActual, expectedLength: N, message?: string): asserts value is StringOfLengthAssertion<TActual, N>;
|
|
3
|
+
export declare function assertStringLength<const N extends number>(value: unknown, expectedLength: N, message?: string): asserts value is StringOfLength<N>;
|
|
15
4
|
//# sourceMappingURL=string-length.assert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-length.assert.d.ts","sourceRoot":"","sources":["../../../src/assert/string-length/string-length.assert.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"string-length.assert.d.ts","sourceRoot":"","sources":["../../../src/assert/string-length/string-length.assert.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,cAAc,EACd,uBAAuB,EACxB,MAAM,yBAAyB,CAAC;AAEjC,wBAAgB,kBAAkB,CAChC,OAAO,SAAS,MAAM,EACtB,KAAK,CAAC,CAAC,SAAS,MAAM,EAEtB,KAAK,EAAE,OAAO,EACd,cAAc,EAAE,CAAC,EACjB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,KAAK,IAAI,uBAAuB,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AAExD,wBAAgB,kBAAkB,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EACvD,KAAK,EAAE,OAAO,EACd,cAAc,EAAE,CAAC,EACjB,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,KAAK,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -16,8 +16,13 @@ import { stringOfLength } from "./string-length.match.js";
|
|
|
16
16
|
export function assertStringLength(value, expectedLength, message) {
|
|
17
17
|
const matcher = stringOfLength(expectedLength);
|
|
18
18
|
if (!matcher.matches(value)) {
|
|
19
|
-
throw new AssertionError(message ??
|
|
20
|
-
`Expected ${desc(value)} to have length ${repr(expectedLength)}, but it had length ${repr(value.length)}.`, value, matcher.represent());
|
|
19
|
+
throw new AssertionError(message ?? buildStringLengthMessage(value, expectedLength), value, matcher.represent());
|
|
21
20
|
}
|
|
22
21
|
}
|
|
22
|
+
function buildStringLengthMessage(value, expectedLength) {
|
|
23
|
+
if (typeof value !== "string") {
|
|
24
|
+
return `Expected ${desc(value)} to be a string of length ${repr(expectedLength)}.`;
|
|
25
|
+
}
|
|
26
|
+
return `Expected ${desc(value)} to have length ${repr(expectedLength)}, but it had length ${repr(value.length)}.`;
|
|
27
|
+
}
|
|
23
28
|
//# sourceMappingURL=string-length.assert.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-length.assert.js","sourceRoot":"","sources":["../../../src/assert/string-length/string-length.assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"string-length.assert.js","sourceRoot":"","sources":["../../../src/assert/string-length/string-length.assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAqB1D;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAc,EACd,cAAsB,EACtB,OAAgB;IAEhB,MAAM,OAAO,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;IAC/C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,cAAc,CACtB,OAAO,IAAI,wBAAwB,CAAC,KAAK,EAAE,cAAc,CAAC,EAC1D,KAAK,EACL,OAAO,CAAC,SAAS,EAAE,CACpB,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,wBAAwB,CAC/B,KAAc,EACd,cAAsB;IAEtB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,YAAY,IAAI,CAAC,KAAK,CAAC,6BAA6B,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;IACrF,CAAC;IAED,OAAO,YAAY,IAAI,CAAC,KAAK,CAAC,mBAAmB,IAAI,CAAC,cAAc,CAAC,uBAAuB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC;AACpH,CAAC"}
|
|
@@ -1,96 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export type StringOfLength<N extends number> = N extends 0 ? "" : N extends 1 ? string & {
|
|
3
|
-
length: 1;
|
|
4
|
-
0: string;
|
|
5
|
-
} : N extends 2 ? string & {
|
|
6
|
-
length: 2;
|
|
7
|
-
0: string;
|
|
8
|
-
1: string;
|
|
9
|
-
} : N extends 3 ? string & {
|
|
10
|
-
length: 3;
|
|
11
|
-
0: string;
|
|
12
|
-
1: string;
|
|
13
|
-
2: string;
|
|
14
|
-
} : N extends 4 ? string & {
|
|
15
|
-
length: 4;
|
|
16
|
-
0: string;
|
|
17
|
-
1: string;
|
|
18
|
-
2: string;
|
|
19
|
-
3: string;
|
|
20
|
-
} : N extends 5 ? string & {
|
|
21
|
-
length: 5;
|
|
22
|
-
0: string;
|
|
23
|
-
1: string;
|
|
24
|
-
2: string;
|
|
25
|
-
3: string;
|
|
26
|
-
4: string;
|
|
27
|
-
} : N extends 6 ? string & {
|
|
28
|
-
length: 6;
|
|
29
|
-
0: string;
|
|
30
|
-
1: string;
|
|
31
|
-
2: string;
|
|
32
|
-
3: string;
|
|
33
|
-
4: string;
|
|
34
|
-
5: string;
|
|
35
|
-
} : N extends 7 ? string & {
|
|
36
|
-
length: 7;
|
|
37
|
-
0: string;
|
|
38
|
-
1: string;
|
|
39
|
-
2: string;
|
|
40
|
-
3: string;
|
|
41
|
-
4: string;
|
|
42
|
-
5: string;
|
|
43
|
-
6: string;
|
|
44
|
-
} : N extends 8 ? string & {
|
|
45
|
-
length: 8;
|
|
46
|
-
0: string;
|
|
47
|
-
1: string;
|
|
48
|
-
2: string;
|
|
49
|
-
3: string;
|
|
50
|
-
4: string;
|
|
51
|
-
5: string;
|
|
52
|
-
6: string;
|
|
53
|
-
7: string;
|
|
54
|
-
} : N extends 9 ? string & {
|
|
55
|
-
length: 9;
|
|
56
|
-
0: string;
|
|
57
|
-
1: string;
|
|
58
|
-
2: string;
|
|
59
|
-
3: string;
|
|
60
|
-
4: string;
|
|
61
|
-
5: string;
|
|
62
|
-
6: string;
|
|
63
|
-
7: string;
|
|
64
|
-
8: string;
|
|
65
|
-
} : N extends 10 ? string & {
|
|
66
|
-
length: 10;
|
|
67
|
-
0: string;
|
|
68
|
-
1: string;
|
|
69
|
-
2: string;
|
|
70
|
-
3: string;
|
|
71
|
-
4: string;
|
|
72
|
-
5: string;
|
|
73
|
-
6: string;
|
|
74
|
-
7: string;
|
|
75
|
-
8: string;
|
|
76
|
-
9: string;
|
|
77
|
-
} : string & {
|
|
78
|
-
length: N;
|
|
79
|
-
0: string;
|
|
80
|
-
1: string;
|
|
81
|
-
2: string;
|
|
82
|
-
3: string;
|
|
83
|
-
4: string;
|
|
84
|
-
5: string;
|
|
85
|
-
6: string;
|
|
86
|
-
7: string;
|
|
87
|
-
8: string;
|
|
88
|
-
9: string;
|
|
89
|
-
10: string;
|
|
90
|
-
};
|
|
91
|
-
export type StringOfLengthMatcher<N extends number> = AssertionMatcher<StringOfLength<N>> & {
|
|
92
|
-
readonly [refinement]?: (actual: unknown) => StringOfLength<N>;
|
|
93
|
-
};
|
|
1
|
+
import { type StringOfLengthMatcher } from "./string-length.type.js";
|
|
94
2
|
/**
|
|
95
3
|
* Matcher for a string with exactly the expected length.
|
|
96
4
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-length.match.d.ts","sourceRoot":"","sources":["../../../src/assert/string-length/string-length.match.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"string-length.match.d.ts","sourceRoot":"","sources":["../../../src/assert/string-length/string-length.match.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,yBAAyB,CAAC;AAEjC;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EACnD,cAAc,EAAE,CAAC,GAChB,qBAAqB,CAAC,CAAC,CAAC,CAY1B"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { createMatcher
|
|
1
|
+
import { createMatcher } from "../../match/match.js";
|
|
2
2
|
import { repr } from "../../describe/describe.js";
|
|
3
|
+
import { stringOfLengthMatcher, } from "./string-length.type.js";
|
|
3
4
|
/**
|
|
4
5
|
* Matcher for a string with exactly the expected length.
|
|
5
6
|
*/
|
|
6
7
|
export function stringOfLength(expectedLength) {
|
|
7
|
-
return
|
|
8
|
+
return {
|
|
9
|
+
...createMatcher((value) => typeof value === "string" && value.length === expectedLength, () => `string of length ${repr(expectedLength)}`, () => `String(${repr(expectedLength)})`),
|
|
10
|
+
// Runtime marker used only to make the matcher type nominal for type-level
|
|
11
|
+
// refinement dispatch. It is not part of the user-facing matcher behaviour.
|
|
12
|
+
[stringOfLengthMatcher]: expectedLength,
|
|
13
|
+
};
|
|
8
14
|
}
|
|
9
15
|
//# sourceMappingURL=string-length.match.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-length.match.js","sourceRoot":"","sources":["../../../src/assert/string-length/string-length.match.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"string-length.match.js","sourceRoot":"","sources":["../../../src/assert/string-length/string-length.match.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EACL,qBAAqB,GAGtB,MAAM,yBAAyB,CAAC;AAEjC;;GAEG;AACH,MAAM,UAAU,cAAc,CAC5B,cAAiB;IAEjB,OAAO;QACL,GAAG,aAAa,CACd,CAAC,KAAK,EAA8B,EAAE,CACpC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,cAAc,EAC9D,GAAG,EAAE,CAAC,oBAAoB,IAAI,CAAC,cAAc,CAAC,EAAE,EAChD,GAAG,EAAE,CAAC,UAAU,IAAI,CAAC,cAAc,CAAC,GAAG,CACxC;QACD,2EAA2E;QAC3E,4EAA4E;QAC5E,CAAC,qBAAqB,CAAC,EAAE,cAAc;KACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { AssertionMatcher, refinement } from "../../match/match.js";
|
|
2
|
+
/**
|
|
3
|
+
* Unique symbol to reliably identify the StringOfLengthMatcher type.
|
|
4
|
+
*
|
|
5
|
+
* TypeScript is structurally typed, so matcher types with similar predicates
|
|
6
|
+
* can otherwise accidentally satisfy each other's conditional branches.
|
|
7
|
+
*/
|
|
8
|
+
export declare const stringOfLengthMatcher: unique symbol;
|
|
9
|
+
export type StringOfLength<N extends number> = N extends 0 ? "" : N extends 1 ? string & {
|
|
10
|
+
length: 1;
|
|
11
|
+
0: string;
|
|
12
|
+
} : N extends 2 ? string & {
|
|
13
|
+
length: 2;
|
|
14
|
+
0: string;
|
|
15
|
+
1: string;
|
|
16
|
+
} : N extends 3 ? string & {
|
|
17
|
+
length: 3;
|
|
18
|
+
0: string;
|
|
19
|
+
1: string;
|
|
20
|
+
2: string;
|
|
21
|
+
} : N extends 4 ? string & {
|
|
22
|
+
length: 4;
|
|
23
|
+
0: string;
|
|
24
|
+
1: string;
|
|
25
|
+
2: string;
|
|
26
|
+
3: string;
|
|
27
|
+
} : N extends 5 ? string & {
|
|
28
|
+
length: 5;
|
|
29
|
+
0: string;
|
|
30
|
+
1: string;
|
|
31
|
+
2: string;
|
|
32
|
+
3: string;
|
|
33
|
+
4: string;
|
|
34
|
+
} : N extends 6 ? string & {
|
|
35
|
+
length: 6;
|
|
36
|
+
0: string;
|
|
37
|
+
1: string;
|
|
38
|
+
2: string;
|
|
39
|
+
3: string;
|
|
40
|
+
4: string;
|
|
41
|
+
5: string;
|
|
42
|
+
} : N extends 7 ? string & {
|
|
43
|
+
length: 7;
|
|
44
|
+
0: string;
|
|
45
|
+
1: string;
|
|
46
|
+
2: string;
|
|
47
|
+
3: string;
|
|
48
|
+
4: string;
|
|
49
|
+
5: string;
|
|
50
|
+
6: string;
|
|
51
|
+
} : N extends 8 ? string & {
|
|
52
|
+
length: 8;
|
|
53
|
+
0: string;
|
|
54
|
+
1: string;
|
|
55
|
+
2: string;
|
|
56
|
+
3: string;
|
|
57
|
+
4: string;
|
|
58
|
+
5: string;
|
|
59
|
+
6: string;
|
|
60
|
+
7: string;
|
|
61
|
+
} : N extends 9 ? string & {
|
|
62
|
+
length: 9;
|
|
63
|
+
0: string;
|
|
64
|
+
1: string;
|
|
65
|
+
2: string;
|
|
66
|
+
3: string;
|
|
67
|
+
4: string;
|
|
68
|
+
5: string;
|
|
69
|
+
6: string;
|
|
70
|
+
7: string;
|
|
71
|
+
8: string;
|
|
72
|
+
} : N extends 10 ? string & {
|
|
73
|
+
length: 10;
|
|
74
|
+
0: string;
|
|
75
|
+
1: string;
|
|
76
|
+
2: string;
|
|
77
|
+
3: string;
|
|
78
|
+
4: string;
|
|
79
|
+
5: string;
|
|
80
|
+
6: string;
|
|
81
|
+
7: string;
|
|
82
|
+
8: string;
|
|
83
|
+
9: string;
|
|
84
|
+
} : string & {
|
|
85
|
+
length: N;
|
|
86
|
+
0: string;
|
|
87
|
+
1: string;
|
|
88
|
+
2: string;
|
|
89
|
+
3: string;
|
|
90
|
+
4: string;
|
|
91
|
+
5: string;
|
|
92
|
+
6: string;
|
|
93
|
+
7: string;
|
|
94
|
+
8: string;
|
|
95
|
+
9: string;
|
|
96
|
+
10: string;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Type produced when an actual value is matched by stringOfLength().
|
|
100
|
+
*
|
|
101
|
+
* The primary goal is to expose clean, readable user-facing types in IDE
|
|
102
|
+
* tooltips and TypeScript errors. For exact length checks, the readable type is
|
|
103
|
+
* StringOfLength<N>, which models exact length and safe indexing up to a fixed
|
|
104
|
+
* limit.
|
|
105
|
+
*
|
|
106
|
+
* We intentionally do not try to recursively compute the length of arbitrary
|
|
107
|
+
* string literal unions here. That would add significant type complexity and
|
|
108
|
+
* noisier compiler output for limited practical gain.
|
|
109
|
+
*/
|
|
110
|
+
export type StringOfLengthMatch<TActual, N extends number> = [
|
|
111
|
+
Extract<NonNullable<TActual>, StringOfLength<N>>
|
|
112
|
+
] extends [never] ? StringOfLength<N> : Extract<NonNullable<TActual>, StringOfLength<N>>;
|
|
113
|
+
/**
|
|
114
|
+
* Type produced when assertStringLength() narrows a value.
|
|
115
|
+
*
|
|
116
|
+
* Assertion functions must assert a type assignable to the asserted parameter's
|
|
117
|
+
* original type. So the no-overlap fallback keeps the original actual string
|
|
118
|
+
* type in an intersection.
|
|
119
|
+
*/
|
|
120
|
+
export type StringOfLengthAssertion<TActual extends string, N extends number> = [Extract<TActual, StringOfLength<N>>] extends [never] ? TActual & StringOfLength<N> : Extract<TActual, StringOfLength<N>>;
|
|
121
|
+
export type StringOfLengthMatcher<N extends number> = AssertionMatcher<StringOfLength<N>> & {
|
|
122
|
+
readonly [stringOfLengthMatcher]: N;
|
|
123
|
+
/**
|
|
124
|
+
* Optional type-level hook used by compositional assertions such as
|
|
125
|
+
* assertObjectMatches().
|
|
126
|
+
*
|
|
127
|
+
* This lets the matcher describe how it refines an existing actual type,
|
|
128
|
+
* rather than only exposing the standalone matches() predicate type.
|
|
129
|
+
*/
|
|
130
|
+
readonly [refinement]?: <TActual>(actual: TActual) => StringOfLengthMatch<TActual, N>;
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=string-length.type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-length.type.d.ts","sourceRoot":"","sources":["../../../src/assert/string-length/string-length.type.ts"],"names":[],"mappings":"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"}
|