@alwatr/iranian-national-code-validator 1.0.22 โ†’ 2.0.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/main.js ADDED
@@ -0,0 +1,5 @@
1
+ /* ๐Ÿ“ฆ @alwatr/iranian-national-code-validator v2.0.0 */
2
+ function n(i){if(!/^\d{10}$/.test(i))return!1;let a=+i[9],e=i.split("").slice(0,9).reduce((t,o,l)=>t+ +o*(10-l),0)%11;return e<2?a===e:a+e===11}export{n as isValidIranianNationalCode};
3
+
4
+ //# debugId=0FBEF7D003BA0D6364756E2164756E21
5
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/main.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Validates an Iranian National Code (Code Melli).\n *\n * The validation is based on the official algorithm:\n * 1. The code must be 10 digits.\n * 2. The last digit is a check digit.\n * 3. A weighted sum of the first 9 digits is calculated.\n * 4. The remainder of the sum divided by 11 is compared with the check digit based on a specific rule.\n *\n * @param str The Iranian National Code to validate.\n * @returns `true` if the national code is valid, `false` otherwise.\n *\n * @example\n * ```ts\n * console.log(isValidIranianNationalCode('0018550152')); // true\n * console.log(isValidIranianNationalCode('0018550153')); // false\n * console.log(isValidIranianNationalCode('12345')); // false\n * ```\n */\nexport function isValidIranianNationalCode(str: string): boolean {\n if (!/^\\d{10}$/.test(str)) return false;\n\n const check = +str[9];\n const sum = str.split('').slice(0, 9).reduce((acc, x, i) => acc + +x * (10 - i), 0) % 11;\n\n return sum < 2 ? check === sum : check + sum === 11;\n}\n"
6
+ ],
7
+ "mappings": ";AAmBO,SAAS,CAA0B,CAAC,EAAsB,CAC/D,GAAI,CAAC,WAAW,KAAK,CAAG,EAAG,MAAO,GAElC,IAAM,EAAQ,CAAC,EAAI,GACb,EAAM,EAAI,MAAM,EAAE,EAAE,MAAM,EAAG,CAAC,EAAE,OAAO,CAAC,EAAK,EAAG,IAAM,GAAM,CAAC,GAAK,GAAK,GAAI,CAAC,EAAI,GAEtF,OAAO,EAAM,EAAI,IAAU,EAAM,EAAQ,IAAQ",
8
+ "debugId": "0FBEF7D003BA0D6364756E2164756E21",
9
+ "names": []
10
+ }
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "@alwatr/iranian-national-code-validator",
3
3
  "description": "A tiny TypeScript library to Validates an Iranian National Code (Code Melli).",
4
- "version": "1.0.22",
4
+ "version": "2.0.0",
5
5
  "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
6
6
  "bugs": "https://github.com/Alwatr/nanolib/issues",
7
7
  "devDependencies": {
8
- "@alwatr/nano-build": "6.4.2",
9
- "@alwatr/prettier-config": "6.0.2",
10
- "@alwatr/tsconfig-base": "6.0.4",
11
- "@alwatr/type-helper": "7.0.2",
8
+ "@alwatr/nano-build": "7.0.0",
9
+ "@alwatr/prettier-config": "7.0.0",
10
+ "@alwatr/tsconfig-base": "7.0.0",
11
+ "@alwatr/type-helper": "8.0.0",
12
12
  "typescript": "^5.9.3"
13
13
  },
14
14
  "exports": {
15
15
  ".": {
16
16
  "types": "./dist/main.d.ts",
17
- "import": "./dist/main.mjs",
18
- "require": "./dist/main.cjs"
17
+ "default": "./dist/main.js"
19
18
  }
20
19
  },
21
20
  "files": [
22
- "**/*.{js,mjs,cjs,map,d.ts,html,md,LEGAL.txt}",
21
+ "**/*.{js,mjs,cjs,ts,map,d.ts,html,LEGAL.txt}",
22
+ "README.md",
23
23
  "LICENSE",
24
24
  "!demo/**/*",
25
25
  "!**/*.test.js"
@@ -43,8 +43,6 @@
43
43
  "validator"
44
44
  ],
45
45
  "license": "MPL-2.0",
46
- "main": "./dist/main.cjs",
47
- "module": "./dist/main.mjs",
48
46
  "prettier": "@alwatr/prettier-config",
