From 76b5da485afd90db44710a27364f52bf4cbc4f85 Mon Sep 17 00:00:00 2001 From: Mohamed Amin Boubaker Date: Tue, 24 Sep 2019 14:59:00 +0100 Subject: [PATCH 1/4] added support for Tunisia National Identity Card test Successfully passed Signed-off-by: Mohamed Amin Boubaker --- README.md | 2 +- src/lib/isIdentityCard.js | 12 ++++++++++++ test/validators.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 239b3a8e1..d19ec3b48 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ Validator | Description **isHexColor(str)** | check if the string is a hexadecimal color. **isHSL(str)** | check if the string is an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).

Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: `hsl(200grad+.1%62%/1)`). **isRgbColor(str, [, includePercentValues])** | check if the string is a rgb or rgba color.

`includePercentValues` defaults to `true`. If you don't want to allow to set `rgb` or `rgba` values with percents, like `rgb(5%,5%,5%)`, or `rgba(90%,90%,90%,.3)`, then set it to false. -**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'zh-TW', 'he-IL']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. +**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'zh-TW', 'he-IL', 'ar-TN']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. **isIn(str, values)** | check if the string is in a array of allowed values. **isInt(str [, options])** | check if the string is an integer.

`options` is an object which can contain the keys `min` and/or `max` to check the integer is within boundaries (e.g. `{ min: 10, max: 99 }`). `options` can also contain the key `allow_leading_zeroes`, which when set to false will disallow integer values with leading zeroes (e.g. `{ allow_leading_zeroes: false }`). Finally, `options` can contain the keys `gt` and/or `lt` which will enforce integers being greater than or less than, respectively, the value provided (e.g. `{gt: 1, lt: 4}` for a number between 1 and 4). **isIP(str [, version])** | check if the string is an IP (version 4 or 6). diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index c74acde2a..6e7d29a5a 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -51,6 +51,18 @@ const validators = { } return sum % 10 === 0; }, + 'ar-TN': (str) => { + const DNI = /^\d{8}$/; + + // sanitize user input + const sanitized = str.trim(); + + // validate the data structure + if (!DNI.test(sanitized)) { + return false; + } + return true; + }, 'zh-TW': (str) => { const ALPHABET_CODES = { A: 10, diff --git a/test/validators.js b/test/validators.js index 2a76438a1..7b82560fe 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3977,6 +3977,35 @@ describe('Validators', () => { '336000842', ], }, + { + locale: 'ar-TN', + valid: [ + '09958092', + '09151092', + '65126506', + '79378815', + '58994407', + '73089789', + '73260311', + ], + invalid: [ + '123456789546', + '123456789', + '023456789', + '12345678A', + '12345', + '1234578A', + '123 578A', + '12345 678Z', + '12345678-Z', + '1234*6789', + '1234*678Z', + 'GE9800as98', + 'X231071922', + '1234*678Z', + '12345678!', + ], + }, { locale: 'zh-TW', valid: [ From b801e49e9d95b58ebd01a2aea53a47b003b078e9 Mon Sep 17 00:00:00 2001 From: Mohamed Amin Boubaker Date: Tue, 24 Sep 2019 16:21:32 +0100 Subject: [PATCH 2/4] package script update clean.win : clean script for windows buildtest : one script to build and test --- package.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b9d0f46bf..e79268676 100644 --- a/package.json +++ b/package.json @@ -58,16 +58,21 @@ "lint": "eslint src test", "lint:fix": "eslint --fix src test", "clean:node": "rm -rf index.js lib", + "clean:node.win": "RMDIR /S /Q lib && ERASE /F /Q index.js", "clean:es": "rm -rf es", + "clean:es.win": "RMDIR /S /Q es", "clean:browser": "rm -rf validator*.js", + "clean:browser.win": "ERASE /F /Q validator*.js", "clean": "npm run clean:node && npm run clean:browser && npm run clean:es", + "clean.win": "npm run clean:node.win && npm run clean:browser.win && npm run clean:es.win", "minify": "uglifyjs validator.js -o validator.min.js --compress --mangle --comments /Copyright/", "build:browser": "node --require @babel/register build-browser && npm run minify", "build:es": "babel src -d es --env-name=es", "build:node": "babel src -d .", "build": "npm run build:browser && npm run build:node && npm run build:es", "pretest": "npm run lint && npm run build", - "test": "nyc mocha --require @babel/register --reporter dot" + "test": "nyc mocha --require @babel/register --reporter dot", + "buildtest": "npm run build && npm run lint:fix && npm run test" }, "engines": { "node": ">= 0.10" From 062f4bf481f92e1640184fda66b996264396528c Mon Sep 17 00:00:00 2001 From: Mohamed Amin Boubaker Date: Sun, 17 Nov 2019 18:08:49 +0100 Subject: [PATCH 3/4] don't need to add a buildtest command since pretest will be called automatically by npm test Signed-off-by: Mohamed Amin Boubaker --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index e79268676..572315c95 100644 --- a/package.json +++ b/package.json @@ -71,8 +71,7 @@ "build:node": "babel src -d .", "build": "npm run build:browser && npm run build:node && npm run build:es", "pretest": "npm run lint && npm run build", - "test": "nyc mocha --require @babel/register --reporter dot", - "buildtest": "npm run build && npm run lint:fix && npm run test" + "test": "nyc mocha --require @babel/register --reporter dot" }, "engines": { "node": ">= 0.10" From ee516ed82bac02e2b706d2f7d0c126e7ce2eac75 Mon Sep 17 00:00:00 2001 From: Mohamed Amin Boubaker Date: Sun, 17 Nov 2019 19:12:45 +0100 Subject: [PATCH 4/4] use `yarn clean` command with `rimraf` for cross platform support Signed-off-by: Mohamed Amin Boubaker --- package.json | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 572315c95..ef9a80309 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "eslint-plugin-import": "^2.11.0", "mocha": "^5.1.1", "nyc": "^14.1.0", + "rimraf": "^3.0.0", "rollup": "^0.43.0", "rollup-plugin-babel": "^4.0.1", "uglify-js": "^3.0.19" @@ -57,14 +58,10 @@ "scripts": { "lint": "eslint src test", "lint:fix": "eslint --fix src test", - "clean:node": "rm -rf index.js lib", - "clean:node.win": "RMDIR /S /Q lib && ERASE /F /Q index.js", - "clean:es": "rm -rf es", - "clean:es.win": "RMDIR /S /Q es", - "clean:browser": "rm -rf validator*.js", - "clean:browser.win": "ERASE /F /Q validator*.js", + "clean:node": "rimraf index.js lib", + "clean:es": "rimraf es", + "clean:browser": "rimraf validator*.js", "clean": "npm run clean:node && npm run clean:browser && npm run clean:es", - "clean.win": "npm run clean:node.win && npm run clean:browser.win && npm run clean:es.win", "minify": "uglifyjs validator.js -o validator.min.js --compress --mangle --comments /Copyright/", "build:browser": "node --require @babel/register build-browser && npm run minify", "build:es": "babel src -d es --env-name=es",