@zipbul/baker 5.1.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/dist/index.d.ts +11 -9
  3. package/dist/index.js +1 -1
  4. package/dist/src/baker.d.ts +8 -9
  5. package/dist/src/baker.js +1 -1
  6. package/dist/src/common/enums.d.ts +10 -0
  7. package/dist/src/common/enums.js +1 -0
  8. package/dist/src/common/index.d.ts +6 -0
  9. package/dist/src/common/index.js +1 -0
  10. package/dist/src/common/interfaces.d.ts +4 -0
  11. package/dist/src/common/types.d.ts +2 -0
  12. package/dist/src/config/config-normalizer.d.ts +7 -0
  13. package/dist/src/config/config-normalizer.js +1 -0
  14. package/dist/src/config/constants.d.ts +6 -0
  15. package/dist/src/config/constants.js +1 -0
  16. package/dist/src/config/index.d.ts +3 -0
  17. package/dist/src/config/index.js +1 -0
  18. package/dist/src/{configure.d.ts → config/interfaces.d.ts} +1 -8
  19. package/dist/src/config/interfaces.js +0 -0
  20. package/dist/src/decorators/constants.d.ts +2 -0
  21. package/dist/src/decorators/constants.js +1 -0
  22. package/dist/src/decorators/enums.d.ts +5 -0
  23. package/dist/src/decorators/enums.js +1 -0
  24. package/dist/src/decorators/field.d.ts +3 -54
  25. package/dist/src/decorators/field.js +1 -1
  26. package/dist/src/decorators/index.d.ts +2 -2
  27. package/dist/src/decorators/index.js +1 -1
  28. package/dist/src/decorators/interfaces.d.ts +50 -0
  29. package/dist/src/decorators/interfaces.js +0 -0
  30. package/dist/src/decorators/public.d.ts +2 -0
  31. package/dist/src/decorators/public.js +1 -0
  32. package/dist/src/decorators/types.d.ts +6 -0
  33. package/dist/src/decorators/types.js +0 -0
  34. package/dist/src/metadata/enums.d.ts +5 -0
  35. package/dist/src/metadata/enums.js +1 -0
  36. package/dist/src/metadata/index.d.ts +3 -0
  37. package/dist/src/metadata/index.js +1 -0
  38. package/dist/src/metadata/interfaces.d.ts +90 -0
  39. package/dist/src/metadata/interfaces.js +0 -0
  40. package/dist/src/metadata/meta-store.d.ts +49 -0
  41. package/dist/src/metadata/meta-store.js +1 -0
  42. package/dist/src/metadata/types.d.ts +10 -0
  43. package/dist/src/metadata/types.js +0 -0
  44. package/dist/src/rules/array.d.ts +2 -2
  45. package/dist/src/rules/array.js +1 -1
  46. package/dist/src/rules/binary.d.ts +2 -2
  47. package/dist/src/rules/binary.js +1 -1
  48. package/dist/src/rules/combinators.d.ts +1 -1
  49. package/dist/src/rules/combinators.js +1 -1
  50. package/dist/src/rules/common.d.ts +3 -3
  51. package/dist/src/rules/common.js +1 -1
  52. package/dist/src/rules/constants.d.ts +10 -0
  53. package/dist/src/rules/constants.js +1 -0
  54. package/dist/src/{create-rule.d.ts → rules/create-rule.d.ts} +1 -1
  55. package/dist/src/rules/create-rule.js +1 -0
  56. package/dist/src/rules/date.d.ts +1 -1
  57. package/dist/src/rules/date.js +1 -1
  58. package/dist/src/{enums.d.ts → rules/enums.d.ts} +0 -20
  59. package/dist/src/rules/enums.js +1 -0
  60. package/dist/src/rules/index.d.ts +5 -13
  61. package/dist/src/rules/index.js +1 -1
  62. package/dist/src/rules/interfaces.d.ts +43 -0
  63. package/dist/src/rules/interfaces.js +0 -0
  64. package/dist/src/rules/locales.d.ts +1 -1
  65. package/dist/src/rules/locales.js +1 -1
  66. package/dist/src/rules/number.d.ts +3 -3
  67. package/dist/src/rules/number.js +1 -1
  68. package/dist/src/rules/object.d.ts +1 -1
  69. package/dist/src/rules/object.js +1 -1
  70. package/dist/src/rules/public.d.ts +14 -0
  71. package/dist/src/rules/public.js +1 -0
  72. package/dist/src/{rule-metadata.d.ts → rules/rule-metadata.d.ts} +1 -1
  73. package/dist/src/{rule-metadata.js → rules/rule-metadata.js} +1 -1
  74. package/dist/src/{rule-plan.d.ts → rules/rule-plan.d.ts} +4 -7
  75. package/dist/src/rules/rule-plan.js +1 -0
  76. package/dist/src/rules/string-basic.d.ts +23 -0
  77. package/dist/src/rules/string-basic.js +1 -0
  78. package/dist/src/rules/string-crypto.d.ts +5 -0
  79. package/dist/src/rules/string-crypto.js +1 -0
  80. package/dist/src/rules/string-datetime.d.ts +3 -0
  81. package/dist/src/rules/string-datetime.js +1 -0
  82. package/dist/src/rules/string-encoding.d.ts +14 -0
  83. package/dist/src/rules/string-encoding.js +1 -0
  84. package/dist/src/rules/string-finance.d.ts +18 -0
  85. package/dist/src/rules/string-finance.js +10 -0
  86. package/dist/src/rules/string-format.d.ts +38 -0
  87. package/dist/src/rules/string-format.js +1 -0
  88. package/dist/src/rules/string-geo.d.ts +5 -0
  89. package/dist/src/rules/string-geo.js +1 -0
  90. package/dist/src/rules/string-identifier.d.ts +16 -0
  91. package/dist/src/rules/string-identifier.js +3 -0
  92. package/dist/src/rules/string-shared.d.ts +3 -0
  93. package/dist/src/rules/string-shared.js +1 -0
  94. package/dist/src/rules/string-width.d.ts +6 -0
  95. package/dist/src/rules/string-width.js +1 -0
  96. package/dist/src/rules/string.d.ts +14 -110
  97. package/dist/src/rules/string.js +1 -12
  98. package/dist/src/rules/typechecker.d.ts +10 -10
  99. package/dist/src/rules/typechecker.js +5 -5
  100. package/dist/src/rules/types.d.ts +26 -0
  101. package/dist/src/rules/types.js +0 -0
  102. package/dist/src/{functions → runtime}/check-call-options.d.ts +1 -1
  103. package/dist/src/runtime/check-call-options.js +1 -0
  104. package/dist/src/runtime/constants.d.ts +3 -0
  105. package/dist/src/runtime/constants.js +1 -0
  106. package/dist/src/{functions → runtime}/deserialize.d.ts +2 -3
  107. package/dist/src/runtime/deserialize.js +1 -0
  108. package/dist/src/runtime/index.d.ts +3 -0
  109. package/dist/src/runtime/index.js +1 -0
  110. package/dist/src/{functions → runtime}/serialize.d.ts +2 -2
  111. package/dist/src/runtime/serialize.js +1 -0
  112. package/dist/src/{functions → runtime}/validate.d.ts +2 -3
  113. package/dist/src/runtime/validate.js +1 -0
  114. package/dist/src/seal/async-analyzer.d.ts +20 -0
  115. package/dist/src/seal/async-analyzer.js +1 -0
  116. package/dist/src/seal/circular-analyzer.d.ts +9 -6
  117. package/dist/src/seal/circular-analyzer.js +1 -1
  118. package/dist/src/seal/circular-placeholder.d.ts +20 -0
  119. package/dist/src/seal/circular-placeholder.js +1 -0
  120. package/dist/src/seal/codegen-utils.d.ts +15 -0
  121. package/dist/src/seal/codegen-utils.js +1 -1
  122. package/dist/src/seal/compile-cache.d.ts +38 -0
  123. package/dist/src/seal/compile-cache.js +1 -0
  124. package/dist/src/seal/constants.d.ts +62 -0
  125. package/dist/src/seal/constants.js +1 -0
  126. package/dist/src/seal/deserialize-builder.d.ts +3 -6
  127. package/dist/src/seal/deserialize-builder.js +200 -263
  128. package/dist/src/seal/deserialize-codegen.d.ts +58 -0
  129. package/dist/src/seal/deserialize-codegen.js +64 -0
  130. package/dist/src/seal/enums.d.ts +1 -2
  131. package/dist/src/seal/enums.js +1 -1
  132. package/dist/src/seal/expose-validator.d.ts +2 -2
  133. package/dist/src/seal/expose-validator.js +1 -1
  134. package/dist/src/seal/index.d.ts +3 -0
  135. package/dist/src/seal/index.js +1 -0
  136. package/dist/src/seal/inheritance-merger.d.ts +18 -0
  137. package/dist/src/seal/inheritance-merger.js +1 -0
  138. package/dist/src/seal/interfaces.d.ts +89 -0
  139. package/dist/src/seal/interfaces.js +0 -0
  140. package/dist/src/seal/meta-validator.d.ts +16 -0
  141. package/dist/src/seal/meta-validator.js +1 -0
  142. package/dist/src/seal/seal.d.ts +4 -28
  143. package/dist/src/seal/seal.js +1 -1
  144. package/dist/src/seal/serialize-builder.d.ts +5 -3
  145. package/dist/src/seal/serialize-builder.js +64 -64
  146. package/dist/src/seal/type-normalizer.d.ts +9 -0
  147. package/dist/src/seal/type-normalizer.js +1 -0
  148. package/dist/src/seal/type-resolver.d.ts +2 -0
  149. package/dist/src/seal/type-resolver.js +1 -0
  150. package/dist/src/seal/types.d.ts +6 -0
  151. package/dist/src/seal/types.js +0 -0
  152. package/dist/src/transformers/{collection.transformer.d.ts → collection.d.ts} +1 -1
  153. package/dist/src/transformers/constants.d.ts +2 -0
  154. package/dist/src/transformers/constants.js +1 -0
  155. package/dist/src/transformers/{date.transformer.d.ts → date.d.ts} +1 -1
  156. package/dist/src/transformers/date.js +1 -0
  157. package/dist/src/transformers/index.d.ts +3 -8
  158. package/dist/src/transformers/index.js +1 -1
  159. package/dist/src/transformers/interfaces.d.ts +26 -0
  160. package/dist/src/transformers/interfaces.js +0 -0
  161. package/dist/src/transformers/luxon.d.ts +3 -0
  162. package/dist/src/transformers/luxon.js +1 -0
  163. package/dist/src/transformers/moment.d.ts +3 -0
  164. package/dist/src/transformers/moment.js +1 -0
  165. package/dist/src/transformers/{number.transformer.d.ts → number.d.ts} +1 -1
  166. package/dist/src/transformers/public.d.ts +7 -0
  167. package/dist/src/transformers/public.js +1 -0
  168. package/dist/src/transformers/{string.transformer.d.ts → string.d.ts} +1 -1
  169. package/dist/src/transformers/types.d.ts +3 -0
  170. package/dist/src/transformers/types.js +0 -0
  171. package/package.json +7 -7
  172. package/dist/src/collect.d.ts +0 -15
  173. package/dist/src/collect.js +0 -1
  174. package/dist/src/configure.js +0 -1
  175. package/dist/src/create-rule.js +0 -1
  176. package/dist/src/enums.js +0 -1
  177. package/dist/src/functions/check-call-options.js +0 -1
  178. package/dist/src/functions/deserialize.js +0 -1
  179. package/dist/src/functions/serialize.js +0 -1
  180. package/dist/src/functions/validate.js +0 -1
  181. package/dist/src/interfaces.d.ts +0 -32
  182. package/dist/src/meta-access.d.ts +0 -12
  183. package/dist/src/meta-access.js +0 -1
  184. package/dist/src/rule-plan.js +0 -1
  185. package/dist/src/seal/validate-meta.d.ts +0 -13
  186. package/dist/src/seal/validate-meta.js +0 -1
  187. package/dist/src/transformers/date.transformer.js +0 -1
  188. package/dist/src/transformers/luxon.transformer.d.ts +0 -8
  189. package/dist/src/transformers/luxon.transformer.js +0 -1
  190. package/dist/src/transformers/moment.transformer.d.ts +0 -7
  191. package/dist/src/transformers/moment.transformer.js +0 -1
  192. package/dist/src/types.d.ts +0 -177
  193. /package/dist/src/{errors.d.ts → common/errors.d.ts} +0 -0
  194. /package/dist/src/{errors.js → common/errors.js} +0 -0
  195. /package/dist/src/{interfaces.js → common/interfaces.js} +0 -0
  196. /package/dist/src/{types.js → common/types.js} +0 -0
  197. /package/dist/src/{utils.d.ts → common/utils.d.ts} +0 -0
  198. /package/dist/src/{utils.js → common/utils.js} +0 -0
  199. /package/dist/src/transformers/{collection.transformer.js → collection.js} +0 -0
  200. /package/dist/src/transformers/{number.transformer.js → number.js} +0 -0
  201. /package/dist/src/transformers/{string.transformer.js → string.js} +0 -0
