react-intl-number-input 0.8.5 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/number.js ADDED
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveLocale = resolveLocale;
4
+ exports.clampToBounds = clampToBounds;
5
+ exports.createDigitMap = createDigitMap;
6
+ exports.stripAffixes = stripAffixes;
7
+ exports.parseNumber = parseNumber;
8
+ exports.preserveAffixEdit = preserveAffixEdit;
9
+ exports.addStep = addStep;
10
+ function resolveLocale(locale) {
11
+ try {
12
+ return Intl.NumberFormat.supportedLocalesOf([locale])[0] || 'en-US';
13
+ }
14
+ catch (_a) {
15
+ return 'en-US';
16
+ }
17
+ }
18
+ function clampToBounds(value, min, max) {
19
+ return Math.min(Math.max(value, min !== null && min !== void 0 ? min : -Infinity), max !== null && max !== void 0 ? max : Infinity);
20
+ }
21
+ function createDigitMap(locale) {
22
+ const formatter = new Intl.NumberFormat(locale, { useGrouping: false });
23
+ const digits = new Map();
24
+ for (let digit = 0; digit <= 9; digit++) {
25
+ const ascii = String(digit);
26
+ const localized = formatter.formatToParts(digit)
27
+ .filter((part) => part.type === 'integer').map((part) => part.value).join('');
28
+ digits.set(ascii, ascii);
29
+ digits.set(localized, ascii);
30
+ }
31
+ return digits;
32
+ }
33
+ function stripAffixes(text, prefix, suffix) {
34
+ if (prefix && text.startsWith(prefix))
35
+ text = text.slice(prefix.length);
36
+ if (suffix && text.endsWith(suffix))
37
+ text = text.slice(0, -suffix.length);
38
+ return text;
39
+ }
40
+ function parseNumber(text, digits, precision) {
41
+ const negative = /[-\u2212]/.test(text);
42
+ const ascii = Array.from(text).map((character) => digits.get(character) || '').join('');
43
+ // Insert the implied decimal before conversion to avoid overflowing a digit string
44
+ // that represents a finite number after scaling, and unnecessary double rounding.
45
+ const padded = ascii.padStart(precision + 1, '0');
46
+ const decimal = precision === 0 ? padded
47
+ : `${padded.slice(0, -precision)}.${padded.slice(-precision)}`;
48
+ const numeric = Number(decimal);
49
+ return negative ? -numeric : numeric;
50
+ }
51
+ function preserveAffixEdit(previous, next, prefix, suffix) {
52
+ let start = 0;
53
+ while (start < previous.length && start < next.length && previous[start] === next[start])
54
+ start++;
55
+ let end = previous.length;
56
+ let nextEnd = next.length;
57
+ while (end > start && nextEnd > start && previous[end - 1] === next[nextEnd - 1]) {
58
+ end--;
59
+ nextEnd--;
60
+ }
61
+ const numericEnd = previous.length - suffix.length;
62
+ const onlyPrefix = prefix.length > 0 && start < prefix.length && end <= prefix.length;
63
+ const onlySuffix = suffix.length > 0 && start >= numericEnd && end > numericEnd;
64
+ return onlyPrefix || onlySuffix ? previous : next;
65
+ }
66
+ function decimalPlaces(value) {
67
+ var _a;
68
+ const [mantissa, exponent = '0'] = String(value).toLowerCase().split('e');
69
+ return Math.max(0, (((_a = mantissa.split('.')[1]) === null || _a === void 0 ? void 0 : _a.length) || 0) - Number(exponent));
70
+ }
71
+ function addStep(value, delta) {
72
+ const places = Math.max(decimalPlaces(value), decimalPlaces(delta));
73
+ const factor = Math.pow(10, places);
74
+ const scaledValue = Math.round(value * factor);
75
+ const scaledDelta = Math.round(delta * factor);
76
+ const sum = scaledValue + scaledDelta;
77
+ if (Number.isSafeInteger(scaledValue) && Number.isSafeInteger(scaledDelta) && Number.isSafeInteger(sum)) {
78
+ return sum / factor;
79
+ }
80
+ return value + delta;
81
+ }
82
+ //# sourceMappingURL=number.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.js","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uBAA8B,MAAc;IAC1C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC;IACtE,CAAC;eAAO,CAAC;QACP,OAAO,OAAO,CAAC;IACjB,CAAC;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AC,EAAE,EAAE,MAAM,CAAC,CAAC;IACpC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;IAC/C,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;IAC/C,MAAM,GAAG,GAAG,WAAW,GAAG,WAAW,CAAC;IACtC,IAAI,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC;QACxG,OAAO,GAAG,GAAG,MAAM,CAAC;IACtB,CAAC;IACD,OAAO,KAAK,GAAG,KAAK,CAAC;AACvB,CAAC","sourcesContent":["export function resolveLocale(locale: string): string {\n try {\n return Intl.NumberFormat.supportedLocalesOf([locale])[0] || 'en-US';\n } catch {\n return 'en-US';\n }\n}\n\nexport function clampToBounds(value: number, min?: number, max?: number): number {\n return Math.min(Math.max(value, min ?? -Infinity), max ?? Infinity);\n}\n\nexport function createDigitMap(locale: string): Map<string, string> {\n const formatter = new Intl.NumberFormat(locale, { useGrouping: false });\n const digits = new Map<string, string>();\n for (let digit = 0; digit <= 9; digit++) {\n const ascii = String(digit);\n const localized = formatter.formatToParts(digit)\n .filter((part) => part.type === 'integer').map((part) => part.value).join('');\n digits.set(ascii, ascii);\n digits.set(localized, ascii);\n }\n return digits;\n}\n\nexport function stripAffixes(text: string, prefix: string, suffix: string): string {\n if (prefix && text.startsWith(prefix)) text = text.slice(prefix.length);\n if (suffix && text.endsWith(suffix)) text = text.slice(0, -suffix.length);\n return text;\n}\n\nexport function parseNumber(text: string, digits: Map<string, string>, precision: number): number {\n const negative = /[-\\u2212]/.test(text);\n const ascii = Array.from(text).map((character) => digits.get(character) || '').join('');\n // Insert the implied decimal before conversion to avoid overflowing a digit string\n // that represents a finite number after scaling, and unnecessary double rounding.\n const padded = ascii.padStart(precision + 1, '0');\n const decimal = precision === 0 ? padded\n : `${padded.slice(0, -precision)}.${padded.slice(-precision)}`;\n const numeric = Number(decimal);\n return negative ? -numeric : numeric;\n}\n\nexport function preserveAffixEdit(previous: string, next: string, prefix: string, suffix: string): string {\n let start = 0;\n while (start < previous.length && start < next.length && previous[start] === next[start]) start++;\n let end = previous.length;\n let nextEnd = next.length;\n while (end > start && nextEnd > start && previous[end - 1] === next[nextEnd - 1]) {\n end--;\n nextEnd--;\n }\n const numericEnd = previous.length - suffix.length;\n const onlyPrefix = prefix.length > 0 && start < prefix.length && end <= prefix.length;\n const onlySuffix = suffix.length > 0 && start >= numericEnd && end > numericEnd;\n return onlyPrefix || onlySuffix ? previous : next;\n}\n\nfunction decimalPlaces(value: number): number {\n const [mantissa, exponent = '0'] = String(value).toLowerCase().split('e');\n return Math.max(0, (mantissa.split('.')[1]?.length || 0) - Number(exponent));\n}\n\nexport function addStep(value: number, delta: number): number {\n const places = Math.max(decimalPlaces(value), decimalPlaces(delta));\n const factor = Math.pow(10, places);\n const scaledValue = Math.round(value * factor);\n const scaledDelta = Math.round(delta * factor);\n const sum = scaledValue + scaledDelta;\n if (Number.isSafeInteger(scaledValue) && Number.isSafeInteger(scaledDelta) && Number.isSafeInteger(sum)) {\n return sum / factor;\n }\n return value + delta;\n}\n"]}
package/package.json CHANGED
@@ -1,80 +1,94 @@
1
- {
2
- "name": "react-intl-number-input",
3
- "version": "0.8.5",
4
- "description": "A React component for masked and formatted number input.",
5
- "main": "dist/index.js",
6
- "module": "dist/esm/index.js",
7
- "types": "dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/esm/index.js",
12
- "require": "./dist/index.js",
13
- "default": "./dist/index.js"
14
- }
15
- },
16
- "files": [
17
- "dist",
18
- "README.md",
19
- "LICENSE",
20
- "CHANGELOG.md",
21
- "CONTRIBUTING.md"
22
- ],
23
- "engines": {
24
- "node": ">=20"
25
- },
26
- "sideEffects": false,
27
- "scripts": {
28
- "test": "jest --runInBand",
29
- "dev": "node scripts/demo.mjs",
30
- "start": "node scripts/demo.mjs",
31
- "transpile": "npm run build:lib",
32
- "build:cjs": "tsc",
33
- "build:esm": "tsc -p tsconfig.esm.json",
34
- "build:lib": "npm run build:cjs && npm run build:esm && node -e \"require('fs').writeFileSync('dist/esm/package.json', '{\\\"type\\\": \\\"module\\\"}')\"",
35
- "prepublishOnly": "npm test && npm run build:lib",
36
- "build": "node scripts/demo.mjs --production",
37
- "deploy": "gh-pages -d example/dist",
38
- "publish-demo": "npm run build && npm run deploy"
39
- },
40
- "repository": {
41
- "type": "git",
42
- "url": "git+https://github.com/nandorip/react-intl-number-input.git"
43
- },
44
- "keywords": [
45
- "react",
46
- "react-component",
47
- "javascript",
48
- "mask",
49
- "currency",
50
- "money",
51
- "number",
52
- "intl",
53
- "input",
54
- "typescript"
55
- ],
56
- "author": "Fernando Pires Reherman <nandorip@live.com>",
57
- "license": "MIT",
58
- "bugs": {
59
- "url": "https://github.com/nandorip/react-intl-number-input/issues"
60
- },
61
- "homepage": "https://github.com/nandorip/react-intl-number-input#readme",
62
- "peerDependencies": {
63
- "react": ">=16.8.0 <20"
64
- },
65
- "devDependencies": {
66
- "@testing-library/jest-dom": "^7.0.1",
67
- "@testing-library/react": "^16.3.2",
68
- "@types/react": "^19.2.18",
69
- "esbuild": "^0.28.2",
70
- "gh-pages": "^6.3.0",
71
- "jest": "^30.4.2",
72
- "jest-environment-jsdom": "^30.4.1",
73
- "react": "^19.2.8",
74
- "react-dom": "^19.2.8",
75
- "typescript": "^7.0.2"
76
- },
77
- "overrides": {
78
- "js-yaml": "4.3.1"
79
- }
80
- }
1
+ {
2
+ "name": "react-intl-number-input",
3
+ "version": "0.9.0",
4
+ "description": "A React component for masked and formatted number input.",
5
+ "main": "dist/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/esm/index.d.ts",
12
+ "default": "./dist/esm/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "README.md",
23
+ "LICENSE",
24
+ "CHANGELOG.md",
25
+ "CONTRIBUTING.md"
26
+ ],
27
+ "engines": {
28
+ "node": ">=20"
29
+ },
30
+ "sideEffects": false,
31
+ "scripts": {
32
+ "test": "jest --runInBand",
33
+ "typecheck": "tsc -p tsconfig.check.json",
34
+ "check:package": "node scripts/check-package.mjs",
35
+ "check": "npm test && npm run typecheck && npm run build:lib && npm run check:package",
36
+ "dev": "node scripts/demo.mjs",
37
+ "start": "node scripts/demo.mjs",
38
+ "transpile": "npm run build:lib",
39
+ "build:cjs": "tsc",
40
+ "build:esm": "tsc -p tsconfig.esm.json",
41
+ "build:lib": "npm run build:cjs && npm run build:esm && node -e \"require('fs').writeFileSync('dist/esm/package.json', '{\\\"type\\\": \\\"module\\\"}')\"",
42
+ "prepack": "npm run build:lib",
43
+ "prepublishOnly": "npm run check",
44
+ "build": "node scripts/demo.mjs --production",
45
+ "deploy": "gh-pages -d example/dist",
46
+ "publish-demo": "npm run build && npm run deploy",
47
+ "release": "node scripts/release.mjs"
48
+ },
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "git+https://github.com/nandorip/react-intl-number-input.git"
52
+ },
53
+ "keywords": [
54
+ "react",
55
+ "react-component",
56
+ "javascript",
57
+ "mask",
58
+ "currency",
59
+ "money",
60
+ "number",
61
+ "intl",
62
+ "input",
63
+ "typescript"
64
+ ],
65
+ "author": "Fernando Pires Reherman <nandorip@live.com>",
66
+ "license": "MIT",
67
+ "bugs": {
68
+ "url": "https://github.com/nandorip/react-intl-number-input/issues"
69
+ },
70
+ "homepage": "https://github.com/nandorip/react-intl-number-input#readme",
71
+ "peerDependencies": {
72
+ "react": ">=16.8.0 <20"
73
+ },
74
+ "devDependencies": {
75
+ "@testing-library/jest-dom": "^7.0.1",
76
+ "@testing-library/react": "^16.3.3",
77
+ "@types/react": "^19.3.0",
78
+ "@types/react-dom": "^19.3.0",
79
+ "esbuild": "^0.28.2",
80
+ "gh-pages": "6.1.1",
81
+ "jest": "^30.5.2",
82
+ "jest-environment-jsdom": "^30.5.2",
83
+ "react": "^19.3.0",
84
+ "react-dom": "^19.3.0",
85
+ "typescript": "^7.0.2"
86
+ },
87
+ "overrides": {
88
+ "js-yaml": "4.3.2"
89
+ },
90
+ "allowScripts": {
91
+ "esbuild": true,
92
+ "unrs-resolver": true
93
+ }
94
+ }