From 667086bd973bd8edf245cdcece5afe295b7fc795 Mon Sep 17 00:00:00 2001 From: AYUSHI1007 Date: Fri, 1 May 2026 12:43:41 +0530 Subject: [PATCH 1/7] Added PAN validator with tests --- build-browser.js | 20 ++++++++++---------- jsconfig.json | 6 ------ package.json | 9 ++++++--- src/lib/isPAN.js | 0 test/validators/isPAN.test.js | 0 5 files changed, 16 insertions(+), 19 deletions(-) delete mode 100644 jsconfig.json create mode 100644 src/lib/isPAN.js create mode 100644 test/validators/isPAN.test.js diff --git a/build-browser.js b/build-browser.js index c863bd399..9587bb4c9 100644 --- a/build-browser.js +++ b/build-browser.js @@ -6,7 +6,7 @@ import babelPresetEnv from "@babel/preset-env"; import pkg from "./package.json"; rollup({ - entry: "src/index.js", + input: "src/index.js", plugins: [ babel({ presets: [[babelPresetEnv, { modules: false }]], @@ -16,15 +16,15 @@ rollup({ }) .then((bundle) => bundle.write({ - dest: "validator.js", - format: "umd", - moduleName: pkg.name, - banner: `/*!\n${String(fs.readFileSync("./LICENSE")) - .trim() - .split("\n") - .map((l) => ` * ${l}`) - .join("\n")}\n */`, - }) + file: "validator.js", + format: "umd", + name: pkg.name, + banner: `/*!\n${String(fs.readFileSync("./LICENSE")) + .trim() + .split("\n") + .map((l) => ` * ${l}`) + .join("\n")}\n */`, +}) ) .catch((e) => { process.stderr.write(`${e.message}\n`); diff --git a/jsconfig.json b/jsconfig.json deleted file mode 100644 index 1376adb2c..000000000 --- a/jsconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "compilerOptions": { - "module": "system", - "target": "ES6" - } -} \ No newline at end of file diff --git a/package.json b/package.json index 2b5c5c8bb..3a42488bd 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,8 @@ "npm-run-all": "^4.1.5", "nyc": "^14.1.0", "rimraf": "^3.0.0", - "rollup": "^0.47.0", - "rollup-plugin-babel": "^4.0.1", + "rollup": "^2.80.0", + "rollup-plugin-babel": "^4.4.0", "timezone-mock": "^1.3.6", "uglify-js": "^3.0.19" }, @@ -72,5 +72,8 @@ "engines": { "node": ">= 0.10" }, - "license": "MIT" + "license": "MIT", + "dependencies": { + "validator": "^13.15.35" + } } diff --git a/src/lib/isPAN.js b/src/lib/isPAN.js new file mode 100644 index 000000000..e69de29bb diff --git a/test/validators/isPAN.test.js b/test/validators/isPAN.test.js new file mode 100644 index 000000000..e69de29bb From 785972ff00339c8add7422b28da34fe947b8031b Mon Sep 17 00:00:00 2001 From: AYUSHI1007 Date: Mon, 4 May 2026 09:55:06 +0530 Subject: [PATCH 2/7] PAN validation addition --- README.md | 2 +- src/index.js | 2 +- src/lib/isPAN.js | 4 ++++ test/validators/isPAN.test.js | 23 +++++++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8ef42fd79..841124bc9 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,7 @@ Sanitizer | Description **trim(input [, chars])** | trim characters (whitespace by default) from both sides of the input. **unescape(input)** | replace HTML encoded entities with `<`, `>`, `&`, `'`, `"`, `` ` ``, `\` and `/`. **whitelist(input, chars)** | remove characters that do not appear in the whitelist. The characters are used in a RegExp and so you will need to escape some chars, e.g. `whitelist(input, '\\[\\]')`. - +**isPAN(str)** | check if the string is a valid Indian PAN number. ### XSS Sanitization XSS sanitization was removed from the library in [2d5d6999](https://github.com/validatorjs/validator.js/commit/2d5d6999541add350fb396ef02dc42ca3215049e). diff --git a/src/index.js b/src/index.js index 3700cbd6c..24db79f10 100644 --- a/src/index.js +++ b/src/index.js @@ -129,7 +129,7 @@ import isLicensePlate from './lib/isLicensePlate'; import isStrongPassword from './lib/isStrongPassword'; import isVAT from './lib/isVAT'; - +export { default as isPAN } from './lib/isPAN'; const version = '13.15.35'; const validator = { diff --git a/src/lib/isPAN.js b/src/lib/isPAN.js index e69de29bb..3cca093af 100644 --- a/src/lib/isPAN.js +++ b/src/lib/isPAN.js @@ -0,0 +1,4 @@ +export default function isPAN(str) { + const panRegex = /^[A-Z]{5}[0-9]{4}[A-Z]$/; + return panRegex.test(str); +} \ No newline at end of file diff --git a/test/validators/isPAN.test.js b/test/validators/isPAN.test.js index e69de29bb..5bc85317a 100644 --- a/test/validators/isPAN.test.js +++ b/test/validators/isPAN.test.js @@ -0,0 +1,23 @@ +import isPAN from '../src/lib/isPAN'; + +describe('isPAN', () => { + it('valid PAN', () => { + if (!isPAN('ABCDE1234F')) throw new Error(); + }); + + it('invalid length', () => { + if (isPAN('ABCDE123F')) throw new Error(); + }); + + it('lowercase should fail', () => { + if (isPAN('abcde1234f')) throw new Error(); + }); + + it('wrong format', () => { + if (isPAN('1234ABCDE1')) throw new Error(); + }); + + it('empty string', () => { + if (isPAN('')) throw new Error(); + }); +}); \ No newline at end of file From ad505b600aa5d7c44432b641e00344b81efb1923 Mon Sep 17 00:00:00 2001 From: AYUSHI1007 Date: Mon, 4 May 2026 10:42:51 +0530 Subject: [PATCH 3/7] isPAN changes --- src/index.js | 3 ++- src/lib/isPAN.js | 2 +- test/validators/isPAN.test.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 24db79f10..028f61372 100644 --- a/src/index.js +++ b/src/index.js @@ -129,7 +129,8 @@ import isLicensePlate from './lib/isLicensePlate'; import isStrongPassword from './lib/isStrongPassword'; import isVAT from './lib/isVAT'; -export { default as isPAN } from './lib/isPAN'; +import isPAN from './lib/isPAN'; + const version = '13.15.35'; const validator = { diff --git a/src/lib/isPAN.js b/src/lib/isPAN.js index 3cca093af..c48c28ced 100644 --- a/src/lib/isPAN.js +++ b/src/lib/isPAN.js @@ -1,4 +1,4 @@ export default function isPAN(str) { const panRegex = /^[A-Z]{5}[0-9]{4}[A-Z]$/; return panRegex.test(str); -} \ No newline at end of file +} diff --git a/test/validators/isPAN.test.js b/test/validators/isPAN.test.js index 5bc85317a..47a2a0188 100644 --- a/test/validators/isPAN.test.js +++ b/test/validators/isPAN.test.js @@ -20,4 +20,4 @@ describe('isPAN', () => { it('empty string', () => { if (isPAN('')) throw new Error(); }); -}); \ No newline at end of file +}); From 1696251b11293efd4f9eabddc4c74119ff31a284 Mon Sep 17 00:00:00 2001 From: AYUSHI1007 Date: Mon, 4 May 2026 10:52:52 +0530 Subject: [PATCH 4/7] isPAN change --- src/index.js | 1 + test/validators/isPAN.test.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 028f61372..aa3c8b045 100644 --- a/src/index.js +++ b/src/index.js @@ -245,6 +245,7 @@ const validator = { isTime, isLicensePlate, isVAT, + isPAN, ibanLocales, }; diff --git a/test/validators/isPAN.test.js b/test/validators/isPAN.test.js index 47a2a0188..e6ff21357 100644 --- a/test/validators/isPAN.test.js +++ b/test/validators/isPAN.test.js @@ -1,4 +1,4 @@ -import isPAN from '../src/lib/isPAN'; +import validator from '../../src/index'; describe('isPAN', () => { it('valid PAN', () => { From 2483f25da527c98580b21632bf521d5a611e6bb4 Mon Sep 17 00:00:00 2001 From: AYUSHI1007 Date: Mon, 4 May 2026 11:01:12 +0530 Subject: [PATCH 5/7] validator fix --- test/validators/isPAN.test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/validators/isPAN.test.js b/test/validators/isPAN.test.js index e6ff21357..9d6deaf20 100644 --- a/test/validators/isPAN.test.js +++ b/test/validators/isPAN.test.js @@ -2,22 +2,22 @@ import validator from '../../src/index'; describe('isPAN', () => { it('valid PAN', () => { - if (!isPAN('ABCDE1234F')) throw new Error(); + validator.isPAN('ABCDE1234F').should.equal(true); }); it('invalid length', () => { - if (isPAN('ABCDE123F')) throw new Error(); + validator.isPAN('ABCDE123F').should.equal(false); }); it('lowercase should fail', () => { - if (isPAN('abcde1234f')) throw new Error(); + validator.isPAN('abcde1234f').should.equal(false); }); it('wrong format', () => { - if (isPAN('1234ABCDE1')) throw new Error(); + validator.isPAN('1234ABCDE1').should.equal(false); }); it('empty string', () => { - if (isPAN('')) throw new Error(); + validator.isPAN('').should.equal(false); }); -}); +}); \ No newline at end of file From aac784c18b1165abb333885a2795603a65a24056 Mon Sep 17 00:00:00 2001 From: AYUSHI1007 Date: Mon, 4 May 2026 11:02:59 +0530 Subject: [PATCH 6/7] New line --- test/validators/isPAN.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators/isPAN.test.js b/test/validators/isPAN.test.js index 9d6deaf20..c3463ab94 100644 --- a/test/validators/isPAN.test.js +++ b/test/validators/isPAN.test.js @@ -20,4 +20,4 @@ describe('isPAN', () => { it('empty string', () => { validator.isPAN('').should.equal(false); }); -}); \ No newline at end of file +}); From 417412e2d98491b4ae9017952db89d1f02174650 Mon Sep 17 00:00:00 2001 From: AYUSHI1007 Date: Mon, 4 May 2026 11:17:09 +0530 Subject: [PATCH 7/7] Node 8 fix --- test/validators/isPAN.test.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/validators/isPAN.test.js b/test/validators/isPAN.test.js index c3463ab94..2272d2d93 100644 --- a/test/validators/isPAN.test.js +++ b/test/validators/isPAN.test.js @@ -1,23 +1,24 @@ import validator from '../../src/index'; +import assert from 'assert'; describe('isPAN', () => { it('valid PAN', () => { - validator.isPAN('ABCDE1234F').should.equal(true); + assert.strictEqual(validator.isPAN('ABCDE1234F'), true); }); it('invalid length', () => { - validator.isPAN('ABCDE123F').should.equal(false); + assert.strictEqual(validator.isPAN('ABCDE123F'), false); }); it('lowercase should fail', () => { - validator.isPAN('abcde1234f').should.equal(false); + assert.strictEqual(validator.isPAN('abcde1234f'), false); }); it('wrong format', () => { - validator.isPAN('1234ABCDE1').should.equal(false); + assert.strictEqual(validator.isPAN('1234ABCDE1'), false); }); it('empty string', () => { - validator.isPAN('').should.equal(false); + assert.strictEqual(validator.isPAN(''), false); }); });