Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mhf-ir authored Mar 10, 2021
2 parents ff72417 + deb1d1e commit ec435d5
Show file tree
Hide file tree
Showing 18 changed files with 511 additions and 359 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
test:
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [14, 12, 10, 8, 6]
name: Run tests on Node.js ${{ matrix.node-version }}
steps:
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2-beta
with:
node-version: ${{ matrix.node-version }}
check-latest: true
- name: Checkout repository
uses: actions/checkout@v2
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- if: matrix.node-version == 14
name: Generate coverage file
run: npm run test:ci > coverage.lcov
- if: matrix.node-version == 14
name: Send coverage info to Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.lcov
24 changes: 24 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: NPM Publish
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-20.04
steps:
- name: Setup Node.js 14
uses: actions/setup-node@v2-beta
with:
node-version: 14
check-latest: true
registry-url: https://registry.npmjs.org/
- name: Checkout Repository
uses: actions/checkout@v2
- name: Install Dependencies
run: npm install
- name: Run Tests
run: npm test
- name: Publish Package to NPM Registry
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_SECRET}}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ package-lock.json
yarn.lock
/es
/lib
/index.js
validator.js
validator.min.js
index.js
4 changes: 0 additions & 4 deletions .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,5 @@
],
"include": [
"src/**/*.js"
],
"exclude": [
"validator.js",
"lib/**/*.js"
]
}
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

