react-input-mask-format 2.0.0 → 2.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.
@@ -0,0 +1,55 @@
1
+ // src/presets/index.ts
2
+ var card = {
3
+ mask: "9999 9999 9999 9999",
4
+ maskPlaceholder: "_"
5
+ };
6
+ var kzPhone = {
7
+ mask: "+7 (799) 999-99-99",
8
+ maskPlaceholder: "_"
9
+ };
10
+ var kzIin = {
11
+ mask: "999999999999",
12
+ maskPlaceholder: "_"
13
+ };
14
+ var kzBin = {
15
+ mask: "999999999999",
16
+ maskPlaceholder: "_"
17
+ };
18
+ var kzIban = {
19
+ // KZ + 2 check + 3 bank digits + 13 alnum account, grouped by 4
20
+ mask: "KZ99 999* **** **** ****",
21
+ maskPlaceholder: "_",
22
+ transform: "uppercase"
23
+ };
24
+ var KZ_PLATE_LETTER = /[ABCEHKMNOPTXY]/i;
25
+ var kzPlate = {
26
+ // 3 digits · 3 letters (Latin look-alikes of Cyrillic) · 2-digit region
27
+ mask: [
28
+ /[0-9]/,
29
+ /[0-9]/,
30
+ /[0-9]/,
31
+ " ",
32
+ KZ_PLATE_LETTER,
33
+ KZ_PLATE_LETTER,
34
+ KZ_PLATE_LETTER,
35
+ " ",
36
+ /[0-9]/,
37
+ /[0-9]/
38
+ ],
39
+ maskPlaceholder: "_",
40
+ transform: "uppercase"
41
+ };
42
+ var kzPostal = {
43
+ mask: "999999",
44
+ maskPlaceholder: "_"
45
+ };
46
+ export {
47
+ card,
48
+ kzBin,
49
+ kzIban,
50
+ kzIin,
51
+ kzPhone,
52
+ kzPlate,
53
+ kzPostal
54
+ };
55
+ //# sourceMappingURL=presets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/presets/index.ts"],"sourcesContent":["import type { Mask, Transform, FormatChars } from \"../types\";\n\nexport interface MaskPreset {\n mask: Mask;\n maskPlaceholder?: string | null;\n transform?: Transform;\n formatChars?: FormatChars;\n}\n\n// ── Generic (country-agnostic) ───────────────────────────────\nexport const card: MaskPreset = {\n mask: \"9999 9999 9999 9999\",\n maskPlaceholder: \"_\"\n};\n\n// ── Kazakhstan ───────────────────────────────────────────────\nexport const kzPhone: MaskPreset = {\n mask: \"+7 (799) 999-99-99\",\n maskPlaceholder: \"_\"\n};\n\nexport const kzIin: MaskPreset = {\n mask: \"999999999999\",\n maskPlaceholder: \"_\"\n};\n\nexport const kzBin: MaskPreset = {\n mask: \"999999999999\",\n maskPlaceholder: \"_\"\n};\n\nexport const kzIban: MaskPreset = {\n // KZ + 2 check + 3 bank digits + 13 alnum account, grouped by 4\n mask: \"KZ99 999* **** **** ****\",\n maskPlaceholder: \"_\",\n transform: \"uppercase\"\n};\n\nconst KZ_PLATE_LETTER = /[ABCEHKMNOPTXY]/i;\nexport const kzPlate: MaskPreset = {\n // 3 digits · 3 letters (Latin look-alikes of Cyrillic) · 2-digit region\n mask: [\n /[0-9]/, /[0-9]/, /[0-9]/, \" \",\n KZ_PLATE_LETTER, KZ_PLATE_LETTER, KZ_PLATE_LETTER, \" \",\n /[0-9]/, /[0-9]/\n ],\n maskPlaceholder: \"_\",\n transform: \"uppercase\"\n};\n\nexport const kzPostal: MaskPreset = {\n mask: \"999999\",\n maskPlaceholder: \"_\"\n};\n"],"mappings":";AAUO,IAAM,OAAmB;AAAA,EAC9B,MAAM;AAAA,EACN,iBAAiB;AACnB;AAGO,IAAM,UAAsB;AAAA,EACjC,MAAM;AAAA,EACN,iBAAiB;AACnB;AAEO,IAAM,QAAoB;AAAA,EAC/B,MAAM;AAAA,EACN,iBAAiB;AACnB;AAEO,IAAM,QAAoB;AAAA,EAC/B,MAAM;AAAA,EACN,iBAAiB;AACnB;AAEO,IAAM,SAAqB;AAAA;AAAA,EAEhC,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,WAAW;AACb;AAEA,IAAM,kBAAkB;AACjB,IAAM,UAAsB;AAAA;AAAA,EAEjC,MAAM;AAAA,IACJ;AAAA,IAAS;AAAA,IAAS;AAAA,IAAS;AAAA,IAC3B;AAAA,IAAiB;AAAA,IAAiB;AAAA,IAAiB;AAAA,IACnD;AAAA,IAAS;AAAA,EACX;AAAA,EACA,iBAAiB;AAAA,EACjB,WAAW;AACb;AAEO,IAAM,WAAuB;AAAA,EAClC,MAAM;AAAA,EACN,iBAAiB;AACnB;","names":[]}
@@ -0,0 +1,77 @@
1
+ import * as React from 'react';
2
+
3
+ type Mask = string | Array<string | RegExp>;
4
+ type Transform = "uppercase" | "lowercase" | ((char: string, position: number) => string);
5
+ type FormatChars = Record<string, RegExp>;
6
+ interface Selection {
7
+ start: number | null;
8
+ end: number | null;
9
+ length?: number;
10
+ }
11
+ interface InputState {
12
+ value: string;
13
+ selection: Selection;
14
+ }
15
+ type BeforeMaskedStateChangeFn = (states: {
16
+ previousState?: InputState;
17
+ currentState?: InputState;
18
+ nextState: InputState;
19
+ }) => InputState;
20
+ /**
21
+ * Legacy (react-input-mask v2) signature for the before-change hook.
22
+ * @deprecated Use BeforeMaskedStateChangeFn with beforeMaskedStateChange.
23
+ */
24
+ type BeforeMaskedValueChangeFn = (newState: InputState, oldState: InputState | null, userInput: string | null, maskOptions: V2MaskOptions) => InputState;
25
+ /** Mask options shape passed to the legacy beforeMaskedValueChange callback. */
26
+ interface V2MaskOptions {
27
+ mask?: Mask;
28
+ maskChar: string | null;
29
+ alwaysShowMask: boolean;
30
+ formatChars: Record<string, RegExp | string>;
31
+ permanents: number[];
32
+ }
33
+ interface InputMaskProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "children"> {
34
+ /**
35
+ * Mask format. Either a string (9 = 0-9, a = A-Za-z, * = A-Za-z0-9,
36
+ * backslash escapes) or an array of constant characters and RegExps.
37
+ */
38
+ mask?: Mask;
39
+ /** Character(s) to cover unfilled parts. Default "_", null — empty. */
40
+ maskPlaceholder?: string | null;
41
+ /** Show mask even when input is empty and unfocused. */
42
+ alwaysShowMask?: boolean;
43
+ /** Modify masked value and cursor position before they are applied. */
44
+ beforeMaskedStateChange?: BeforeMaskedStateChangeFn;
45
+ /** Normalize each entered character. "uppercase" | "lowercase" | (char, position) => char. Must be pure. */
46
+ transform?: Transform;
47
+ /** Custom input component. */
48
+ children?: React.ReactElement;
49
+ /** @deprecated Use maskPlaceholder. */
50
+ maskChar?: string | null;
51
+ /**
52
+ * Map of custom mask tokens to character classes. Prefer RegExp values
53
+ * (e.g. `{ "#": /[0-9]/ }`); a ready-made `extendedFormatChars` is exported.
54
+ * String values are a deprecated legacy form and emit a one-time warning.
55
+ */
56
+ formatChars?: Record<string, RegExp | string>;
57
+ /** @deprecated Use beforeMaskedStateChange. */
58
+ beforeMaskedValueChange?: BeforeMaskedValueChangeFn;
59
+ }
60
+ interface UseMaskOptions {
61
+ /** Mask format — same grammar as InputMask's `mask`. */
62
+ mask?: Mask | null;
63
+ /** Character(s) to cover unfilled parts. Default "_", null — empty. */
64
+ maskPlaceholder?: string | null;
65
+ /** Show mask even when input is empty and unfocused. */
66
+ alwaysShowMask?: boolean;
67
+ /** Map of custom mask tokens to character classes. Prefer RegExp values. */
68
+ formatChars?: Record<string, RegExp | string>;
69
+ /** Normalize each entered character. Must be pure. */
70
+ transform?: Transform;
71
+ /** Modify masked value and cursor position before they are applied. */
72
+ beforeMaskedStateChange?: BeforeMaskedStateChangeFn;
73
+ /** @deprecated Use beforeMaskedStateChange. */
74
+ beforeMaskedValueChange?: BeforeMaskedValueChangeFn;
75
+ }
76
+
77
+ export type { BeforeMaskedStateChangeFn as B, FormatChars as F, InputMaskProps as I, Mask as M, Selection as S, Transform as T, UseMaskOptions as U, BeforeMaskedValueChangeFn as a, InputState as b };
@@ -0,0 +1,77 @@
1
+ import * as React from 'react';
2
+
3
+ type Mask = string | Array<string | RegExp>;
4
+ type Transform = "uppercase" | "lowercase" | ((char: string, position: number) => string);
5
+ type FormatChars = Record<string, RegExp>;
6
+ interface Selection {
7
+ start: number | null;
8
+ end: number | null;
9
+ length?: number;
10
+ }
11
+ interface InputState {
12
+ value: string;
13
+ selection: Selection;
14
+ }
15
+ type BeforeMaskedStateChangeFn = (states: {
16
+ previousState?: InputState;
17
+ currentState?: InputState;
18
+ nextState: InputState;
19
+ }) => InputState;
20
+ /**
21
+ * Legacy (react-input-mask v2) signature for the before-change hook.
22
+ * @deprecated Use BeforeMaskedStateChangeFn with beforeMaskedStateChange.
23
+ */
24
+ type BeforeMaskedValueChangeFn = (newState: InputState, oldState: InputState | null, userInput: string | null, maskOptions: V2MaskOptions) => InputState;
25
+ /** Mask options shape passed to the legacy beforeMaskedValueChange callback. */
26
+ interface V2MaskOptions {
27
+ mask?: Mask;
28
+ maskChar: string | null;
29
+ alwaysShowMask: boolean;
30
+ formatChars: Record<string, RegExp | string>;
31
+ permanents: number[];
32
+ }
33
+ interface InputMaskProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "children"> {
34
+ /**
35
+ * Mask format. Either a string (9 = 0-9, a = A-Za-z, * = A-Za-z0-9,
36
+ * backslash escapes) or an array of constant characters and RegExps.
37
+ */
38
+ mask?: Mask;
39
+ /** Character(s) to cover unfilled parts. Default "_", null — empty. */
40
+ maskPlaceholder?: string | null;
41
+ /** Show mask even when input is empty and unfocused. */
42
+ alwaysShowMask?: boolean;
43
+ /** Modify masked value and cursor position before they are applied. */
44
+ beforeMaskedStateChange?: BeforeMaskedStateChangeFn;
45
+ /** Normalize each entered character. "uppercase" | "lowercase" | (char, position) => char. Must be pure. */
46
+ transform?: Transform;
47
+ /** Custom input component. */
48
+ children?: React.ReactElement;
49
+ /** @deprecated Use maskPlaceholder. */
50
+ maskChar?: string | null;
51
+ /**
52
+ * Map of custom mask tokens to character classes. Prefer RegExp values
53
+ * (e.g. `{ "#": /[0-9]/ }`); a ready-made `extendedFormatChars` is exported.
54
+ * String values are a deprecated legacy form and emit a one-time warning.
55
+ */
56
+ formatChars?: Record<string, RegExp | string>;
57
+ /** @deprecated Use beforeMaskedStateChange. */
58
+ beforeMaskedValueChange?: BeforeMaskedValueChangeFn;
59
+ }
60
+ interface UseMaskOptions {
61
+ /** Mask format — same grammar as InputMask's `mask`. */
62
+ mask?: Mask | null;
63
+ /** Character(s) to cover unfilled parts. Default "_", null — empty. */
64
+ maskPlaceholder?: string | null;
65
+ /** Show mask even when input is empty and unfocused. */
66
+ alwaysShowMask?: boolean;
67
+ /** Map of custom mask tokens to character classes. Prefer RegExp values. */
68
+ formatChars?: Record<string, RegExp | string>;
69
+ /** Normalize each entered character. Must be pure. */
70
+ transform?: Transform;
71
+ /** Modify masked value and cursor position before they are applied. */
72
+ beforeMaskedStateChange?: BeforeMaskedStateChangeFn;
73
+ /** @deprecated Use beforeMaskedStateChange. */
74
+ beforeMaskedValueChange?: BeforeMaskedValueChangeFn;
75
+ }
76
+
77
+ export type { BeforeMaskedStateChangeFn as B, FormatChars as F, InputMaskProps as I, Mask as M, Selection as S, Transform as T, UseMaskOptions as U, BeforeMaskedValueChangeFn as a, InputState as b };
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/validators/index.ts
21
+ var validators_exports = {};
22
+ __export(validators_exports, {
23
+ isValidBin: () => isValidBin,
24
+ isValidIin: () => isValidIin,
25
+ isValidKzIban: () => isValidKzIban,
26
+ luhn: () => luhn
27
+ });
28
+ module.exports = __toCommonJS(validators_exports);
29
+ function digitsOnly(value) {
30
+ return (value != null ? value : "").replace(/\D/g, "");
31
+ }
32
+ function luhn(value) {
33
+ const digits = digitsOnly(value);
34
+ if (digits.length === 0) {
35
+ return false;
36
+ }
37
+ let sum = 0;
38
+ let double = false;
39
+ for (let i = digits.length - 1; i >= 0; i--) {
40
+ let d = digits.charCodeAt(i) - 48;
41
+ if (double) {
42
+ d *= 2;
43
+ if (d > 9) {
44
+ d -= 9;
45
+ }
46
+ }
47
+ sum += d;
48
+ double = !double;
49
+ }
50
+ return sum % 10 === 0;
51
+ }
52
+ var IIN_W1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
53
+ var IIN_W2 = [3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 2];
54
+ function iinBinChecksum(value) {
55
+ const digits = digitsOnly(value);
56
+ if (digits.length !== 12) {
57
+ return false;
58
+ }
59
+ const d = digits.split("").map((c) => c.charCodeAt(0) - 48);
60
+ const weighted = (w) => w.reduce((sum, wi, i) => sum + wi * d[i], 0) % 11;
61
+ let control = weighted(IIN_W1);
62
+ if (control === 10) {
63
+ control = weighted(IIN_W2);
64
+ if (control === 10) {
65
+ return false;
66
+ }
67
+ }
68
+ return control === d[11];
69
+ }
70
+ function isValidIin(value) {
71
+ return iinBinChecksum(value);
72
+ }
73
+ function isValidBin(value) {
74
+ return iinBinChecksum(value);
75
+ }
76
+ function isValidKzIban(value) {
77
+ const s = (value != null ? value : "").replace(/\s+/g, "").toUpperCase();
78
+ if (s.length !== 20 || !s.startsWith("KZ") || !/^[0-9A-Z]+$/.test(s)) {
79
+ return false;
80
+ }
81
+ const rearranged = s.slice(4) + s.slice(0, 4);
82
+ let remainder = 0;
83
+ for (let i = 0; i < rearranged.length; i++) {
84
+ const ch = rearranged[i];
85
+ const chunk = ch >= "A" && ch <= "Z" ? String(ch.charCodeAt(0) - 55) : ch;
86
+ for (let j = 0; j < chunk.length; j++) {
87
+ remainder = (remainder * 10 + (chunk.charCodeAt(j) - 48)) % 97;
88
+ }
89
+ }
90
+ return remainder === 1;
91
+ }
92
+ // Annotate the CommonJS export names for ESM import in node:
93
+ 0 && (module.exports = {
94
+ isValidBin,
95
+ isValidIin,
96
+ isValidKzIban,
97
+ luhn
98
+ });
99
+ //# sourceMappingURL=validators.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/validators/index.ts"],"sourcesContent":["function digitsOnly(value: string): string {\n return (value ?? \"\").replace(/\\D/g, \"\");\n}\n\nexport function luhn(value: string): boolean {\n const digits = digitsOnly(value);\n if (digits.length === 0) {\n return false;\n }\n let sum = 0;\n let double = false;\n for (let i = digits.length - 1; i >= 0; i--) {\n let d = digits.charCodeAt(i) - 48;\n if (double) {\n d *= 2;\n if (d > 9) {\n d -= 9;\n }\n }\n sum += d;\n double = !double;\n }\n return sum % 10 === 0;\n}\n\nconst IIN_W1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];\nconst IIN_W2 = [3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 2];\n\nfunction iinBinChecksum(value: string): boolean {\n const digits = digitsOnly(value);\n if (digits.length !== 12) {\n return false;\n }\n const d = digits.split(\"\").map(c => c.charCodeAt(0) - 48);\n const weighted = (w: number[]): number =>\n w.reduce((sum, wi, i) => sum + wi * d[i], 0) % 11;\n let control = weighted(IIN_W1);\n if (control === 10) {\n control = weighted(IIN_W2);\n if (control === 10) {\n return false;\n }\n }\n return control === d[11];\n}\n\nexport function isValidIin(value: string): boolean {\n return iinBinChecksum(value);\n}\n\nexport function isValidBin(value: string): boolean {\n return iinBinChecksum(value);\n}\n\nexport function isValidKzIban(value: string): boolean {\n const s = (value ?? \"\").replace(/\\s+/g, \"\").toUpperCase();\n if (s.length !== 20 || !s.startsWith(\"KZ\") || !/^[0-9A-Z]+$/.test(s)) {\n return false;\n }\n const rearranged = s.slice(4) + s.slice(0, 4);\n let remainder = 0;\n for (let i = 0; i < rearranged.length; i++) {\n const ch = rearranged[i];\n // A→10 … Z→35, digits stay as-is\n const chunk = ch >= \"A\" && ch <= \"Z\" ? String(ch.charCodeAt(0) - 55) : ch;\n for (let j = 0; j < chunk.length; j++) {\n remainder = (remainder * 10 + (chunk.charCodeAt(j) - 48)) % 97;\n }\n }\n return remainder === 1;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAS,WAAW,OAAuB;AACzC,UAAQ,wBAAS,IAAI,QAAQ,OAAO,EAAE;AACxC;AAEO,SAAS,KAAK,OAAwB;AAC3C,QAAM,SAAS,WAAW,KAAK;AAC/B,MAAI,OAAO,WAAW,GAAG;AACvB,WAAO;AAAA,EACT;AACA,MAAI,MAAM;AACV,MAAI,SAAS;AACb,WAAS,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,KAAK;AAC3C,QAAI,IAAI,OAAO,WAAW,CAAC,IAAI;AAC/B,QAAI,QAAQ;AACV,WAAK;AACL,UAAI,IAAI,GAAG;AACT,aAAK;AAAA,MACP;AAAA,IACF;AACA,WAAO;AACP,aAAS,CAAC;AAAA,EACZ;AACA,SAAO,MAAM,OAAO;AACtB;AAEA,IAAM,SAAS,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,EAAE;AACjD,IAAM,SAAS,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,CAAC;AAEjD,SAAS,eAAe,OAAwB;AAC9C,QAAM,SAAS,WAAW,KAAK;AAC/B,MAAI,OAAO,WAAW,IAAI;AACxB,WAAO;AAAA,EACT;AACA,QAAM,IAAI,OAAO,MAAM,EAAE,EAAE,IAAI,OAAK,EAAE,WAAW,CAAC,IAAI,EAAE;AACxD,QAAM,WAAW,CAAC,MAChB,EAAE,OAAO,CAAC,KAAK,IAAI,MAAM,MAAM,KAAK,EAAE,CAAC,GAAG,CAAC,IAAI;AACjD,MAAI,UAAU,SAAS,MAAM;AAC7B,MAAI,YAAY,IAAI;AAClB,cAAU,SAAS,MAAM;AACzB,QAAI,YAAY,IAAI;AAClB,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO,YAAY,EAAE,EAAE;AACzB;AAEO,SAAS,WAAW,OAAwB;AACjD,SAAO,eAAe,KAAK;AAC7B;AAEO,SAAS,WAAW,OAAwB;AACjD,SAAO,eAAe,KAAK;AAC7B;AAEO,SAAS,cAAc,OAAwB;AACpD,QAAM,KAAK,wBAAS,IAAI,QAAQ,QAAQ,EAAE,EAAE,YAAY;AACxD,MAAI,EAAE,WAAW,MAAM,CAAC,EAAE,WAAW,IAAI,KAAK,CAAC,cAAc,KAAK,CAAC,GAAG;AACpE,WAAO;AAAA,EACT;AACA,QAAM,aAAa,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC;AAC5C,MAAI,YAAY;AAChB,WAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;AAC1C,UAAM,KAAK,WAAW,CAAC;AAEvB,UAAM,QAAQ,MAAM,OAAO,MAAM,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,EAAE,IAAI;AACvE,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,mBAAa,YAAY,MAAM,MAAM,WAAW,CAAC,IAAI,OAAO;AAAA,IAC9D;AAAA,EACF;AACA,SAAO,cAAc;AACvB;","names":[]}
@@ -0,0 +1,6 @@
1
+ declare function luhn(value: string): boolean;
2
+ declare function isValidIin(value: string): boolean;
3
+ declare function isValidBin(value: string): boolean;
4
+ declare function isValidKzIban(value: string): boolean;
5
+
6
+ export { isValidBin, isValidIin, isValidKzIban, luhn };
@@ -0,0 +1,6 @@
1
+ declare function luhn(value: string): boolean;
2
+ declare function isValidIin(value: string): boolean;
3
+ declare function isValidBin(value: string): boolean;
4
+ declare function isValidKzIban(value: string): boolean;
5
+
6
+ export { isValidBin, isValidIin, isValidKzIban, luhn };
@@ -0,0 +1,71 @@
1
+ // src/validators/index.ts
2
+ function digitsOnly(value) {
3
+ return (value != null ? value : "").replace(/\D/g, "");
4
+ }
5
+ function luhn(value) {
6
+ const digits = digitsOnly(value);
7
+ if (digits.length === 0) {
8
+ return false;
9
+ }
10
+ let sum = 0;
11
+ let double = false;
12
+ for (let i = digits.length - 1; i >= 0; i--) {
13
+ let d = digits.charCodeAt(i) - 48;
14
+ if (double) {
15
+ d *= 2;
16
+ if (d > 9) {
17
+ d -= 9;
18
+ }
19
+ }
20
+ sum += d;
21
+ double = !double;
22
+ }
23
+ return sum % 10 === 0;
24
+ }
25
+ var IIN_W1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
26
+ var IIN_W2 = [3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 2];
27
+ function iinBinChecksum(value) {
28
+ const digits = digitsOnly(value);
29
+ if (digits.length !== 12) {
30
+ return false;
31
+ }
32
+ const d = digits.split("").map((c) => c.charCodeAt(0) - 48);
33
+ const weighted = (w) => w.reduce((sum, wi, i) => sum + wi * d[i], 0) % 11;
34
+ let control = weighted(IIN_W1);
35
+ if (control === 10) {
36
+ control = weighted(IIN_W2);
37
+ if (control === 10) {
38
+ return false;
39
+ }
40
+ }
41
+ return control === d[11];
42
+ }
43
+ function isValidIin(value) {
44
+ return iinBinChecksum(value);
45
+ }
46
+ function isValidBin(value) {
47
+ return iinBinChecksum(value);
48
+ }
49
+ function isValidKzIban(value) {
50
+ const s = (value != null ? value : "").replace(/\s+/g, "").toUpperCase();
51
+ if (s.length !== 20 || !s.startsWith("KZ") || !/^[0-9A-Z]+$/.test(s)) {
52
+ return false;
53
+ }
54
+ const rearranged = s.slice(4) + s.slice(0, 4);
55
+ let remainder = 0;
56
+ for (let i = 0; i < rearranged.length; i++) {
57
+ const ch = rearranged[i];
58
+ const chunk = ch >= "A" && ch <= "Z" ? String(ch.charCodeAt(0) - 55) : ch;
59
+ for (let j = 0; j < chunk.length; j++) {
60
+ remainder = (remainder * 10 + (chunk.charCodeAt(j) - 48)) % 97;
61
+ }
62
+ }
63
+ return remainder === 1;
64
+ }
65
+ export {
66
+ isValidBin,
67
+ isValidIin,
68
+ isValidKzIban,
69
+ luhn
70
+ };
71
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/validators/index.ts"],"sourcesContent":["function digitsOnly(value: string): string {\n return (value ?? \"\").replace(/\\D/g, \"\");\n}\n\nexport function luhn(value: string): boolean {\n const digits = digitsOnly(value);\n if (digits.length === 0) {\n return false;\n }\n let sum = 0;\n let double = false;\n for (let i = digits.length - 1; i >= 0; i--) {\n let d = digits.charCodeAt(i) - 48;\n if (double) {\n d *= 2;\n if (d > 9) {\n d -= 9;\n }\n }\n sum += d;\n double = !double;\n }\n return sum % 10 === 0;\n}\n\nconst IIN_W1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];\nconst IIN_W2 = [3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 2];\n\nfunction iinBinChecksum(value: string): boolean {\n const digits = digitsOnly(value);\n if (digits.length !== 12) {\n return false;\n }\n const d = digits.split(\"\").map(c => c.charCodeAt(0) - 48);\n const weighted = (w: number[]): number =>\n w.reduce((sum, wi, i) => sum + wi * d[i], 0) % 11;\n let control = weighted(IIN_W1);\n if (control === 10) {\n control = weighted(IIN_W2);\n if (control === 10) {\n return false;\n }\n }\n return control === d[11];\n}\n\nexport function isValidIin(value: string): boolean {\n return iinBinChecksum(value);\n}\n\nexport function isValidBin(value: string): boolean {\n return iinBinChecksum(value);\n}\n\nexport function isValidKzIban(value: string): boolean {\n const s = (value ?? \"\").replace(/\\s+/g, \"\").toUpperCase();\n if (s.length !== 20 || !s.startsWith(\"KZ\") || !/^[0-9A-Z]+$/.test(s)) {\n return false;\n }\n const rearranged = s.slice(4) + s.slice(0, 4);\n let remainder = 0;\n for (let i = 0; i < rearranged.length; i++) {\n const ch = rearranged[i];\n // A→10 … Z→35, digits stay as-is\n const chunk = ch >= \"A\" && ch <= \"Z\" ? String(ch.charCodeAt(0) - 55) : ch;\n for (let j = 0; j < chunk.length; j++) {\n remainder = (remainder * 10 + (chunk.charCodeAt(j) - 48)) % 97;\n }\n }\n return remainder === 1;\n}\n"],"mappings":";AAAA,SAAS,WAAW,OAAuB;AACzC,UAAQ,wBAAS,IAAI,QAAQ,OAAO,EAAE;AACxC;AAEO,SAAS,KAAK,OAAwB;AAC3C,QAAM,SAAS,WAAW,KAAK;AAC/B,MAAI,OAAO,WAAW,GAAG;AACvB,WAAO;AAAA,EACT;AACA,MAAI,MAAM;AACV,MAAI,SAAS;AACb,WAAS,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,KAAK;AAC3C,QAAI,IAAI,OAAO,WAAW,CAAC,IAAI;AAC/B,QAAI,QAAQ;AACV,WAAK;AACL,UAAI,IAAI,GAAG;AACT,aAAK;AAAA,MACP;AAAA,IACF;AACA,WAAO;AACP,aAAS,CAAC;AAAA,EACZ;AACA,SAAO,MAAM,OAAO;AACtB;AAEA,IAAM,SAAS,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,EAAE;AACjD,IAAM,SAAS,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,CAAC;AAEjD,SAAS,eAAe,OAAwB;AAC9C,QAAM,SAAS,WAAW,KAAK;AAC/B,MAAI,OAAO,WAAW,IAAI;AACxB,WAAO;AAAA,EACT;AACA,QAAM,IAAI,OAAO,MAAM,EAAE,EAAE,IAAI,OAAK,EAAE,WAAW,CAAC,IAAI,EAAE;AACxD,QAAM,WAAW,CAAC,MAChB,EAAE,OAAO,CAAC,KAAK,IAAI,MAAM,MAAM,KAAK,EAAE,CAAC,GAAG,CAAC,IAAI;AACjD,MAAI,UAAU,SAAS,MAAM;AAC7B,MAAI,YAAY,IAAI;AAClB,cAAU,SAAS,MAAM;AACzB,QAAI,YAAY,IAAI;AAClB,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO,YAAY,EAAE,EAAE;AACzB;AAEO,SAAS,WAAW,OAAwB;AACjD,SAAO,eAAe,KAAK;AAC7B;AAEO,SAAS,WAAW,OAAwB;AACjD,SAAO,eAAe,KAAK;AAC7B;AAEO,SAAS,cAAc,OAAwB;AACpD,QAAM,KAAK,wBAAS,IAAI,QAAQ,QAAQ,EAAE,EAAE,YAAY;AACxD,MAAI,EAAE,WAAW,MAAM,CAAC,EAAE,WAAW,IAAI,KAAK,CAAC,cAAc,KAAK,CAAC,GAAG;AACpE,WAAO;AAAA,EACT;AACA,QAAM,aAAa,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC;AAC5C,MAAI,YAAY;AAChB,WAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;AAC1C,UAAM,KAAK,WAAW,CAAC;AAEvB,UAAM,QAAQ,MAAM,OAAO,MAAM,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,EAAE,IAAI;AACvE,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,mBAAa,YAAY,MAAM,MAAM,WAAW,CAAC,IAAI,OAAO;AAAA,IAC9D;AAAA,EACF;AACA,SAAO,cAAc;AACvB;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-input-mask-format",
3
3
  "description": "Masked input component for React",
4
- "version": "2.0.0",
4
+ "version": "2.2.0",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/Temirtator/react-input-mask-format",
7
7
  "license": "MIT",
@@ -50,6 +50,18 @@
50
50
  "import": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
51
51
  "require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" }