49
47
  "publishConfig": {
50
48
  "access": "public"
@@ -57,12 +55,12 @@
57
55
  "scripts": {
58
56
  "b": "bun run build",
59
57
  "build": "bun run build:ts && bun run build:es",
60
- "build:es": "nano-build --preset=module",
58
+ "build:es": "nano-build --preset=module src/main.ts",
61
59
  "build:ts": "tsc --build",
62
60
  "c": "bun run clean",
63
61
  "cb": "bun run clean && bun run build",
64
62
  "clean": "rm -rfv dist *.tsbuildinfo",
65
- "d": "bun run build:es && bun --enable-source-maps --trace-warnings",
63
+ "d": "bun run build:es && bun",
66
64
  "t": "bun run test",
67
65
  "test": "bun test",
68
66
  "w": "bun run watch",
@@ -73,5 +71,5 @@
73
71
  "sideEffects": false,
74
72
  "type": "module",
75
73
  "types": "./dist/main.d.ts",
76
- "gitHead": "def1decf8f496f4b0d3d3ab952c346c689c30160"
74
+ "gitHead": "056102a1c8a563bbae8a290b6830450f467322a3"
77
75
  }
package/src/main.ts ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Validates an Iranian National Code (Code Melli).
3
+ *
4
+ * The validation is based on the official algorithm:
5
+ * 1. The code must be 10 digits.
6
+ * 2. The last digit is a check digit.
7
+ * 3. A weighted sum of the first 9 digits is calculated.
8
+ * 4. The remainder of the sum divided by 11 is compared with the check digit based on a specific rule.
9
+ *
10
+ * @param str The Iranian National Code to validate.
11
+ * @returns `true` if the national code is valid, `false` otherwise.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * console.log(isValidIranianNationalCode('0018550152')); // true
16
+ * console.log(isValidIranianNationalCode('0018550153')); // false
17
+ * console.log(isValidIranianNationalCode('12345')); // false
18
+ * ```
19
+ */
20
+ export function isValidIranianNationalCode(str: string): boolean {
21
+ if (!/^\d{10}$/.test(str)) return false;
22
+
23
+ const check = +str[9];
24
+ const sum = str.split('').slice(0, 9).reduce((acc, x, i) => acc + +x * (10 - i), 0) % 11;
25
+
26
+ return sum < 2 ? check === sum : check + sum === 11;
27
+ }
package/CHANGELOG.md DELETED
@@ -1,125 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [1.0.22](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.21...@alwatr/iranian-national-code-validator@1.0.22) (2026-03-18)
7
-
8
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
9
-
10
- ## [1.0.21](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.20...@alwatr/iranian-national-code-validator@1.0.21) (2026-03-16)
11
-
12
- ### ๐Ÿ”จ Code Refactoring
13
-
14
- * migrate build scripts from yarn to bun across multiple packages ([d90e962](https://github.com/Alwatr/nanolib/commit/d90e962f15e5c951e191d5f02341279b6472abc3))
15
-
16
- ## [1.0.20](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.19...@alwatr/iranian-national-code-validator@1.0.20) (2026-02-18)
17
-
18
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
19
-
20
- ## [1.0.19](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.18...@alwatr/iranian-national-code-validator@1.0.19) (2025-12-23)
21
-
22
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
23
-
24
- ## [1.0.18](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.17...@alwatr/iranian-national-code-validator@1.0.18) (2025-12-13)
25
-
26
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
27
-
28
- ## [1.0.17](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.16...@alwatr/iranian-national-code-validator@1.0.17) (2025-12-10)
29
-
30
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
31
-
32
- ## [1.0.16](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.15...@alwatr/iranian-national-code-validator@1.0.16) (2025-11-18)
33
-
34
- ### ๐Ÿ”จ Code Refactoring
35
-
36
- * remove unnecessary type declarations from tsconfig.json files ([89bcc7d](https://github.com/Alwatr/nanolib/commit/89bcc7db839807110b80f8ba34414ea9734d9c75))
37
-
38
- ## [1.0.15](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.14...@alwatr/iranian-national-code-validator@1.0.15) (2025-11-15)
39
-
40
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
41
-
42
- ## [1.0.14](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.13...@alwatr/iranian-national-code-validator@1.0.14) (2025-11-15)
43
-
44
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
45
-
46
- ## [1.0.13](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.12...@alwatr/iranian-national-code-validator@1.0.13) (2025-11-04)
47
-
48
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
49
-
50
- ## [1.0.12](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.11...@alwatr/iranian-national-code-validator@1.0.12) (2025-10-06)
51
-
52
- ### ๐Ÿ”— Dependencies update
53
-
54
- * bump the npm-dependencies group with 4 updates ([9825815](https://github.com/Alwatr/nanolib/commit/982581552bbb4b97dca52af5e93a80937f0c3109))
55
-
56
- ## [1.0.11](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.10...@alwatr/iranian-national-code-validator@1.0.11) (2025-09-27)
57
-
58
- ### ๐Ÿงน Miscellaneous Chores
59
-
60
- * exclude test files from package distribution ([86f4f2f](https://github.com/Alwatr/nanolib/commit/86f4f2f5985845c5cf3a3a9398de7b2f98ce53e7))
61
-
62
- ## [1.0.10](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.9...@alwatr/iranian-national-code-validator@1.0.10) (2025-09-22)
63
-
64
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
65
-
66
- ## [1.0.9](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.8...@alwatr/iranian-national-code-validator@1.0.9) (2025-09-22)
67
-
68
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
69
-
70
- ## [1.0.8](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.7...@alwatr/iranian-national-code-validator@1.0.8) (2025-09-21)
71
-
72
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
73
-
74
- ## [1.0.7](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.6...@alwatr/iranian-national-code-validator@1.0.7) (2025-09-20)
75
-
76
- ### ๐Ÿ› Bug Fixes
77
-
78
- * add sideEffects property to package.json files for better tree-shaking ([c7b9e74](https://github.com/Alwatr/nanolib/commit/c7b9e74e1920c8e35b438742de61883ca62da58c))
79
- * add sideEffects property to package.json files for better tree-shaking ([e8402c4](https://github.com/Alwatr/nanolib/commit/e8402c481a14a1f807a37aaa862a936713d26176))
80
-
81
- ### ๐Ÿงน Miscellaneous Chores
82
-
83
- * remove duplicate sideEffects property from multiple package.json files ([b123f86](https://github.com/Alwatr/nanolib/commit/b123f86be81481de2314aae9bb2eeb629743d24c))
84
-
85
- ## [1.0.6](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.5...@alwatr/iranian-national-code-validator@1.0.6) (2025-09-19)
86
-
87
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
88
-
89
- ## [1.0.5](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.4...@alwatr/iranian-national-code-validator@1.0.5) (2025-09-15)
90
-
91
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
92
-
93
- ## [1.0.4](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.3...@alwatr/iranian-national-code-validator@1.0.4) (2025-09-13)
94
-
95
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
96
-
97
- ## [1.0.3](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.2...@alwatr/iranian-national-code-validator@1.0.3) (2025-09-13)
98
-
99
- ### ๐Ÿงน Miscellaneous Chores
100
-
101
- * remove package-tracer dependency and related code from fetch package ([96fe4e9](https://github.com/Alwatr/nanolib/commit/96fe4e9552a205f218ceed187c55e4e904a07089))
102
-
103
- ## [1.0.2](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.1...@alwatr/iranian-national-code-validator@1.0.2) (2025-09-09)
104
-
105
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
106
-
107
- ## [1.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/iranian-national-code-validator@1.0.0...@alwatr/iranian-national-code-validator@1.0.1) (2025-09-06)
108
-
109
- **Note:** Version bump only for package @alwatr/iranian-national-code-validator
110
-
111
- ## 1.0.0 (2025-09-05)
112
-
113
- ### ๐Ÿ”จ Code Refactoring
114
-
115
- * rename package & update its usages ([1c3064a](https://github.com/Alwatr/nanolib/commit/1c3064a8d5d7a408f697f200439a4c979dd0e6df))
116
- * update package.json structure and license from AGPL-3.0 to MPL-2.0 ([f72fb2b](https://github.com/Alwatr/nanolib/commit/f72fb2b4a39919305a7e61056c07b9e58284f809))
117
-
118
- ### ๐Ÿงน Miscellaneous Chores
119
-
120
- * replace GNU AGPL with Mozilla Public License 2.0 for the Iranian National Code Validator package ([7efa5ce](https://github.com/Alwatr/nanolib/commit/7efa5ce68ede8059cd98d5458a22e280a01f37ff))
121
-
122
- ### ๐Ÿ”— Dependencies update
123
-
124
- * fix TypeScript version ([b041c1e](https://github.com/Alwatr/nanolib/commit/b041c1e54935b7d2870406b27f7be29aeaa5f308))
125
- * update workspace dependency versions to use wildcard ([c7c06e5](https://github.com/Alwatr/nanolib/commit/c7c06e54c240317f13f35bb0c2bed92058ec8dbe))
package/dist/main.cjs DELETED
@@ -1,3 +0,0 @@
1
- /** ๐Ÿ“ฆ @alwatr/iranian-national-code-validator v1.0.22 */
2
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var main_exports={};__export(main_exports,{isValidIranianNationalCode:()=>isValidIranianNationalCode});module.exports=__toCommonJS(main_exports);function isValidIranianNationalCode(str){if(!/^\d{10}$/.test(str))return false;const check=+str[9];const sum=str.split("").slice(0,9).reduce((acc,x,i)=>acc+ +x*(10-i),0)%11;return sum<2?check===sum:check+sum===11}0&&(module.exports={isValidIranianNationalCode});
3
- //# sourceMappingURL=main.cjs.map
package/dist/main.cjs.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/main.ts"],
4
- "sourcesContent": ["/**\n * Validates an Iranian National Code (Code Melli).\n *\n * The validation is based on the official algorithm:\n * 1. The code must be 10 digits.\n * 2. The last digit is a check digit.\n * 3. A weighted sum of the first 9 digits is calculated.\n * 4. The remainder of the sum divided by 11 is compared with the check digit based on a specific rule.\n *\n * @param str The Iranian National Code to validate.\n * @returns `true` if the national code is valid, `false` otherwise.\n *\n * @example\n * ```ts\n * console.log(isValidIranianNationalCode('0018550152')); // true\n * console.log(isValidIranianNationalCode('0018550153')); // false\n * console.log(isValidIranianNationalCode('12345')); // false\n * ```\n */\nexport function isValidIranianNationalCode(str: string): boolean {\n if (!/^\\d{10}$/.test(str)) return false;\n\n const check = +str[9];\n const sum = str.split('').slice(0, 9).reduce((acc, x, i) => acc + +x * (10 - i), 0) % 11;\n\n return sum < 2 ? check === sum : check + sum === 11;\n}\n"],
5
- "mappings": ";qqBAAA,iJAmBO,SAAS,2BAA2B,IAAsB,CAC/D,GAAI,CAAC,WAAW,KAAK,GAAG,EAAG,MAAO,OAElC,MAAM,MAAQ,CAAC,IAAI,CAAC,EACpB,MAAM,IAAM,IAAI,MAAM,EAAE,EAAE,MAAM,EAAG,CAAC,EAAE,OAAO,CAAC,IAAK,EAAG,IAAM,KAAM,CAAC,GAAK,GAAK,GAAI,CAAC,EAAI,GAEtF,OAAO,IAAM,EAAI,QAAU,IAAM,MAAQ,MAAQ,EACnD",
6
- "names": []
7
- }
package/dist/main.mjs DELETED
@@ -1,3 +0,0 @@
1
- /** ๐Ÿ“ฆ @alwatr/iranian-national-code-validator v1.0.22 */
2
- function isValidIranianNationalCode(str){if(!/^\d{10}$/.test(str))return false;const check=+str[9];const sum=str.split("").slice(0,9).reduce((acc,x,i)=>acc+ +x*(10-i),0)%11;return sum<2?check===sum:check+sum===11}export{isValidIranianNationalCode};
3
- //# sourceMappingURL=main.mjs.map
package/dist/main.mjs.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/main.ts"],
4
- "sourcesContent": ["/**\n * Validates an Iranian National Code (Code Melli).\n *\n * The validation is based on the official algorithm:\n * 1. The code must be 10 digits.\n * 2. The last digit is a check digit.\n * 3. A weighted sum of the first 9 digits is calculated.\n * 4. The remainder of the sum divided by 11 is compared with the check digit based on a specific rule.\n *\n * @param str The Iranian National Code to validate.\n * @returns `true` if the national code is valid, `false` otherwise.\n *\n * @example\n * ```ts\n * console.log(isValidIranianNationalCode('0018550152')); // true\n * console.log(isValidIranianNationalCode('0018550153')); // false\n * console.log(isValidIranianNationalCode('12345')); // false\n * ```\n */\nexport function isValidIranianNationalCode(str: string): boolean {\n if (!/^\\d{10}$/.test(str)) return false;\n\n const check = +str[9];\n const sum = str.split('').slice(0, 9).reduce((acc, x, i) => acc + +x * (10 - i), 0) % 11;\n\n return sum < 2 ? check === sum : check + sum === 11;\n}\n"],
5
- "mappings": ";AAmBO,SAAS,2BAA2B,IAAsB,CAC/D,GAAI,CAAC,WAAW,KAAK,GAAG,EAAG,MAAO,OAElC,MAAM,MAAQ,CAAC,IAAI,CAAC,EACpB,MAAM,IAAM,IAAI,MAAM,EAAE,EAAE,MAAM,EAAG,CAAC,EAAE,OAAO,CAAC,IAAK,EAAG,IAAM,KAAM,CAAC,GAAK,GAAK,GAAI,CAAC,EAAI,GAEtF,OAAO,IAAM,EAAI,QAAU,IAAM,MAAQ,MAAQ,EACnD",
6
- "names": []
7
- }