@@ -0,0 +1,10 @@
1
+ import type { RawClassMeta } from './interfaces';
2
+ import { RAW } from '../symbols';
3
+ /** The TC39 decorator-metadata object that carries the baker RAW slot (`Class[Symbol.metadata]`). */
4
+ export type MetaObject = Record<PropertyKey, unknown> & {
5
+ [RAW]?: RawClassMeta;
6
+ };
7
+ /** A class (constructor) viewed as a carrier of decorator metadata. */
8
+ export type MetaCarrier = Function & {
9
+ [Symbol.metadata]?: MetaObject | null;
10
+ };
File without changes
@@ -1,8 +1,8 @@
1
- import type { EmittableRule } from '../types';
1
+ import type { EmittableRule } from './interfaces';
2
2
  declare function arrayContains(values: unknown[]): EmittableRule;
3
3
  declare function arrayNotContains(values: unknown[]): EmittableRule;
4
4
  declare function arrayMinSize(min: number): EmittableRule;
5
5
  declare function arrayMaxSize(max: number): EmittableRule;
6
6
  declare function arrayUnique(identifier?: (val: unknown) => unknown): EmittableRule;
7
- declare const arrayNotEmpty: import("../types").InternalRule;
7
+ declare const arrayNotEmpty: import("./interfaces").InternalRule;
8
8
  export { arrayContains, arrayNotContains, arrayMinSize, arrayMaxSize, arrayUnique, arrayNotEmpty };
@@ -1 +1 @@
1
- import{CacheKey as D,RequiredType as A,RuleOp as F}from"../enums.js";import{makePlannedRule as G,makeRule as H,planCompare as I,planLength as J}from"../rule-plan.js";function arrayContains(b){return H({name:"arrayContains",requiresType:A.Array,constraints:{values:b},validate:(j)=>Array.isArray(j)&&b.every((w)=>j.includes(w)),emit:(j,w)=>{return`if (!refs[${w.addRef(b)}].every(function(v){return ${j}.includes(v);})) ${w.fail("arrayContains")};`}})}function arrayNotContains(b){return H({name:"arrayNotContains",requiresType:A.Array,constraints:{values:b},validate:(j)=>Array.isArray(j)&&b.every((w)=>!j.includes(w)),emit:(j,w)=>{return`if (refs[${w.addRef(b)}].some(function(v){return ${j}.includes(v);})) ${w.fail("arrayNotContains")};`}})}function arrayMinSize(b){const j={cacheKey:D.Length,failure:I(J(),F.Lt,b)};return G({name:"arrayMinSize",requiresType:A.Array,constraints:{min:b},plan:j,validate:(w)=>Array.isArray(w)&&w.length>=b})}function arrayMaxSize(b){const j={cacheKey:D.Length,failure:I(J(),F.Gt,b)};return G({name:"arrayMaxSize",requiresType:A.Array,constraints:{max:b},plan:j,validate:(w)=>Array.isArray(w)&&w.length<=b})}function arrayUnique(b){return H({name:"arrayUnique",requiresType:A.Array,constraints:{},validate:(j)=>{if(!Array.isArray(j))return!1;if(b){const w=j.map(b);return new Set(w).size===w.length}return new Set(j).size===j.length},emit:(j,w)=>{if(b){const B=w.addRef(b);return`{var keys=${j}.map(refs[${B}]);if(new Set(keys).size!==keys.length)${w.fail("arrayUnique")};}`}return`if(new Set(${j}).size!==${j}.length)${w.fail("arrayUnique")};`}})}const Q={cacheKey:D.Length,failure:I(J(),F.Eq,0)};const arrayNotEmpty=G({name:"arrayNotEmpty",requiresType:A.Array,constraints:{},plan:Q,validate:(b)=>Array.isArray(b)&&b.length>0});export{arrayContains,arrayNotContains,arrayMinSize,arrayMaxSize,arrayUnique,arrayNotEmpty};
1
+ import{CacheKey as D}from"../common/index.js";import{RequiredType as A,RuleOp as F}from"./enums.js";import{makePlannedRule as G,makeRule as H,planCompare as I,planLength as J}from"./rule-plan.js";function arrayContains(b){return H({name:"arrayContains",requiresType:A.Array,constraints:{values:b},validate:(j)=>Array.isArray(j)&&b.every((w)=>j.includes(w)),emit:(j,w)=>{return`if (!refs[${w.addRef(b)}].every(function(v){return ${j}.includes(v);})) ${w.fail("arrayContains")};`}})}function arrayNotContains(b){return H({name:"arrayNotContains",requiresType:A.Array,constraints:{values:b},validate:(j)=>Array.isArray(j)&&b.every((w)=>!j.includes(w)),emit:(j,w)=>{return`if (refs[${w.addRef(b)}].some(function(v){return ${j}.includes(v);})) ${w.fail("arrayNotContains")};`}})}function arrayMinSize(b){const j={cacheKey:D.Length,failure:I(J(),F.Lt,b)};return G({name:"arrayMinSize",requiresType:A.Array,constraints:{min:b},plan:j,validate:(w)=>Array.isArray(w)&&w.length>=b})}function arrayMaxSize(b){const j={cacheKey:D.Length,failure:I(J(),F.Gt,b)};return G({name:"arrayMaxSize",requiresType:A.Array,constraints:{max:b},plan:j,validate:(w)=>Array.isArray(w)&&w.length<=b})}function arrayUnique(b){return H({name:"arrayUnique",requiresType:A.Array,constraints:{},validate:(j)=>{if(!Array.isArray(j))return!1;if(b){const w=j.map(b);return new Set(w).size===w.length}return new Set(j).size===j.length},emit:(j,w)=>{if(b){const B=w.addRef(b);return`{var keys=${j}.map(refs[${B}]);if(new Set(keys).size!==keys.length)${w.fail("arrayUnique")};}`}return`if(new Set(${j}).size!==${j}.length)${w.fail("arrayUnique")};`}})}const Q={cacheKey:D.Length,failure:I(J(),F.Eq,0)};const arrayNotEmpty=G({name:"arrayNotEmpty",requiresType:A.Array,constraints:{},plan:Q,validate:(b)=>Array.isArray(b)&&b.length>0});export{arrayContains,arrayNotContains,arrayMinSize,arrayMaxSize,arrayUnique,arrayNotEmpty};
@@ -1,3 +1,3 @@
1
- import type { EmittableRule } from '../types';
2
- export declare const isUint8Array: import("../types").InternalRule;
1
+ import type { EmittableRule } from './interfaces';
2
+ export declare const isUint8Array: import("./interfaces").InternalRule;
3
3
  export declare function isByteSize(min: number, max?: number): EmittableRule;