610 changes: 305 additions & 305 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "validator-js",
"main": "validator.js",
"homepage": "https://github.com/chriso/validator.js",
"homepage": "https://github.com/validatorjs/validator.js",
"authors": [
"Chris O'Hara <[email protected]>"
],
Expand Down
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "String validation and sanitization",
"version": "13.5.1",
"sideEffects": false,
"homepage": "https://github.com/chriso/validator.js",
"homepage": "https://github.com/validatorjs/validator.js",
"files": [
"index.js",
"es",
Expand All @@ -25,18 +25,15 @@
],
"author": "Chris O'Hara <[email protected]>",
"contributors": [
{
"name": "Anthony Nandaa",
"url": "https://github.com/profnandaa"
}
"Anthony Nandaa (https://github.com/profnandaa)"
],
"main": "index.js",
"bugs": {
"url": "https://github.com/chriso/validator.js/issues"
"url": "https://github.com/validatorjs/validator.js/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/chriso/validator.js.git"
"url": "git+https://github.com/validatorjs/validator.js.git"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
Expand Down
18 changes: 16 additions & 2 deletions src/lib/isAlphanumeric.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import assertString from './util/assertString';
import { alphanumeric } from './alpha';

export default function isAlphanumeric(str, locale = 'en-US') {
assertString(str);
export default function isAlphanumeric(_str, locale = 'en-US', options = {}) {
assertString(_str);

let str = _str;
const { ignore } = options;

if (ignore) {
if (ignore instanceof RegExp) {
str = str.replace(ignore, '');
} else if (typeof ignore === 'string') {
str = str.replace(new RegExp(`[${ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&')}]`, 'g'), ''); // escape regex for ignore
} else {
throw new Error('ignore should be instance of a String or RegExp');
}
}

if (locale in alphanumeric) {
return alphanumeric[locale].test(str);
}
Expand Down
7 changes: 4 additions & 3 deletions src/lib/isDataURI.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export default function isDataURI(str) {
return false;
}
for (let i = 0; i < attributes.length; i++) {
if (i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') {
// ok
} else if (!validAttribute.test(attributes[i])) {
if (
!(i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') &&
!validAttribute.test(attributes[i])
) {
return false;
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/lib/isEAN.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
* the thirteen-digit EAN-13, while the
* less commonly used 8-digit EAN-8 barcode was
* introduced for use on small packages.
* Also EAN/UCC-14 is used for Grouping of individual
* trade items above unit level(Intermediate, Carton or Pallet).
* For more info about EAN-14 checkout: https://www.gtin.info/itf-14-barcodes/
* EAN consists of:
* GS1 prefix, manufacturer code, product code and check digit
* Reference: https://en.wikipedia.org/wiki/International_Article_Number
* Reference: https://www.gtin.info/
*/

import assertString from './util/assertString';

/**
* Define EAN Lenghts; 8 for EAN-8; 13 for EAN-13
* and Regular Expression for valid EANs (EAN-8, EAN-13),
* with exact numberic matching of 8 or 13 digits [0-9]
* Define EAN Lenghts; 8 for EAN-8; 13 for EAN-13; 14 for EAN-14
* and Regular Expression for valid EANs (EAN-8, EAN-13, EAN-14),
* with exact numberic matching of 8 or 13 or 14 digits [0-9]
*/
const LENGTH_EAN_8 = 8;
const validEanRegex = /^(\d{8}|\d{13})$/;
const LENGTH_EAN_14 = 14;
const validEanRegex = /^(\d{8}|\d{13}|\d{14})$/;


/**
Expand All @@ -28,7 +33,7 @@ const validEanRegex = /^(\d{8}|\d{13})$/;
* @return {number}
*/
function getPositionWeightThroughLengthAndIndex(length, index) {
if (length === LENGTH_EAN_8) {
if (length === LENGTH_EAN_8 || length === LENGTH_EAN_14) {
return (index % 2 === 0) ? 3 : 1;
}

Expand Down Expand Up @@ -56,7 +61,7 @@ function calculateCheckDigit(ean) {

/**
* Check if string is valid EAN:
* Matches EAN-8/EAN-13 regex
* Matches EAN-8/EAN-13/EAN-14 regex
* Has valid check digit.
*
* @param {string} str
Expand Down
13 changes: 13 additions & 0 deletions src/lib/isIdentityCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ const validators = {
}
return sum % 10 === 0;
},
'ar-LY': (str) => {
// Libya National Identity Number NIN is 12 digits, the first digit is either 1 or 2
const NIN = /^(1|2)\d{11}$/;

// sanitize user input
const sanitized = str.trim();

// validate the data structure
if (!NIN.test(sanitized)) {
return false;
}
return true;
},
'ar-TN': (str) => {
const DNI = /^\d{8}$/;

Expand Down
17 changes: 8 additions & 9 deletions src/lib/isMACAddress.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import assertString from './util/assertString';

const macAddress = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/;
const macAddressNoColons = /^([0-9a-fA-F]){12}$/;
const macAddressWithHyphen = /^([0-9a-fA-F][0-9a-fA-F]-){5}([0-9a-fA-F][0-9a-fA-F])$/;
const macAddressWithSpaces = /^([0-9a-fA-F][0-9a-fA-F]\s){5}([0-9a-fA-F][0-9a-fA-F])$/;
const macAddressWithDots = /^([0-9a-fA-F]{4}).([0-9a-fA-F]{4}).([0-9a-fA-F]{4})$/;
const macAddress = /^(?:[0-9a-fA-F]{2}([-:\s]))([0-9a-fA-F]{2}\1){4}([0-9a-fA-F]{2})$/;
const macAddressNoSeparators = /^([0-9a-fA-F]){12}$/;
const macAddressWithDots = /^([0-9a-fA-F]{4}\.){2}([0-9a-fA-F]{4})$/;

export default function isMACAddress(str, options) {
assertString(str);
if (options && options.no_colons) {
return macAddressNoColons.test(str);
/**
* @deprecated `no_colons` TODO: remove it in the next major
*/
if (options && (options.no_colons || options.no_separators)) {
return macAddressNoSeparators.test(str);
}

return macAddress.test(str)
|| macAddressWithHyphen.test(str)
|| macAddressWithSpaces.test(str)
|| macAddressWithDots.test(str);
}
1 change: 1 addition & 0 deletions src/lib/isPassportNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const passportRegexByCountryCode = {
LT: /^[A-Z0-9]{8}$/, // LITHUANIA
LU: /^[A-Z0-9]{8}$/, // LUXEMBURG
LV: /^[A-Z0-9]{2}\d{7}$/, // LATVIA
LY: /^[A-Z0-9]{8}$/, // LIBYA
MT: /^\d{7}$/, // MALTA
NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/, // NETHERLANDS
PO: /^[A-Z]{2}\d{7}$/, // POLAND
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isSlug.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assertString from './util/assertString';

let charsetRegex = /^[^\s-_](?!.*?[-_]{2,})([a-z0-9-\\]{1,})[^\s]*[^-_\s]$/;
let charsetRegex = /^[^\s-_](?!.*?[-_]{2,})[a-z0-9-\\][^\s]*[^-_\s]$/;

export default function isSlug(str) {
assertString(str);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isStrongPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import assertString from './util/assertString';
const upperCaseRegex = /^[A-Z]$/;
const lowerCaseRegex = /^[a-z]$/;
const numberRegex = /^[0-9]$/;
const symbolRegex = /^[-#!$%^&*()_+|~=`{}\[\]:";'<>?,.\/ ]$/;
const symbolRegex = /^[-#!$@%^&*()_+|~=`{}\[\]:";'<>?,.\/ ]$/;

const defaultOptions = {
minLength: 8,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/rtrim.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import assertString from './util/assertString';
export default function rtrim(str, chars) {
assertString(str);
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
const pattern = chars ? new RegExp(`[${chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}]+$`, 'g') : /\s+$/g;
const pattern = chars ? new RegExp(`[${chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}]+$`, 'g') : /(\s)+$/g;
return str.replace(pattern, '');
}
Loading

0 comments on commit ec435d5

Please sign in to comment.