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/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/index.js b/src/index.js index 3700cbd6c..aa3c8b045 100644 --- a/src/index.js +++ b/src/index.js @@ -129,6 +129,7 @@ import isLicensePlate from './lib/isLicensePlate'; import isStrongPassword from './lib/isStrongPassword'; import isVAT from './lib/isVAT'; +import isPAN from './lib/isPAN'; const version = '13.15.35'; @@ -244,6 +245,7 @@ const validator = { isTime, isLicensePlate, isVAT, + isPAN, ibanLocales, }; diff --git a/src/lib/isPAN.js b/src/lib/isPAN.js new file mode 100644 index 000000000..c48c28ced --- /dev/null +++ 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); +} diff --git a/test/validators/isPAN.test.js b/test/validators/isPAN.test.js new file mode 100644 index 000000000..2272d2d93 --- /dev/null +++ b/test/validators/isPAN.test.js @@ -0,0 +1,24 @@ +import validator from '../../src/index'; +import assert from 'assert'; + +describe('isPAN', () => { + it('valid PAN', () => { + assert.strictEqual(validator.isPAN('ABCDE1234F'), true); + }); + + it('invalid length', () => { + assert.strictEqual(validator.isPAN('ABCDE123F'), false); + }); + + it('lowercase should fail', () => { + assert.strictEqual(validator.isPAN('abcde1234f'), false); + }); + + it('wrong format', () => { + assert.strictEqual(validator.isPAN('1234ABCDE1'), false); + }); + + it('empty string', () => { + assert.strictEqual(validator.isPAN(''), false); + }); +});