@@ -1,3 +1,3 @@
1
- import{makeRule as A}from"../rule-plan.js";export const isUint8Array=A({name:"isUint8Array",constraints:{},validate:(f)=>f instanceof Uint8Array,emit:(f,j)=>`if (!(${f} instanceof Uint8Array)) ${j.fail("isUint8Array")};`});export function isByteSize(f,j){return A({name:"isByteSize",constraints:{min:f,max:j},validate:(q)=>{if(!ArrayBuffer.isView(q))return!1;const w=q.byteLength;if(w<f)return!1;if(j!==void 0&&w>j)return!1;return!0},emit:(q,w)=>{let z=`if (!ArrayBuffer.isView(${q})) ${w.fail("isByteSize")};`;z+=`
1
+ import{makeRule as A}from"./rule-plan.js";export const isUint8Array=A({name:"isUint8Array",constraints:{},validate:(f)=>f instanceof Uint8Array,emit:(f,j)=>`if (!(${f} instanceof Uint8Array)) ${j.fail("isUint8Array")};`});export function isByteSize(f,j){return A({name:"isByteSize",constraints:j!==void 0?{min:f,max:j}:{min:f},validate:(q)=>{if(!ArrayBuffer.isView(q))return!1;const w=q.byteLength;if(w<f)return!1;if(j!==void 0&&w>j)return!1;return!0},emit:(q,w)=>{let z=`if (!ArrayBuffer.isView(${q})) ${w.fail("isByteSize")};`;z+=`
2
2
  else if (${q}.byteLength < ${f}) ${w.fail("isByteSize")};`;if(j!==void 0)z+=`
3
3
  else if (${q}.byteLength > ${j}) ${w.fail("isByteSize")};`;return z}})}
@@ -1,4 +1,4 @@
1
- import type { EmittableRule } from '../types';
1
+ import type { EmittableRule } from './interfaces';
2
2
  declare function oneOf(...branches: EmittableRule[]): EmittableRule;
3
3
  declare function arrayEvery(...rules: EmittableRule[]): EmittableRule;
4
4
  export { oneOf, arrayEvery };
@@ -1 +1 @@
1
- import{BakerError as H}from"../errors.js";import{makeRule as F}from"../rule-plan.js";function J(q,D){if(typeof q==="function"&&typeof q.emit==="function"&&typeof q.ruleName==="string")return;throw new H(`${D}: every argument must be a baker rule (function with .emit and .ruleName). Use createRule() or import a rule from @zipbul/baker/rules.`)}function oneOf(...q){if(q.length===0)throw new H("oneOf requires at least one rule.");for(const z of q)J(z,"oneOf");const D={oneOf:q.map((z)=>z.ruleName)};if(q.some((z)=>z.isAsync===!0)){const z=async(j)=>{for(const w of q)if(await w(j))return!0;return!1};return F({name:"oneOf",constraints:D,isAsync:!0,validate:z,emit:(j,w)=>{return`if (!(await refs[${w.addRef(z)}](${j}))) ${w.fail("oneOf")};`}})}return F({name:"oneOf",constraints:D,validate:(z)=>q.some((j)=>j(z)),emit:(z,j)=>{return`if (!(${q.map((C)=>`refs[${j.addRef(C)}](${z})`).join(" || ")})) ${j.fail("oneOf")};`}})}function arrayEvery(...q){if(q.length===0)throw new H("arrayEvery requires at least one rule.");for(const j of q)J(j,"arrayEvery");const D={arrayEvery:q.map((j)=>j.ruleName)};if(q.some((j)=>j.isAsync===!0)){const j=async(w)=>{if(!Array.isArray(w))return!1;for(const C of w)for(const I of q)if(!await I(C))return!1;return!0};return F({name:"arrayEvery",constraints:D,isAsync:!0,validate:j,emit:(w,C)=>{return`if (!(await refs[${C.addRef(j)}](${w}))) ${C.fail("arrayEvery")};`}})}const G=(j)=>q.every((w)=>w(j));return F({name:"arrayEvery",constraints:D,validate:(j)=>Array.isArray(j)&&j.every(G),emit:(j,w)=>{const C=w.addRef(G);return`if (!(Array.isArray(${j}) && ${j}.every(refs[${C}]))) ${w.fail("arrayEvery")};`}})}export{oneOf,arrayEvery};
1
+ import{BakerError as I}from"../common/index.js";import{makeRule as D}from"./rule-plan.js";function oneOf(...q){if(q.length===0)throw new I("oneOf requires at least one rule.");const C={oneOf:q.map((z)=>z.ruleName)};if(q.some((z)=>z.isAsync===!0)){const z=async(g)=>{for(const j of q)if(await j(g))return!0;return!1};return D({name:"oneOf",constraints:C,isAsync:!0,validate:z,emit:(g,j)=>{return`if (!(await refs[${j.addRef(z)}](${g}))) ${j.fail("oneOf")};`}})}const F=q;return D({name:"oneOf",constraints:C,validate:(z)=>F.some((g)=>g(z)),emit:(z,g)=>{return`if (!(${q.map((A)=>`refs[${g.addRef(A)}](${z})`).join(" || ")})) ${g.fail("oneOf")};`}})}function arrayEvery(...q){if(q.length===0)throw new I("arrayEvery requires at least one rule.");const C={arrayEvery:q.map((g)=>g.ruleName)};if(q.some((g)=>g.isAsync===!0)){const g=async(j)=>{if(!Array.isArray(j))return!1;for(const A of j)for(const H of q)if(!await H(A))return!1;return!0};return D({name:"arrayEvery",constraints:C,isAsync:!0,validate:g,emit:(j,A)=>{return`if (!(await refs[${A.addRef(g)}](${j}))) ${A.fail("arrayEvery")};`}})}const F=q,G=(g)=>F.every((j)=>j(g));return D({name:"arrayEvery",constraints:C,validate:(g)=>Array.isArray(g)&&g.every(G),emit:(g,j)=>{const A=j.addRef(G);return`if (!(Array.isArray(${g}) && ${g}.every(refs[${A}]))) ${j.fail("arrayEvery")};`}})}export{oneOf,arrayEvery};
@@ -1,7 +1,7 @@
1
- import type { EmittableRule } from '../types';
1
+ import type { EmittableRule } from './interfaces';
2
2
  export declare function equals(comparison: unknown): EmittableRule;
3
3
  export declare function notEquals(comparison: unknown): EmittableRule;
4
- export declare const isEmpty: import("../types").InternalRule;
5
- export declare const isNotEmpty: import("../types").InternalRule;
4
+ export declare const isEmpty: import("./interfaces").InternalRule;
5
+ export declare const isNotEmpty: import("./interfaces").InternalRule;
6
6
  export declare function isIn(array: unknown[]): EmittableRule;
7
7
  export declare function isNotIn(array: unknown[]): EmittableRule;
@@ -1 +1 @@
1
- import{makeRule as h}from"../rule-plan.js";export function equals(b){return h({name:"equals",constraints:{value:b},validate:(d)=>d===b,emit:(d,f)=>{const g=f.addRef(b);return`if (${d} !== refs[${g}]) ${f.fail("equals")};`}})}export function notEquals(b){return h({name:"notEquals",constraints:{value:b},validate:(d)=>d!==b,emit:(d,f)=>{const g=f.addRef(b);return`if (${d} === refs[${g}]) ${f.fail("notEquals")};`}})}export const isEmpty=h({name:"isEmpty",constraints:{},validate:(b)=>b===void 0||b===null||b==="",emit:(b,d)=>`if (${b} !== undefined && ${b} !== null && ${b} !== '') ${d.fail("isEmpty")};`});export const isNotEmpty=h({name:"isNotEmpty",constraints:{},validate:(b)=>b!==void 0&&b!==null&&b!=="",emit:(b,d)=>`if (${b} === undefined || ${b} === null || ${b} === '') ${d.fail("isNotEmpty")};`});export function isIn(b){const d=new Set(b);return h({name:"isIn",constraints:{values:b},validate:(f)=>d.has(f),emit:(f,g)=>{return`if (!refs[${g.addRef(d)}].has(${f})) ${g.fail("isIn")};`}})}export function isNotIn(b){const d=new Set(b);return h({name:"isNotIn",constraints:{values:b},validate:(f)=>!d.has(f),emit:(f,g)=>{return`if (refs[${g.addRef(d)}].has(${f})) ${g.fail("isNotIn")};`}})}
1
+ import{makeRule as h}from"./rule-plan.js";export function equals(b){return h({name:"equals",constraints:{value:b},validate:(d)=>d===b,emit:(d,f)=>{const g=f.addRef(b);return`if (${d} !== refs[${g}]) ${f.fail("equals")};`}})}export function notEquals(b){return h({name:"notEquals",constraints:{value:b},validate:(d)=>d!==b,emit:(d,f)=>{const g=f.addRef(b);return`if (${d} === refs[${g}]) ${f.fail("notEquals")};`}})}export const isEmpty=h({name:"isEmpty",constraints:{},validate:(b)=>b===void 0||b===null||b==="",emit:(b,d)=>`if (${b} !== undefined && ${b} !== null && ${b} !== '') ${d.fail("isEmpty")};`});export const isNotEmpty=h({name:"isNotEmpty",constraints:{},validate:(b)=>b!==void 0&&b!==null&&b!=="",emit:(b,d)=>`if (${b} === undefined || ${b} === null || ${b} === '') ${d.fail("isNotEmpty")};`});export function isIn(b){const d=new Set(b);return h({name:"isIn",constraints:{values:b},validate:(f)=>d.has(f),emit:(f,g)=>{return`if (!refs[${g.addRef(d)}].has(${f})) ${g.fail("isIn")};`}})}export function isNotIn(b){const d=new Set(b);return h({name:"isNotIn",constraints:{values:b},validate:(f)=>!d.has(f),emit:(f,g)=>{return`if (refs[${g.addRef(d)}].has(${f})) ${g.fail("isNotIn")};`}})}
@@ -0,0 +1,10 @@
1
+ export declare const IBAN_COUNTRY_LENGTH: Record<string, number>;
2
+ export declare const ISO4217_CODES: Set<string>;
3
+ export declare const ISO31661A2_CODES: Set<string>;
4
+ export declare const ISO31661A3_CODES: Set<string>;
5
+ export declare const HASH_REGEXES: Record<string, RegExp>;
6
+ export declare const TAX_ID_REGEXES: Record<string, RegExp>;
7
+ export declare const MOBILE_PHONE_REGEXES: Record<string, RegExp>;
8
+ export declare const POSTAL_CODE_REGEXES: Record<string, RegExp>;
9
+ export declare const IDENTITY_CARD_REGEXES: Record<string, RegExp>;
10
+ export declare const PASSPORT_REGEXES: Record<string, RegExp>;
@@ -0,0 +1 @@
1
+ export const IBAN_COUNTRY_LENGTH={AD:24,AE:23,AL:28,AT:20,AZ:28,BA:20,BE:16,BG:22,BH:22,BR:29,CH:21,CR:22,CY:28,CZ:24,DE:22,DK:18,DO:28,EE:20,ES:24,FI:18,FO:18,FR:27,GB:22,GE:22,GI:23,GL:18,GR:27,GT:28,HR:21,HU:28,IE:22,IL:23,IS:26,IT:27,JO:30,KW:30,KZ:20,LB:28,LC:32,LI:21,LT:20,LU:20,LV:21,MC:27,MD:24,ME:22,MK:19,MR:27,MT:31,MU:30,NL:18,NO:15,PK:24,PL:28,PS:29,PT:25,QA:29,RO:24,RS:22,SA:24,SC:31,SE:24,SI:19,SK:24,SM:27,ST:25,SV:28,TL:23,TN:24,TR:26,UA:29,VA:22,VG:24,XK:20};export const ISO4217_CODES=new Set(["AED","AFN","ALL","AMD","ANG","AOA","ARS","AUD","AWG","AZN","BAM","BBD","BDT","BGN","BHD","BIF","BMD","BND","BOB","BOV","BRL","BSD","BTN","BWP","BYN","BZD","CAD","CDF","CHE","CHF","CHW","CLF","CLP","CNY","COP","COU","CRC","CUC","CUP","CVE","CZK","DJF","DKK","DOP","DZD","EGP","ERN","ETB","EUR","FJD","FKP","GBP","GEL","GHS","GIP","GMD","GNF","GTQ","GYD","HKD","HNL","HRK","HTG","HUF","IDR","ILS","INR","IQD","IRR","ISK","JMD","JOD","JPY","KES","KGS","KHR","KMF","KPW","KRW","KWD","KYD","KZT","LAK","LBP","LKR","LRD","LSL","LYD","MAD","MDL","MGA","MKD","MMK","MNT","MOP","MRU","MUR","MVR","MWK","MXN","MXV","MYR","MZN","NAD","NGN","NIO","NOK","NPR","NZD","OMR","PAB","PEN","PGK","PHP","PKR","PLN","PYG","QAR","RON","RSD","RUB","RWF","SAR","SBD","SCR","SDG","SEK","SGD","SHP","SLE","SLL","SOS","SRD","SSP","STN","SVC","SYP","SZL","THB","TJS","TMT","TND","TOP","TRY","TTD","TWD","TZS","UAH","UGX","USD","USN","UYI","UYU","UYW","UZS","VED","VES","VND","VUV","WST","XAF","XAG","XAU","XBA","XBB","XBC","XBD","XCD","XDR","XOF","XPD","XPF","XPT","XSU","XTS","XUA","YER","ZAR","ZMW","ZWL"]);export const ISO31661A2_CODES=new Set(["AD","AE","AF","AG","AI","AL","AM","AO","AQ","AR","AS","AT","AU","AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BL","BM","BN","BO","BQ","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CU","CV","CW","CX","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FM","FO","FR","GA","GB","GD","GE","GF","GG","GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HM","HN","HR","HT","HU","ID","IE","IL","IM","IN","IO","IQ","IR","IS","IT","JE","JM","JO","JP","KE","KG","KH","KI","KM","KN","KP","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","ME","MF","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PW","PY","QA","RE","RO","RS","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","SS","ST","SV","SX","SY","SZ","TC","TD","TF","TG","TH","TJ","TK","TL","TM","TN","TO","TR","TT","TV","TW","TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","YE","YT","ZA","ZM","ZW"]);export const ISO31661A3_CODES=new Set(["ABW","AFG","AGO","AIA","ALA","ALB","AND","ARE","ARG","ARM","ASM","ATA","ATF","ATG","AUS","AUT","AZE","BDI","BEL","BEN","BES","BFA","BGD","BGR","BHR","BHS","BIH","BLM","BLR","BLZ","BMU","BOL","BRA","BRB","BRN","BTN","BVT","BWA","CAF","CAN","CCK","CHE","CHL","CHN","CIV","CMR","COD","COG","COK","COL","COM","CPV","CRI","CUB","CUW","CXR","CYM","CYP","CZE","DEU","DJI","DMA","DNK","DOM","DZA","ECU","EGY","ERI","ESH","ESP","EST","ETH","FIN","FJI","FLK","FRA","FRO","FSM","GAB","GBR","GEO","GGY","GHA","GIB","GIN","GLP","GMB","GNB","GNQ","GRC","GRD","GRL","GTM","GUF","GUM","GUY","HKG","HMD","HND","HRV","HTI","HUN","IDN","IMN","IND","IOT","IRL","IRN","IRQ","ISL","ISR","ITA","JAM","JEY","JOR","JPN","KAZ","KEN","KGZ","KHM","KIR","KNA","KOR","KWT","LAO","LBN","LBR","LBY","LCA","LIE","LKA","LSO","LTU","LUX","LVA","MAC","MAF","MAR","MCO","MDA","MDG","MDV","MEX","MHL","MKD","MLI","MLT","MMR","MNE","MNG","MNP","MOZ","MRT","MSR","MTQ","MUS","MWI","MYS","MYT","NAM","NCL","NER","NFK","NGA","NIC","NIU","NLD","NOR","NPL","NRU","NZL","OMN","PAK","PAN","PCN","PER","PHL","PLW","PNG","POL","PRI","PRK","PRT","PRY","PSE","PYF","QAT","REU","ROU","RUS","RWA","SAU","SDN","SEN","SGP","SGS","SHN","SJM","SLB","SLE","SLV","SMR","SOM","SPM","SRB","SSD","STP","SUR","SVK","SVN","SWE","SWZ","SXM","SYC","SYR","TCA","TCD","TGO","THA","TJK","TKL","TKM","TLS","TON","TTO","TUN","TUR","TUV","TWN","TZA","UGA","UKR","UMI","URY","USA","UZB","VAT","VCT","VEN","VGB","VIR","VNM","VUT","WLF","WSM","YEM","ZAF","ZMB","ZWE"]);export const HASH_REGEXES={md5:/^[a-f0-9]{32}$/i,md4:/^[a-f0-9]{32}$/i,md2:/^[a-f0-9]{32}$/i,sha1:/^[a-f0-9]{40}$/i,sha256:/^[a-f0-9]{64}$/i,sha384:/^[a-f0-9]{96}$/i,sha512:/^[a-f0-9]{128}$/i,ripemd128:/^[a-f0-9]{32}$/i,ripemd160:/^[a-f0-9]{40}$/i,"tiger128,3":/^[a-f0-9]{32}$/i,"tiger128,4":/^[a-f0-9]{32}$/i,"tiger160,3":/^[a-f0-9]{40}$/i,"tiger160,4":/^[a-f0-9]{40}$/i,"tiger192,3":/^[a-f0-9]{48}$/i,"tiger192,4":/^[a-f0-9]{48}$/i,crc32:/^[a-f0-9]{8}$/i,crc32b:/^[a-f0-9]{8}$/i};export const TAX_ID_REGEXES={US:/^\d{2}-\d{7}$/,KR:/^\d{3}-\d{2}-\d{5}$/,DE:/^\d{11}$/,FR:/^[0-9]{13}$/,GB:/^\d{10}$/,IT:/^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/i,ES:/^[0-9A-Z]\d{7}[0-9A-Z]$/i,AU:/^\d{11}$/,CA:/^\d{9}$/,IN:/^[A-Z]{5}\d{4}[A-Z]$/i};export const MOBILE_PHONE_REGEXES={"ko-KR":/^(\+?82|0)1[016789]\d{7,8}$/,"en-US":/^\+?1?[2-9]\d{2}[2-9]\d{6}$/,"zh-CN":/^(\+?86)?1[3-9]\d{9}$/,"zh-TW":/^(\+?886)?9\d{8}$/,"ja-JP":/^(\+?81)?0?[789]0[0-9]{8}$/,"de-DE":/^(\+?49)?1(5\d|6[0-9]|7[0-9])\d{8}$/,"fr-FR":/^(\+?33)?[67]\d{8}$/,"en-GB":/^(\+?44)?7[1-9]\d{8}$/,"ru-RU":/^(\+?7)?9\d{9}$/,"pt-BR":/^(\+?55)?[1-9]{2}9?\d{8}$/,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N:/^[A-Z]\d{7}$/i,IR:/^[A-Z]\d{8}$/i,IS:/^(A)\d{7}$/i,IT:/^[A-Z0-9]{9}$/i,JO:/^[A-Z]{2}\d{7}$/i,JP:/^[A-Z]{2}\d{7}$/i,KR:/^[A-Z][A-Z0-9]\d{7}$/i,KW:/^\d{8}$/,KZ:/^[A-Z]\d{8}$/i,LI:/^[A-Z]\d{6}X$/i,LT:/^[A-Z0-9]{8}$/i,LU:/^[A-Z0-9]{8}$/i,LV:/^[A-Z0-9]{2}\d{7}$/i,LY:/^[A-Z]{2}\d{7}$/i,MA:/^[A-Z0-9]{2}\d{7}$/i,MD:/^[A-Z]{2}\d{7}$/i,ME:/^[A-Z]{2}\d{7}$/i,MK:/^[A-Z]\d{7}$/i,MT:/^\d{7}$/,MX:/^[A-Z]\d{8}$/i,MY:/^[AHK]\d{8}[A-Z]$/i,NL:/^[A-NP-Z]{2}[A-NP-Z0-9]{6}\d$/i,NO:/^\d{9}$/,NZ:/^[A-Z]{2}\d{6}$/i,PH:/^[A-Z]\d{7}[A-Z]$/i,PK:/^[A-Z]{2}\d{7}$/i,PL:/^[A-Z]{2}\d{7}$/i,PT:/^[A-Z]\d{6}$/i,RO:/^\d{8}$/,RS:/^\d{9}$/,RU:/^\d{9}$/,SA:/^[A-Z]\d{8}$/i,SE:/^\d{8}$/,SL:/^(P)[A-Z]\d{7}$/i,SK:/^[0-9A-Z]\d{7}$/i,TH:/^[A-Z]{1,2}\d{6,7}$/i,TN:/^\d{8}$/,TR:/^[A-Z]\d{8}$/i,TW:/^[A-Z]\d{9}$/i,UA:/^[A-Z]{2}\d{6}$/i,US:/^\d{9}$/,ZA:/^[A-Z]\d{8}$/i};
@@ -1,5 +1,5 @@
1
1
  import type { RequiredType } from './enums';
2
- import type { EmittableRule } from './types';
2
+ import type { EmittableRule } from './interfaces';
3
3
  export interface CreateRuleOptions {
4
4
  /** Rule name. Used as the error code. */
5
5
  name: string;
@@ -0,0 +1 @@
1
+ import{BakerError as K,isAsyncFunction as U,isPromiseLike as V}from"../common/index.js";import{defineRuleMetadata as W}from"./rule-metadata.js";export function createRule(b,Q){const z=typeof b==="string"?b:b.name,C=typeof b==="string"?Q:b.validate;if(typeof C!=="function")throw new K(`createRule(${z}): a validate function is required.`);const I=typeof b==="object"?b.constraints:void 0,J=typeof b==="object"?b.requiresType:void 0,D=U(C),j=function(H){const w=C(H);if(!D&&V(w))throw new K(`createRule(${z}): sync rule returned Promise. Declare the validator with async if it is asynchronous.`);return w};j.emit=function(H,w){const S=w.addRef(j);return`if(!(${D?"await ":""}refs[${S}](${H}))) ${w.fail(z)};`};const G={emit:j.emit,ruleName:z,isAsync:D};if(I!==void 0)G.constraints=I;if(J!==void 0)G.requiresType=J;W(j,G);return j}
@@ -1,3 +1,3 @@
1
- import type { EmittableRule } from '../types';
1
+ import type { EmittableRule } from './interfaces';
2
2
  export declare function minDate(date: Date): EmittableRule;
3
3
  export declare function maxDate(date: Date): EmittableRule;
@@ -1 +1 @@
1
- import{CacheKey as A,RequiredType as B,RuleOp as w}from"../enums.js";import{makePlannedRule as D,planCompare as x,planLiteral as E,planOr as F,planTime as b}from"../rule-plan.js";export function minDate(f){const g=f.getTime(),z={cacheKey:A.Time,failure:F(x(b(),w.Neq,b()),x(b(),w.Lt,E(g)))};return D({name:"minDate",requiresType:B.Date,constraints:{min:f.toISOString()},plan:z,validate:(j)=>j instanceof Date&&j.getTime()>=g})}export function maxDate(f){const g=f.getTime(),z={cacheKey:A.Time,failure:F(x(b(),w.Neq,b()),x(b(),w.Gt,E(g)))};return D({name:"maxDate",requiresType:B.Date,constraints:{max:f.toISOString()},plan:z,validate:(j)=>j instanceof Date&&j.getTime()<=g})}
1
+ import{CacheKey as A}from"../common/index.js";import{RequiredType as B,RuleOp as w}from"./enums.js";import{makePlannedRule as D,planCompare as x,planLiteral as E,planOr as F,planTime as b}from"./rule-plan.js";export function minDate(f){const g=f.getTime(),z={cacheKey:A.Time,failure:F(x(b(),w.Neq,b()),x(b(),w.Lt,E(g)))};return D({name:"minDate",requiresType:B.Date,constraints:{min:f.toISOString()},plan:z,validate:(j)=>j instanceof Date&&j.getTime()>=g})}export function maxDate(f){const g=f.getTime(),z={cacheKey:A.Time,failure:F(x(b(),w.Neq,b()),x(b(),w.Gt,E(g)))};return D({name:"maxDate",requiresType:B.Date,constraints:{max:f.toISOString()},plan:z,validate:(j)=>j instanceof Date&&j.getTime()<=g})}
@@ -7,21 +7,6 @@ export declare enum RequiredType {
7
7
  Array = "array",
8
8
  Object = "object"
9
9
  }
10
- /** Direction of a (de)serialization pass. */
11
- export declare enum Direction {
12
- Deserialize = "deserialize",
13
- Serialize = "serialize"
14
- }
15
- /** Collection container type for a nested field. */
16
- export declare enum CollectionType {
17
- Map = "Map",
18
- Set = "Set"
19
- }
20
- /** Cached accessor a RulePlan reuses across checks. */
21
- export declare enum CacheKey {
22
- Length = "length",
23
- Time = "time"
24
- }
25
10
  /** Discriminant for a RulePlanExpr node. */
26
11
  export declare enum RulePlanExprKind {
27
12
  Value = "value",
@@ -44,8 +29,3 @@ export declare enum RuleOp {
44
29
  Eq = "===",
45
30
  Neq = "!=="
46
31
  }
47
- /** Direction in which a field is excluded. */
48
- export declare enum ExcludeMode {
49
- DeserializeOnly = "deserializeOnly",
50
- SerializeOnly = "serializeOnly"
51
- }
@@ -0,0 +1 @@
1
+ export var RequiredType;((b)=>{b.String="string";b.Number="number";b.Boolean="boolean";b.Date="date";b.Array="array";b.Object="object"})(RequiredType||={});export var RulePlanExprKind;((f)=>{f.Value="value";f.Member="member";f.Call0="call0";f.Literal="literal"})(RulePlanExprKind||={});export var RulePlanCheckKind;((j)=>{j.Compare="compare";j.And="and";j.Or="or"})(RulePlanCheckKind||={});export var RuleOp;((b)=>{b.Lt="<";b.Lte="<=";b.Gt=">";b.Gte=">=";b.Eq="===";b.Neq="!=="})(RuleOp||={});
@@ -1,13 +1,5 @@
1
- export { isString, isNumber, isBoolean, isDate, isEnum, isInt, isArray, isObject, isRegExp, isFunction, isStatelessRegExp, } from './typechecker';
2
- export type { IsNumberOptions } from './typechecker';
3
- export { oneOf, arrayEvery } from './combinators';
4
- export { min, max, isPositive, isNegative, isDivisibleBy } from './number';
5
- export { minDate, maxDate } from './date';
6
- export { equals, notEquals, isEmpty, isNotEmpty, isIn, isNotIn } from './common';
7
- export { minLength, maxLength, length, contains, notContains, matches, isLowercase, isUppercase, isAscii, isAlpha, isAlphanumeric, isHttpToken, isOrigin, isCorsOrigin, isBooleanString, isNumberString, isDecimal, isFullWidth, isHalfWidth, isVariableWidth, isMultibyte, isSurrogatePair, isHexadecimal, isOctal, isEmail, isURL, isUUID, isIP, isHexColor, isRgbColor, isHSL, isMACAddress, isISBN, isISIN, isISO8601, isISRC, isISSN, isJWT, isLatLong, isLocale, isDataURI, isFQDN, isPort, isEAN, isISO31661Alpha2, isISO31661Alpha3, isBIC, isFirebasePushId, isSemVer, isMongoId, isJSON, isBase32, isBase58, isBase64, isDateString, isMimeType, isCurrency, isMagnetURI, isCreditCard, isIBAN, isByteLength, isHash, isRFC3339, isMilitaryTime, isLatitude, isLongitude, isEthereumAddress, isBtcAddress, isISO4217CurrencyCode, isPhoneNumber, isStrongPassword, isTaxId, isULID, isCUID2, } from './string';
8
- export type { IsURLOptions, IsBase64Options, IsMACAddressOptions, IsIBANOptions, IsISSNOptions, IsFQDNOptions, IsISO8601Options, IsNumberStringOptions, IsStrongPasswordOptions, } from './string';
9
- export { arrayContains, arrayNotContains, arrayMinSize, arrayMaxSize, arrayUnique, arrayNotEmpty } from './array';
10
- export { isNotEmptyObject, isInstance } from './object';
11
- export type { IsNotEmptyObjectOptions } from './object';
12
- export { isMobilePhone, isPostalCode, isIdentityCard, isPassportNumber } from './locales';
13
- export { isUint8Array, isByteSize } from './binary';
1
+ export * from './public';
2
+ export { emitRulePlan } from './rule-plan';
3
+ export { RequiredType } from './enums';
4
+ export type { EmittableRule, InternalRule, EmitContext } from './interfaces';
5
+ export type { RulePlanCache } from './types';
@@ -1 +1 @@
1
- export{isString,isNumber,isBoolean,isDate,isEnum,isInt,isArray,isObject,isRegExp,isFunction,isStatelessRegExp}from"./typechecker.js";export{oneOf,arrayEvery}from"./combinators.js";export{min,max,isPositive,isNegative,isDivisibleBy}from"./number.js";export{minDate,maxDate}from"./date.js";export{equals,notEquals,isEmpty,isNotEmpty,isIn,isNotIn}from"./common.js";export{minLength,maxLength,length,contains,notContains,matches,isLowercase,isUppercase,isAscii,isAlpha,isAlphanumeric,isHttpToken,isOrigin,isCorsOrigin,isBooleanString,isNumberString,isDecimal,isFullWidth,isHalfWidth,isVariableWidth,isMultibyte,isSurrogatePair,isHexadecimal,isOctal,isEmail,isURL,isUUID,isIP,isHexColor,isRgbColor,isHSL,isMACAddress,isISBN,isISIN,isISO8601,isISRC,isISSN,isJWT,isLatLong,isLocale,isDataURI,isFQDN,isPort,isEAN,isISO31661Alpha2,isISO31661Alpha3,isBIC,isFirebasePushId,isSemVer,isMongoId,isJSON,isBase32,isBase58,isBase64,isDateString,isMimeType,isCurrency,isMagnetURI,isCreditCard,isIBAN,isByteLength,isHash,isRFC3339,isMilitaryTime,isLatitude,isLongitude,isEthereumAddress,isBtcAddress,isISO4217CurrencyCode,isPhoneNumber,isStrongPassword,isTaxId,isULID,isCUID2}from"./string.js";export{arrayContains,arrayNotContains,arrayMinSize,arrayMaxSize,arrayUnique,arrayNotEmpty}from"./array.js";export{isNotEmptyObject,isInstance}from"./object.js";export{isMobilePhone,isPostalCode,isIdentityCard,isPassportNumber}from"./locales.js";export{isUint8Array,isByteSize}from"./binary.js";
1
+ export*from"./public.js";export{emitRulePlan}from"./rule-plan.js";export{RequiredType}from"./enums.js";
@@ -0,0 +1,43 @@
1
+ import type { CacheKey } from '../common';
2
+ import type { SealedExecutors } from '../seal';
3
+ import type { RequiredType } from './enums';
4
+ import type { RulePlanCheck } from './types';
5
+ export interface EmitContext {
6
+ /** Register a RegExp in the reference array, return its index */
7
+ addRegex(re: RegExp): number;
8
+ /** Register in the reference array, return its index — functions, arrays, Sets, primitives, etc. */
9
+ addRef(value: unknown): number;
10
+ /** Register a SealedExecutors object in the reference array — for nested @Type DTOs */
11
+ addExecutor(executor: SealedExecutors<unknown>): number;
12
+ /** Generate a failure code string from an error code — path is bound by the builder */
13
+ fail(code: string): string;
14
+ /** Whether error collection mode is enabled (= !stopAtFirstError) */
15
+ collectErrors: boolean;
16
+ /** Whether this emit runs inside a type gate (typeof/instanceof already verified) */
17
+ insideTypeGate?: boolean;
18
+ /** @internal Path expression for inline nested — used by makeRuleEmitCtx */
19
+ pathExpr?: string;
20
+ }
21
+ export interface EmittableRule {
22
+ (value: unknown): boolean | Promise<boolean>;
23
+ emit(varName: string, ctx: EmitContext): string;
24
+ readonly ruleName: string;
25
+ /**
26
+ * Meta for the builder to determine whether to insert a typeof guard.
27
+ * Only set for rules that assume a specific type (e.g., isEmail → 'string').
28
+ * `@IsString` itself is undefined (it includes its own typeof check).
29
+ */
30
+ readonly requiresType?: RequiredType;
31
+ /** Expose rule parameters for external reading */
32
+ readonly constraints?: Record<string, unknown>;
33
+ /** true when the rule is explicitly async and must be awaited */
34
+ readonly isAsync?: boolean;
35
+ }
36
+ /** @internal internal rule shape used by builders for optimization metadata */
37
+ export interface InternalRule extends EmittableRule {
38
+ readonly plan?: RulePlan;
39
+ }
40
+ export interface RulePlan {
41
+ cacheKey?: CacheKey;
42
+ failure: RulePlanCheck;
43
+ }
File without changes
@@ -1,4 +1,4 @@
1
- import type { EmittableRule } from '../types';
1
+ import type { EmittableRule } from './interfaces';
2
2
  declare function isMobilePhone(locale: string): EmittableRule;
3
3
  declare function isPostalCode(locale: string): EmittableRule;
4
4
  declare function isIdentityCard(locale: string): EmittableRule;
@@ -1 +1 @@
1
- import{RequiredType as Q}from"../enums.js";import{BakerError as U}from"../errors.js";import{makeRule as V}from"../rule-plan.js";const W={"ko-KR":/^(\+?82|0)1[016789]\d{7,8}$/,"en-US":/^\+?1?[2-9]\d{2}[2-9]\d{6}$/,"zh-CN":/^(\+?86)?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i,TN:/^\d{8}$/,TR:/^[A-Z]\d{8}$/i,TW:/^[A-Z]\d{9}$/i,UA:/^[A-Z]{2}\d{6}$/i,US:/^\d{9}$/,ZA:/^[A-Z]\d{8}$/i};function isPassportNumber(f){return w("isPassportNumber",f,h)}function w(f,z,K){const F=K[z];if(!F)throw new U(`Unsupported locale: "${z}" for ${f}`);return V({name:f,requiresType:Q.String,constraints:{locale:z},validate:(j)=>typeof j==="string"&&F.test(j),emit:(j,J)=>{return`if (!re[${J.addRegex(F)}].test(${j})) ${J.fail(f)};`}})}export{isMobilePhone,isPostalCode,isIdentityCard,isPassportNumber};
1
+ import{BakerError as Q}from"../common/index.js";import{MOBILE_PHONE_REGEXES as U,POSTAL_CODE_REGEXES as V,IDENTITY_CARD_REGEXES as W,PASSPORT_REGEXES as Z}from"./constants.js";import{RequiredType as $}from"./enums.js";import{makeRule as h}from"./rule-plan.js";function isMobilePhone(f){return w("isMobilePhone",f,U)}function isPostalCode(f){return w("isPostalCode",f,V)}function isIdentityCard(f){return w("isIdentityCard",f,W)}function isPassportNumber(f){return w("isPassportNumber",f,Z)}function w(f,z,K){const F=K[z];if(!F)throw new Q(`Unsupported locale: "${z}" for ${f}`);return h({name:f,requiresType:$.String,constraints:{locale:z},validate:(j)=>typeof j==="string"&&F.test(j),emit:(j,J)=>{return`if (!re[${J.addRegex(F)}].test(${j})) ${J.fail(f)};`}})}export{isMobilePhone,isPostalCode,isIdentityCard,isPassportNumber};
@@ -1,10 +1,10 @@
1
- import type { EmittableRule } from '../types';
1
+ import type { EmittableRule } from './interfaces';
2
2
  export declare function min(n: number, opts?: {
3
3
  exclusive?: boolean;
4
4
  }): EmittableRule;
5
5
  export declare function max(n: number, opts?: {
6
6
  exclusive?: boolean;
7
7
  }): EmittableRule;
8
- export declare const isPositive: import("../types").InternalRule;
9
- export declare const isNegative: import("../types").InternalRule;
8
+ export declare const isPositive: import("./interfaces").InternalRule;
9
+ export declare const isNegative: import("./interfaces").InternalRule;
10
10
  export declare function isDivisibleBy(n: number): EmittableRule;
@@ -1 +1 @@
1
- import{RequiredType as A,RuleOp as h}from"../enums.js";import{BakerError as I}from"../errors.js";import{makePlannedRule as D,makeRule as J,planCompare as z,planLiteral as F,planOr as G,planValue as f}from"../rule-plan.js";export function min(b,w){if(!Number.isFinite(b))throw new I(`min: bound must be a finite number, got ${b}`);const j=w?.exclusive??!1,H={failure:G(z(f(),h.Neq,f()),z(f(),j?h.Lte:h.Lt,F(b)))};return D({name:"min",requiresType:A.Number,constraints:j?{min:b,exclusive:!0}:{min:b},plan:H,validate:j?(g)=>typeof g==="number"&&g>b:(g)=>typeof g==="number"&&g>=b})}export function max(b,w){if(!Number.isFinite(b))throw new I(`max: bound must be a finite number, got ${b}`);const j=w?.exclusive??!1,H={failure:G(z(f(),h.Neq,f()),z(f(),j?h.Gte:h.Gt,F(b)))};return D({name:"max",requiresType:A.Number,constraints:j?{max:b,exclusive:!0}:{max:b},plan:H,validate:j?(g)=>typeof g==="number"&&g<b:(g)=>typeof g==="number"&&g<=b})}export const isPositive=D({name:"isPositive",requiresType:A.Number,constraints:{min:0,exclusive:!0},plan:{failure:G(z(f(),h.Neq,f()),z(f(),h.Lte,F(0)))},validate:(b)=>typeof b==="number"&&b>0});export const isNegative=D({name:"isNegative",requiresType:A.Number,constraints:{max:0,exclusive:!0},plan:{failure:G(z(f(),h.Neq,f()),z(f(),h.Gte,F(0)))},validate:(b)=>typeof b==="number"&&b<0});export function isDivisibleBy(b){if(b===0)throw new I("isDivisibleBy: divisor must not be zero");return J({name:"isDivisibleBy",requiresType:A.Number,constraints:{divisor:b},validate:(w)=>typeof w==="number"&&w%b===0,emit:(w,j)=>`if (${w} % ${b} !== 0) ${j.fail("isDivisibleBy")};`})}
1
+ import{BakerError as I}from"../common/index.js";import{RequiredType as A,RuleOp as h}from"./enums.js";import{makePlannedRule as D,makeRule as J,planCompare as z,planLiteral as F,planOr as G,planValue as f}from"./rule-plan.js";export function min(b,w){if(!Number.isFinite(b))throw new I(`min: bound must be a finite number, got ${b}`);const j=w?.exclusive??!1,H={failure:G(z(f(),h.Neq,f()),z(f(),j?h.Lte:h.Lt,F(b)))};return D({name:"min",requiresType:A.Number,constraints:j?{min:b,exclusive:!0}:{min:b},plan:H,validate:j?(g)=>typeof g==="number"&&g>b:(g)=>typeof g==="number"&&g>=b})}export function max(b,w){if(!Number.isFinite(b))throw new I(`max: bound must be a finite number, got ${b}`);const j=w?.exclusive??!1,H={failure:G(z(f(),h.Neq,f()),z(f(),j?h.Gte:h.Gt,F(b)))};return D({name:"max",requiresType:A.Number,constraints:j?{max:b,exclusive:!0}:{max:b},plan:H,validate:j?(g)=>typeof g==="number"&&g<b:(g)=>typeof g==="number"&&g<=b})}export const isPositive=D({name:"isPositive",requiresType:A.Number,constraints:{min:0,exclusive:!0},plan:{failure:G(z(f(),h.Neq,f()),z(f(),h.Lte,F(0)))},validate:(b)=>typeof b==="number"&&b>0});export const isNegative=D({name:"isNegative",requiresType:A.Number,constraints:{max:0,exclusive:!0},plan:{failure:G(z(f(),h.Neq,f()),z(f(),h.Gte,F(0)))},validate:(b)=>typeof b==="number"&&b<0});export function isDivisibleBy(b){if(b===0)throw new I("isDivisibleBy: divisor must not be zero");return J({name:"isDivisibleBy",requiresType:A.Number,constraints:{divisor:b},validate:(w)=>typeof w==="number"&&w%b===0,emit:(w,j)=>`if (${w} % ${b} !== 0) ${j.fail("isDivisibleBy")};`})}
@@ -1,4 +1,4 @@
1
- import type { EmittableRule } from '../types';
1
+ import type { EmittableRule } from './interfaces';
2
2
  export interface IsNotEmptyObjectOptions {
3
3
  /** Whether to ignore keys with null/undefined values (default: false — do not ignore) */
4
4
  nullable?: boolean;
@@ -1 +1 @@
1
- import{RequiredType as C}from"../enums.js";import{makeRule as B}from"../rule-plan.js";export function isNotEmptyObject(w){const z=(f)=>{if(f===null||typeof f!=="object"||Array.isArray(f))return!1;const h=f;if(w?.nullable){for(const A in h)if(h[A]!=null)return!0;return!1}for(const A in h)return!0;return!1};return B({name:"isNotEmptyObject",requiresType:C.Object,constraints:{nullable:w?.nullable},validate:z,emit:(f,h)=>{if(w?.nullable)return`{var __ne=false;for(var __k in ${f}){if(${f}[__k]!=null){__ne=true;break;}}if(!__ne) ${h.fail("isNotEmptyObject")};}`;return`{var __ne=false;for(var __k in ${f}){__ne=true;break;}if(!__ne) ${h.fail("isNotEmptyObject")};}`}})}export function isInstance(w){return B({name:"isInstance",constraints:{type:w.name},validate:(z)=>z instanceof w,emit:(z,f)=>{const h=f.addRef(w);return`if (!(${z} instanceof refs[${h}])) ${f.fail("isInstance")};`}})}
1
+ import{RequiredType as C}from"./enums.js";import{makeRule as B}from"./rule-plan.js";export function isNotEmptyObject(h){const z=(f)=>{if(f===null||typeof f!=="object"||Array.isArray(f))return!1;const w=f;if(h?.nullable){for(const A in w)if(w[A]!=null)return!0;return!1}for(const A in w)return!0;return!1};return B({name:"isNotEmptyObject",requiresType:C.Object,constraints:h?.nullable!==void 0?{nullable:h.nullable}:{},validate:z,emit:(f,w)=>{if(h?.nullable)return`{var __ne=false;for(var __k in ${f}){if(${f}[__k]!=null){__ne=true;break;}}if(!__ne) ${w.fail("isNotEmptyObject")};}`;return`{var __ne=false;for(var __k in ${f}){__ne=true;break;}if(!__ne) ${w.fail("isNotEmptyObject")};}`}})}export function isInstance(h){return B({name:"isInstance",constraints:{type:h.name},validate:(z)=>z instanceof h,emit:(z,f)=>{const w=f.addRef(h);return`if (!(${z} instanceof refs[${w}])) ${f.fail("isInstance")};`}})}
@@ -0,0 +1,14 @@
1
+ export { createRule } from './create-rule';
2
+ export { isString, isNumber, isBoolean, isDate, isEnum, isInt, isArray, isObject, isRegExp, isFunction, isStatelessRegExp, } from './typechecker';
3
+ export type { IsNumberOptions } from './typechecker';
4
+ export { oneOf, arrayEvery } from './combinators';
5
+ export { min, max, isPositive, isNegative, isDivisibleBy } from './number';
6
+ export { minDate, maxDate } from './date';
7
+ export { equals, notEquals, isEmpty, isNotEmpty, isIn, isNotIn } from './common';
8
+ export { minLength, maxLength, length, contains, notContains, matches, isLowercase, isUppercase, isAscii, isAlpha, isAlphanumeric, isHttpToken, isOrigin, isCorsOrigin, isBooleanString, isNumberString, isDecimal, isFullWidth, isHalfWidth, isVariableWidth, isMultibyte, isSurrogatePair, isHexadecimal, isOctal, isEmail, isURL, isUUID, isIP, isHexColor, isRgbColor, isHSL, isMACAddress, isISBN, isISIN, isISO8601, isISRC, isISSN, isJWT, isLatLong, isLocale, isDataURI, isFQDN, isPort, isEAN, isISO31661Alpha2, isISO31661Alpha3, isBIC, isFirebasePushId, isSemVer, isMongoId, isJSON, isBase32, isBase58, isBase64, isDateString, isMimeType, isCurrency, isMagnetURI, isCreditCard, isIBAN, isByteLength, isHash, isRFC3339, isMilitaryTime, isLatitude, isLongitude, isEthereumAddress, isBtcAddress, isISO4217CurrencyCode, isPhoneNumber, isStrongPassword, isTaxId, isULID, isCUID2, } from './string';
9
+ export type { IsURLOptions, IsBase64Options, IsMACAddressOptions, IsIBANOptions, IsISSNOptions, IsFQDNOptions, IsISO8601Options, IsNumberStringOptions, IsStrongPasswordOptions, } from './string';
10
+ export { arrayContains, arrayNotContains, arrayMinSize, arrayMaxSize, arrayUnique, arrayNotEmpty } from './array';
11
+ export { isNotEmptyObject, isInstance } from './object';
12
+ export type { IsNotEmptyObjectOptions } from './object';
13
+ export { isMobilePhone, isPostalCode, isIdentityCard, isPassportNumber } from './locales';
14
+ export { isUint8Array, isByteSize } from './binary';
@@ -0,0 +1 @@
1
+ export{createRule}from"./create-rule.js";export{isString,isNumber,isBoolean,isDate,isEnum,isInt,isArray,isObject,isRegExp,isFunction,isStatelessRegExp}from"./typechecker.js";export{oneOf,arrayEvery}from"./combinators.js";export{min,max,isPositive,isNegative,isDivisibleBy}from"./number.js";export{minDate,maxDate}from"./date.js";export{equals,notEquals,isEmpty,isNotEmpty,isIn,isNotIn}from"./common.js";export{minLength,maxLength,length,contains,notContains,matches,isLowercase,isUppercase,isAscii,isAlpha,isAlphanumeric,isHttpToken,isOrigin,isCorsOrigin,isBooleanString,isNumberString,isDecimal,isFullWidth,isHalfWidth,isVariableWidth,isMultibyte,isSurrogatePair,isHexadecimal,isOctal,isEmail,isURL,isUUID,isIP,isHexColor,isRgbColor,isHSL,isMACAddress,isISBN,isISIN,isISO8601,isISRC,isISSN,isJWT,isLatLong,isLocale,isDataURI,isFQDN,isPort,isEAN,isISO31661Alpha2,isISO31661Alpha3,isBIC,isFirebasePushId,isSemVer,isMongoId,isJSON,isBase32,isBase58,isBase64,isDateString,isMimeType,isCurrency,isMagnetURI,isCreditCard,isIBAN,isByteLength,isHash,isRFC3339,isMilitaryTime,isLatitude,isLongitude,isEthereumAddress,isBtcAddress,isISO4217CurrencyCode,isPhoneNumber,isStrongPassword,isTaxId,isULID,isCUID2}from"./string.js";export{arrayContains,arrayNotContains,arrayMinSize,arrayMaxSize,arrayUnique,arrayNotEmpty}from"./array.js";export{isNotEmptyObject,isInstance}from"./object.js";export{isMobilePhone,isPostalCode,isIdentityCard,isPassportNumber}from"./locales.js";export{isUint8Array,isByteSize}from"./binary.js";
@@ -1,4 +1,4 @@
1
- import type { EmittableRule, InternalRule, RulePlan } from './types';
1
+ import type { EmittableRule, InternalRule, RulePlan } from './interfaces';
2
2
  interface RuleMetadata {
3
3
  emit: EmittableRule['emit'];
4
4
  ruleName: string;
@@ -1 +1 @@
1
- export function defineRuleMetadata(q,b){const j=q;j.emit=b.emit;j.ruleName=b.ruleName;if(b.requiresType!==void 0)j.requiresType=b.requiresType;if(b.constraints!==void 0)j.constraints=b.constraints;if(b.isAsync!==void 0)j.isAsync=b.isAsync;if(b.plan)j.plan=b.plan}
1
+ export function defineRuleMetadata(q,b){const j=q;j.emit=b.emit;j.ruleName=b.ruleName;if(b.requiresType!==void 0)j.requiresType=b.requiresType;if(b.constraints!==void 0)j.constraints=b.constraints;if(b.isAsync!==void 0)j.isAsync=b.isAsync;if(b.plan!==void 0)j.plan=b.plan}
@@ -1,13 +1,10 @@
1
1
  import type { RequiredType } from './enums';
2
- import type { EmitContext, InternalRule, RulePlan, RulePlanCheck, RulePlanExpr } from './types';
2
+ import type { EmitContext, InternalRule, RulePlan } from './interfaces';
3
+ import type { RulePlanCache, RulePlanCheck, RulePlanExpr } from './types';
3
4
  import { RuleOp } from './enums';
4
- type RulePlanCache = {
5
- length?: string;
6
- time?: string;
7
- };
8
5
  declare const planValue: () => RulePlanExpr;
9
- declare const planLength: (object?: RulePlanExpr) => RulePlanExpr;
10
- declare const planTime: (object?: RulePlanExpr) => RulePlanExpr;
6
+ declare const planLength: () => RulePlanExpr;
7
+ declare const planTime: () => RulePlanExpr;
11
8
  declare const planLiteral: (value: number) => RulePlanExpr;
12
9
  declare const planCompare: (left: RulePlanExpr, op: RuleOp, right: number | RulePlanExpr) => RulePlanCheck;
13
10
  declare const planOr: (...checks: RulePlanCheck[]) => RulePlanCheck;
@@ -0,0 +1 @@
1
+ import{RuleOp as X,RulePlanCheckKind as H,RulePlanExprKind as D}from"./enums.js";import{defineRuleMetadata as Y}from"./rule-metadata.js";const planValue=()=>({kind:D.Value});const planLength=()=>({kind:D.Member,property:"length"});const planTime=()=>({kind:D.Call0,method:"getTime"});const planLiteral=(z)=>({kind:D.Literal,value:z});const planCompare=(z,A,B)=>({kind:H.Compare,left:z,op:A,right:typeof B==="number"?planLiteral(B):B});const planOr=(...z)=>({kind:H.Or,checks:z});function makePlannedRule(z){const A={name:z.name,requiresType:z.requiresType,plan:z.plan,validate:z.validate,emit:(B,F)=>emitRulePlan(B,F,z.name,z.plan,void 0,F.insideTypeGate)};if(z.constraints!==void 0)A.constraints=z.constraints;return makeRule(A)}function makeRule(z){const A=(F)=>z.validate(F),B={emit:z.emit,ruleName:z.name,constraints:z.constraints??{}};if(z.requiresType!==void 0)B.requiresType=z.requiresType;if(z.isAsync!==void 0)B.isAsync=z.isAsync;if(z.plan!==void 0)B.plan=z.plan;Y(A,B);return A}function emitRulePlan(z,A,B,F,I,U){const W=U?Z(F.failure):F.failure;return`if (${Q(W,z,I)}) ${A.fail(B)};`}function Z(z){if(z.kind===H.Compare)return z;const A=z.checks.filter((B)=>!_(B));if(A.length===0)return z;if(A.length===1)return A[0];return{kind:z.kind,checks:A}}function _(z){if(z.kind!==H.Compare||z.op!==X.Neq)return!1;return $(z.left,z.right)}function $(z,A){switch(z.kind){case D.Value:return A.kind===D.Value;case D.Member:return A.kind===D.Member;case D.Call0:return A.kind===D.Call0;case D.Literal:return A.kind===D.Literal&&z.value===A.value;default:return z}}function Q(z,A,B){if(z.kind===H.Compare)return`${J(z.left,A,B)} ${z.op} ${J(z.right,A,B)}`;const F=z.kind===H.And?" && ":" || ";return`(${z.checks.map((I)=>Q(I,A,B)).join(F)})`}function J(z,A,B){switch(z.kind){case D.Value:return A;case D.Literal:return String(z.value);case D.Member:return B?.length??`${A}.length`;case D.Call0:return B?.time??`${A}.getTime()`;default:return z}}export{planValue,planLength,planTime,planLiteral,planCompare,planOr,makePlannedRule,makeRule,emitRulePlan};
@@ -0,0 +1,23 @@
1
+ import type { EmittableRule } from './interfaces';
2
+ declare function minLength(min: number): EmittableRule;
3
+ declare function maxLength(max: number): EmittableRule;
4
+ declare function length(minLen: number, maxLen: number): EmittableRule;
5
+ declare function contains(seed: string): EmittableRule;
6
+ declare function notContains(seed: string): EmittableRule;
7
+ declare function matches(pattern: string | RegExp, modifiers?: string): EmittableRule;
8
+ declare const isLowercase: import("./interfaces").InternalRule;
9
+ declare const isUppercase: import("./interfaces").InternalRule;
10
+ declare const isAscii: EmittableRule;
11
+ declare const isAlpha: EmittableRule;
12
+ declare const isAlphanumeric: EmittableRule;
13
+ declare const isHttpToken: EmittableRule;
14
+ declare const isOrigin: import("./interfaces").InternalRule;
15
+ declare const isCorsOrigin: import("./interfaces").InternalRule;
16
+ declare const isBooleanString: import("./interfaces").InternalRule;
17
+ interface IsNumberStringOptions {
18
+ noSymbols?: boolean;
19
+ }
20
+ declare function isNumberString(options?: IsNumberStringOptions): EmittableRule;
21
+ declare function isDecimal(): EmittableRule;
22
+ export { minLength, maxLength, length, contains, notContains, matches, isLowercase, isUppercase, isAscii, isAlpha, isAlphanumeric, isHttpToken, isOrigin, isCorsOrigin, isBooleanString, isNumberString, isDecimal, };
23
+ export type { IsNumberStringOptions };
@@ -0,0 +1 @@
1
+ import{CacheKey as f}from"../common/index.js";import{RequiredType as W,RuleOp as G}from"./enums.js";import{makePlannedRule as F,makeRule as X,planCompare as Y,planLength as B,planOr as P}from"./rule-plan.js";import{makeStringRule as $}from"./string-shared.js";function minLength(j){const z={cacheKey:f.Length,failure:Y(B(),G.Lt,j)};return F({name:"minLength",requiresType:W.String,constraints:{min:j},plan:z,validate:(J)=>typeof J==="string"&&J.length>=j})}function maxLength(j){const z={cacheKey:f.Length,failure:Y(B(),G.Gt,j)};return F({name:"maxLength",requiresType:W.String,constraints:{max:j},plan:z,validate:(J)=>typeof J==="string"&&J.length<=j})}function length(j,z){const J={cacheKey:f.Length,failure:P(Y(B(),G.Lt,j),Y(B(),G.Gt,z))};return F({name:"length",requiresType:W.String,constraints:{min:j,max:z},plan:J,validate:(Q)=>typeof Q==="string"&&Q.length>=j&&Q.length<=z})}function contains(j){return X({name:"contains",requiresType:W.String,constraints:{seed:j},validate:(z)=>typeof z==="string"&&z.includes(j),emit:(z,J)=>{const Q=J.addRef(j);return`if (!${z}.includes(refs[${Q}])) ${J.fail("contains")};`}})}function notContains(j){return X({name:"notContains",requiresType:W.String,constraints:{seed:j},validate:(z)=>typeof z==="string"&&!z.includes(j),emit:(z,J)=>{const Q=J.addRef(j);return`if (${z}.includes(refs[${Q}])) ${J.fail("notContains")};`}})}function matches(j,z){const J=j instanceof RegExp?j.source:j,Q=(j instanceof RegExp?j.flags:z??"").replace(/[gy]/g,""),Z=new RegExp(J,Q);return X({name:"matches",requiresType:W.String,constraints:{pattern:Z.source},validate:(w)=>typeof w==="string"&&Z.test(w),emit:(w,M)=>{return`if (!re[${M.addRegex(Z)}].test(${w})) ${M.fail("matches")};`}})}const isLowercase=X({name:"isLowercase",requiresType:W.String,constraints:{},validate:(j)=>typeof j==="string"&&j===j.toLowerCase(),emit:(j,z)=>`if (${j} !== ${j}.toLowerCase()) ${z.fail("isLowercase")};`});const isUppercase=X({name:"isUppercase",requiresType:W.String,constraints:{},validate:(j)=>typeof j==="string"&&j===j.toUpperCase(),emit:(j,z)=>`if (${j} !== ${j}.toUpperCase()) ${z.fail("isUppercase")};`});const D=new RegExp(`^[${String.fromCharCode(0)}-${String.fromCharCode(127)}]*$`);const isAscii=$("isAscii",(j)=>D.test(j),(j,z)=>{return`if (!re[${z.addRegex(D)}].test(${j})) ${z.fail("isAscii")};`});const H=/^[a-zA-Z]+$/;const isAlpha=$("isAlpha",(j)=>H.test(j),(j,z)=>{return`if (!re[${z.addRegex(H)}].test(${j})) ${z.fail("isAlpha")};`});const K=/^[a-zA-Z0-9]+$/;const isAlphanumeric=$("isAlphanumeric",(j)=>K.test(j),(j,z)=>{return`if (!re[${z.addRegex(K)}].test(${j})) ${z.fail("isAlphanumeric")};`});const V=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;const isHttpToken=$("isHttpToken",(j)=>V.test(j),(j,z)=>{return`if (!re[${z.addRegex(V)}].test(${j})) ${z.fail("isHttpToken")};`});const b=(j)=>{if(j==="null")return!0;try{return new URL(j).origin===j}catch{return!1}};const isOrigin=X({name:"isOrigin",requiresType:W.String,constraints:{format:"origin"},validate:(j)=>typeof j==="string"&&b(j),emit:(j,z)=>{return`if (!(refs[${z.addRef(b)}](${j}))) ${z.fail("isOrigin")};`}});const I=(j)=>j==="*"||b(j);const isCorsOrigin=X({name:"isCorsOrigin",requiresType:W.String,constraints:{format:"origin",allowWildcard:!0},validate:(j)=>typeof j==="string"&&I(j),emit:(j,z)=>{return`if (!(refs[${z.addRef(I)}](${j}))) ${z.fail("isCorsOrigin")};`}});const isBooleanString=X({name:"isBooleanString",requiresType:W.String,constraints:{},validate:(j)=>j==="true"||j==="false"||j==="1"||j==="0",emit:(j,z)=>`if (${j} !== 'true' && ${j} !== 'false' && ${j} !== '1' && ${j} !== '0') ${z.fail("isBooleanString")};`});const U=/^[0-9]+$/;const q=/^[+-]?(?:[0-9]*\.)?[0-9]+$/;function isNumberString(j){const z=j?.noSymbols??!1,J=z?U:q;return $("isNumberString",(Q)=>J.test(Q),(Q,Z)=>{return`if (!re[${Z.addRegex(J)}].test(${Q})) ${Z.fail("isNumberString")};`},W.String,{noSymbols:z})}function isDecimal(){const j=/^[-+]?(?:\d+(?:\.\d+)?|\.\d+)$/;return $("isDecimal",(z)=>j.test(z),(z,J)=>{return`if (!re[${J.addRegex(j)}].test(${z})) ${J.fail("isDecimal")};`})}export{minLength,maxLength,length,contains,notContains,matches,isLowercase,isUppercase,isAscii,isAlpha,isAlphanumeric,isHttpToken,isOrigin,isCorsOrigin,isBooleanString,isNumberString,isDecimal};
@@ -0,0 +1,5 @@
1
+ import type { EmittableRule } from './interfaces';
2
+ declare const isEthereumAddress: EmittableRule;
3
+ declare const isBtcAddress: EmittableRule;
4
+ declare function isHash(algorithm: string): EmittableRule;
5
+ export { isEthereumAddress, isBtcAddress, isHash };
@@ -0,0 +1 @@
1
+ import{BakerError as U}from"../common/index.js";import{HASH_REGEXES as V}from"./constants.js";import{RequiredType as W}from"./enums.js";import{makeRule as Y}from"./rule-plan.js";import{makeStringRule as Q}from"./string-shared.js";const J=/^0x[0-9a-fA-F]{40}$/;const isEthereumAddress=Q("isEthereumAddress",(b)=>J.test(b),(b,f)=>{return`if (!re[${f.addRegex(J)}].test(${b})) ${f.fail("isEthereumAddress")};`});const L=/^1[a-km-zA-HJ-NP-Z1-9]{25,34}$/;const M=/^3[a-km-zA-HJ-NP-Z1-9]{25,34}$/;const O=/^(?:(?:bc1|tb1)[a-z0-9]{6,87}|(?:BC1|TB1)[A-Z0-9]{6,87})$/;const isBtcAddress=Q("isBtcAddress",(b)=>L.test(b)||M.test(b)||O.test(b),(b,f)=>{const z=f.addRegex(L),F=f.addRegex(M),I=f.addRegex(O);return`if (!re[${z}].test(${b}) && !re[${F}].test(${b}) && !re[${I}].test(${b})) ${f.fail("isBtcAddress")};`});function isHash(b){const f=V[b];if(!f)throw new U(`Unsupported algorithm: "${b}" for isHash`);return Y({name:"isHash",requiresType:W.String,constraints:{algorithm:b},validate:(z)=>typeof z==="string"&&f.test(z),emit:(z,F)=>{return`if (!re[${F.addRegex(f)}].test(${z})) ${F.fail("isHash")};`}})}export{isEthereumAddress,isBtcAddress,isHash};
@@ -0,0 +1,3 @@
1
+ declare const isRFC3339: import("./interfaces").EmittableRule;
2
+ declare const isMilitaryTime: import("./interfaces").EmittableRule;
3
+ export { isRFC3339, isMilitaryTime };
@@ -0,0 +1 @@
1
+ import{makeStringRule as d}from"./string-shared.js";const e=/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/i;const isRFC3339=d("isRFC3339",(i)=>e.test(i),(i,t)=>{return`if (!re[${t.addRegex(e)}].test(${i})) ${t.fail("isRFC3339")};`});const s=/^([01]\d|2[0-3]):[0-5]\d$/;const isMilitaryTime=d("isMilitaryTime",(i)=>s.test(i),(i,t)=>{return`if (!re[${t.addRegex(s)}].test(${i})) ${t.fail("isMilitaryTime")};`});export{isRFC3339,isMilitaryTime};
@@ -0,0 +1,14 @@
1
+ import type { EmittableRule } from './interfaces';
2
+ declare const isHexadecimal: EmittableRule;
3
+ declare const isOctal: EmittableRule;
4
+ declare const isHexColor: EmittableRule;
5
+ declare function isRgbColor(includePercentValues?: boolean): EmittableRule;
6
+ declare const isHSL: EmittableRule;
7
+ declare function isBase32(): EmittableRule;
8
+ declare const isBase58: EmittableRule;
9
+ interface IsBase64Options {
10
+ urlSafe?: boolean;
11
+ }
12
+ declare function isBase64(options?: IsBase64Options): EmittableRule;
13
+ export { isHexadecimal, isOctal, isHexColor, isRgbColor, isHSL, isBase32, isBase58, isBase64 };
14
+ export type { IsBase64Options };
@@ -0,0 +1 @@
1
+ import{RequiredType as b}from"./enums.js";import{makeRule as V}from"./rule-plan.js";import{makeStringRule as D}from"./string-shared.js";const M=/^[0-9a-fA-F]+$/;const isHexadecimal=D("isHexadecimal",(w)=>M.test(w),(w,j)=>{return`if (!re[${j.addRegex(M)}].test(${w})) ${j.fail("isHexadecimal")};`});const Q=/^(0[oO])?[0-7]+$/;const isOctal=D("isOctal",(w)=>Q.test(w),(w,j)=>{return`if (!re[${j.addRegex(Q)}].test(${w})) ${j.fail("isOctal")};`});const W=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;const isHexColor=D("isHexColor",(w)=>W.test(w),(w,j)=>{return`if (!re[${j.addRegex(W)}].test(${w})) ${j.fail("isHexColor")};`});const I=/^rgb\(\s*(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\s*,\s*(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\s*,\s*(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\s*\)$/;const J=/^rgba\(\s*(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\s*,\s*(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\s*,\s*(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\s*,\s*(0|0?\.\d+|1(\.0+)?)\s*\)$/;const Y=/^rgb\(\s*(\d{1,2}|100)%\s*,\s*(\d{1,2}|100)%\s*,\s*(\d{1,2}|100)%\s*\)$/;const Z=/^rgba\(\s*(\d{1,2}|100)%\s*,\s*(\d{1,2}|100)%\s*,\s*(\d{1,2}|100)%\s*,\s*(0|0?\.\d+|1(?:\.0+)?)\s*\)$/;function isRgbColor(w=!1){return V({name:"isRgbColor",requiresType:b.String,constraints:{includePercentValues:w},validate:(j)=>{if(typeof j!=="string")return!1;if(w)return Y.test(j)||Z.test(j)||I.test(j)||J.test(j);return I.test(j)||J.test(j)},emit:(j,z)=>{if(w){const q=z.addRegex(Y),h=z.addRegex(Z),y=z.addRegex(I),X=z.addRegex(J);return`if (!re[${q}].test(${j}) && !re[${h}].test(${j}) && !re[${y}].test(${j}) && !re[${X}].test(${j})) ${z.fail("isRgbColor")};`}const F=z.addRegex(I),K=z.addRegex(J);return`if (!re[${F}].test(${j}) && !re[${K}].test(${j})) ${z.fail("isRgbColor")};`}})}const $=/^(?:hsl\(\s*(?:360|3[0-5]\d|[12]\d{2}|[1-9]\d|\d)\s*,\s*(?:100|[1-9]\d|\d)%\s*,\s*(?:100|[1-9]\d|\d)%\s*\)|hsla\(\s*(?:360|3[0-5]\d|[12]\d{2}|[1-9]\d|\d)\s*,\s*(?:100|[1-9]\d|\d)%\s*,\s*(?:100|[1-9]\d|\d)%\s*,\s*(?:0|0?\.\d+|1(?:\.0+)?)\s*\))$/;const isHSL=D("isHSL",(w)=>$.test(w),(w,j)=>{return`if (!re[${j.addRegex($)}].test(${w})) ${j.fail("isHSL")};`});const f=/^[A-Z2-7]+=*$/i;function isBase32(){return D("isBase32",(w)=>w.length%8===0&&f.test(w),(w,j)=>{const z=j.addRegex(f);return`if (${w}.length % 8 !== 0 || !re[${z}].test(${w})) ${j.fail("isBase32")};`})}const U=/^[1-9A-HJ-NP-Za-km-z]+$/;const isBase58=D("isBase58",(w)=>U.test(w),(w,j)=>{return`if (!re[${j.addRegex(U)}].test(${w})) ${j.fail("isBase58")};`});const T=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/;const k=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}(?:==)?|[A-Za-z0-9_-]{3}=?|[A-Za-z0-9_-]{4})$/;function isBase64(w){const j=w?.urlSafe?k:T;return D("isBase64",(z)=>j.test(z),(z,F)=>{return`if (!re[${F.addRegex(j)}].test(${z})) ${F.fail("isBase64")};`},b.String,w?.urlSafe!==void 0?{urlSafe:w.urlSafe}:{})}export{isHexadecimal,isOctal,isHexColor,isRgbColor,isHSL,isBase32,isBase58,isBase64};
@@ -0,0 +1,18 @@
1
+ import type { EmittableRule } from './interfaces';
2
+ declare function isISBN(version?: 10 | 13): EmittableRule;
3
+ declare const isISIN: EmittableRule;
4
+ interface IsISSNOptions {
5
+ requireHyphen?: boolean;
6
+ }
7
+ declare function isISSN(options?: IsISSNOptions): EmittableRule;
8
+ declare const isEAN: EmittableRule;
9
+ declare const isBIC: EmittableRule;
10
+ declare function isCurrency(): EmittableRule;
11
+ declare const isCreditCard: import("./interfaces").InternalRule;
12
+ interface IsIBANOptions {
13
+ allowSpaces?: boolean;
14
+ }
15
+ declare function isIBAN(options?: IsIBANOptions): EmittableRule;
16
+ declare const isISO4217CurrencyCode: EmittableRule;
17
+ export { isISBN, isISIN, isISSN, isEAN, isBIC, isCreditCard, isIBAN, isCurrency, isISO4217CurrencyCode };
18
+ export type { IsISSNOptions, IsIBANOptions };
@@ -0,0 +1,10 @@
1
+ import{IBAN_COUNTRY_LENGTH as L,ISO4217_CODES as F}from"./constants.js";import{RequiredType as Z}from"./enums.js";import{makeRule as $}from"./rule-plan.js";import{makeStringRule as X}from"./string-shared.js";function w(z){const j=z.replace(/[-\s]/g,"");if(!/^\d{9}[\dX]$/.test(j))return!1;let K=0;for(let J=0;J<9;J++)K+=(10-J)*(j.charCodeAt(J)-48);const M=j[9]==="X"?10:j.charCodeAt(9)-48;K+=M;return K%11===0}function D(z){const j=z.replace(/[-\s]/g,"");if(!/^\d{13}$/.test(j))return!1;let K=0;for(let J=0;J<12;J++)K+=(j.charCodeAt(J)-48)*(J%2===0?1:3);return(10-K%10)%10===j.charCodeAt(12)-48}function isISBN(z){const j=(J)=>{if(typeof J!=="string")return!1;if(z===10)return w(J);if(z===13)return D(J);return w(J)||D(J)},K=(J)=>`{var s=${J}.replace(/[-\\s]/g,'');if(!/^\\d{9}[\\dX]$/.test(s)){%%FAIL%%}else{var sm=0;for(var i=0;i<9;i++)sm+=(10-i)*(s.charCodeAt(i)-48);var l=s[9]==='X'?10:(s.charCodeAt(9)-48);sm+=l;if(sm%11!==0){%%FAIL%%}}}`,M=(J)=>`{var s=${J}.replace(/[-\\s]/g,'');if(!/^\\d{13}$/.test(s)){%%FAIL%%}else{var sm=0;for(var i=0;i<12;i++)sm+=(s.charCodeAt(i)-48)*(i%2===0?1:3);var ck=(10-(sm%10))%10;if(ck!==(s.charCodeAt(12)-48)){%%FAIL%%}}}`;return $({name:"isISBN",requiresType:Z.String,constraints:{version:z},validate:j,emit:(J,P)=>{const V=P.fail("isISBN");if(z===10)return K(J).replace(/%%FAIL%%/g,V);if(z===13)return M(J).replace(/%%FAIL%%/g,V);const Q=K(J).replace(/%%FAIL%%/g,"__isbn_ok=false"),W=M(J).replace(/%%FAIL%%/g,"__isbn_ok=false");return`{var __isbn_ok=true;${Q} if(!__isbn_ok){__isbn_ok=true;${W}} if(!__isbn_ok)${V};}`}})}const U=/^[A-Z]{2}[A-Z0-9]{9}[0-9]$/;function f(z){if(!U.test(z))return!1;let j=0,K=!1;for(let M=z.length-1;M>=0;M--){const J=z.charCodeAt(M);if(J<=57){let P=J-48;if(K){P*=2;if(P>9)P-=9}j+=P;K=!K}else{const P=J-55,V=P%10;let Q=V;if(K){Q*=2;if(Q>9)Q-=9}j+=Q;K=!K;Q=(P-V)/10;if(K){Q*=2;if(Q>9)Q-=9}j+=Q;K=!K}}return j%10===0}const isISIN=X("isISIN",f,(z,j)=>{return`if (!re[${j.addRegex(U)}].test(${z})) ${j.fail("isISIN")};
2
+ else { var isSum=0,isAlt=false;
3
+ for(var isI=${z}.length-1;isI>=0;isI--){var isCd=${z}.charCodeAt(isI),isN;if(isCd<=57){isN=isCd-48;if(isAlt){isN*=2;if(isN>9)isN-=9;}isSum+=isN;isAlt=!isAlt;}else{var isVal=isCd-55;var isO=isVal%10;isN=isO;if(isAlt){isN*=2;if(isN>9)isN-=9;}isSum+=isN;isAlt=!isAlt;isN=(isVal-isO)/10;if(isAlt){isN*=2;if(isN>9)isN-=9;}isSum+=isN;isAlt=!isAlt;}}
4
+ if(isSum%10!==0)${j.fail("isISIN")}; }`});function A(z,j){const K=j?.requireHyphen!==!1,M=K?z:z.replace(/-/g,"");if(!(K?/^\d{4}-\d{3}[\dX]$/:/^\d{7}[\dX]$/).test(M))return!1;const P=K?M.replace(/-/g,""):M;let V=0;for(let W=0;W<7;W++)V+=(8-W)*(P.charCodeAt(W)-48);const Q=P[7]==="X"?10:P.charCodeAt(7)-48;V+=Q;return V%11===0}function isISSN(z){const j=z?.requireHyphen!==!1,K=(J)=>typeof J==="string"&&A(J,z),M=j?/^\d{4}-\d{3}[\dX]$/:/^\d{7}[\dX]$/;return $({name:"isISSN",requiresType:Z.String,constraints:{requireHyphen:j},validate:K,emit:(J,P)=>{const V=P.addRegex(M),Q=j?J:`${J}.replace(/-/g,'')`,W=j?"issn.replace(/-/g,'')":"issn";return`{var issn=${Q};if(!re[${V}].test(issn)){${P.fail("isISSN")}}else{var id=${W},iss=0;for(var ii=0;ii<7;ii++)iss+=(8-ii)*(id.charCodeAt(ii)-48);var il=id[7]==='X'?10:(id.charCodeAt(7)-48);iss+=il;if(iss%11!==0)${P.fail("isISSN")};}}`}})}function T(z){if(!/^\d{8}$/.test(z)&&!/^\d{13}$/.test(z))return!1;const j=z.length;let K=0;for(let J=0;J<j-1;J++){const P=z.charCodeAt(J)-48;K+=P*(j===8?J%2===0?3:1:J%2===0?1:3)}return(10-K%10)%10===z.charCodeAt(j-1)-48}const isEAN=X("isEAN",T,(z,j)=>{const K=j.addRegex(/^\d{8}$/),M=j.addRegex(/^\d{13}$/);return`{var ev=${z};if(!re[${K}].test(ev)&&!re[${M}].test(ev)){${j.fail("isEAN")}}else{var el=ev.length,es=0;for(var ei=0;ei<el-1;ei++){var ed=ev.charCodeAt(ei)-48;es+=ed*(el===8?(ei%2===0?3:1):(ei%2===0?1:3));}var ec=(10-(es%10))%10;if(ec!==(ev.charCodeAt(el-1)-48))${j.fail("isEAN")};}}`});const G=/^[A-Z]{6}[A-Z0-9]{2}(?:[A-Z0-9]{3})?$/i;const isBIC=X("isBIC",(z)=>G.test(z),(z,j)=>{return`if (!re[${j.addRegex(G)}].test(${z})) ${j.fail("isBIC")};`});const b=/^(?:[-+]?\$?|\$[-+]?)(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d{1,2})?$/;function isCurrency(){return X("isCurrency",(z)=>b.test(z),(z,j)=>{return`if (!re[${j.addRegex(b)}].test(${z})) ${j.fail("isCurrency")};`})}function k(z){const j=z.replace(/[\s-]/g,"");if(j.length===0||!/^\d+$/.test(j))return!1;let K=0,M=!1;for(let J=j.length-1;J>=0;J--){let P=j.charCodeAt(J)-48;if(M){P*=2;if(P>9)P-=9}K+=P;M=!M}return K%10===0}const isCreditCard=$({name:"isCreditCard",requiresType:Z.String,constraints:{},validate:(z)=>typeof z==="string"&&k(z),emit:(z,j)=>`{
5
+ var cs=${z}.replace(/[\\s-]/g,'');
6
+ if(cs.length===0||!/^\\d+$/.test(cs)){${j.fail("isCreditCard")}}
7
+ else{var sum=0,alt=false;
8
+ for(var ci=cs.length-1;ci>=0;ci--){var cn=cs.charCodeAt(ci)-48;if(alt){cn*=2;if(cn>9)cn-=9;}sum+=cn;alt=!alt;}
9
+ if(sum%10!==0)${j.fail("isCreditCard")};}
10
+ }`});function H(z,j){let K=j?.allowSpaces?z.replace(/\s/g,""):z;K=K.toUpperCase();if(!/^[A-Z]{2}\d{2}[A-Z0-9]+$/.test(K))return!1;const M=K.slice(0,2),J=L[M];if(J!==void 0&&K.length!==J)return!1;const P=K.slice(4)+K.slice(0,4);let V=0;for(let Q=0;Q<P.length;Q++){const W=P.charCodeAt(Q);if(W<=57)V=(V*10+(W-48))%97;else{const Y=W-55;V=(V*100+Y)%97}}return V===1}function isIBAN(z){const j=z?.allowSpaces??!1,K=(M)=>typeof M==="string"&&H(M,z);return $({name:"isIBAN",requiresType:Z.String,constraints:{allowSpaces:j},validate:K,emit:(M,J)=>{const P=J.addRegex(/^[A-Z]{2}\d{2}[A-Z0-9]+$/),V=J.addRef(L);let Q="{";Q+=`var ib=${j?`${M}.replace(/\\s/g,'')`:M}.toUpperCase();`;Q+=`if(!re[${P}].test(ib)){${J.fail("isIBAN")}}`;Q+=`else{var ic=ib.slice(0,2),il=refs[${V}][ic];`;Q+=`if(il!==undefined&&ib.length!==il){${J.fail("isIBAN")}}`;Q+="else{var ir=ib.slice(4)+ib.slice(0,4);";Q+="var im=0;for(var ii=0;ii<ir.length;ii++){var cc=ir.charCodeAt(ii);";Q+="if(cc<=57){im=(im*10+(cc-48))%97;}else{im=(im*100+(cc-55))%97;}}";Q+=`if(im!==1)${J.fail("isIBAN")};}}}`;return Q}})}const isISO4217CurrencyCode=X("isISO4217CurrencyCode",(z)=>F.has(z),(z,j)=>{return`if (!refs[${j.addRef(F)}].has(${z})) ${j.fail("isISO4217CurrencyCode")};`});export{isISBN,isISIN,isISSN,isEAN,isBIC,isCreditCard,isIBAN,isCurrency,isISO4217CurrencyCode};