52
52
  },
53
+ "./presets": {
54
+ "import": { "types": "./dist/presets.d.ts", "default": "./dist/presets.js" },
55
+ "require": { "types": "./dist/presets.d.cts", "default": "./dist/presets.cjs" }
56
+ },
57
+ "./validators": {
58
+ "import": { "types": "./dist/validators.d.ts", "default": "./dist/validators.js" },
59
+ "require": { "types": "./dist/validators.d.cts", "default": "./dist/validators.cjs" }
60
+ },
61
+ "./number": {
62
+ "import": { "types": "./dist/number.d.ts", "default": "./dist/number.js" },
63
+ "require": { "types": "./dist/number.d.cts", "default": "./dist/number.cjs" }
64
+ },
53
65
  "./package.json": "./package.json"
54
66
  },
55
67
  "sideEffects": false,
@@ -57,7 +69,10 @@
57
69
  "dist"
58
70
  ],
59
71
  "size-limit": [
60
- { "path": "dist/index.js", "limit": "6 KB" }
72
+ { "path": "dist/index.js", "limit": "6 KB" },
73
+ { "path": "dist/presets.js", "limit": "2 KB" },
74
+ { "path": "dist/validators.js", "limit": "2 KB" },
75
+ { "path": "dist/number.js", "limit": "2.5 KB" }
61
76
  ],
62
77
  "scripts": {
63
78
  "build": "tsup",