Skip to content

Commit

Permalink
Merge pull request #660 from avimak/master
Browse files Browse the repository at this point in the history
Added validation for ISRC strings
  • Loading branch information
chriso authored Jun 22, 2017
2 parents e3518ce + 851517a commit e05149f
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 1 deletion.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ var _isHexColor = require('./lib/isHexColor');

var _isHexColor2 = _interopRequireDefault(_isHexColor);

var _isISRC = require('./lib/isISRC');

var _isISRC2 = _interopRequireDefault(_isISRC);

var _isMD = require('./lib/isMD5');

var _isMD2 = _interopRequireDefault(_isMD);
Expand Down Expand Up @@ -280,6 +284,7 @@ var validator = {
isHexadecimal: _isHexadecimal2.default,
isDivisibleBy: _isDivisibleBy2.default,
isHexColor: _isHexColor2.default,
isISRC: _isISRC2.default,
isMD5: _isMD2.default,
isJSON: _isJSON2.default,
isEmpty: _isEmpty2.default,
Expand Down
21 changes: 21 additions & 0 deletions lib/isISRC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isISRC;

var _assertString = require('./util/assertString');

var _assertString2 = _interopRequireDefault(_assertString);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// see http://isrc.ifpi.org/en/isrc-standard/code-syntax
var isrc = /^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;

function isISRC(str) {
(0, _assertString2.default)(str);
return isrc.test(str);
}
module.exports = exports['default'];
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import isDivisibleBy from './lib/isDivisibleBy';

import isHexColor from './lib/isHexColor';

import isISRC from './lib/isISRC';

import isMD5 from './lib/isMD5';

import isJSON from './lib/isJSON';
Expand Down Expand Up @@ -114,6 +116,7 @@ const validator = {
isHexadecimal,
isDivisibleBy,
isHexColor,
isISRC,
isMD5,
isJSON,
isEmpty,
Expand Down
9 changes: 9 additions & 0 deletions src/lib/isISRC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import assertString from './util/assertString';

// see http://isrc.ifpi.org/en/isrc-standard/code-syntax
const isrc = /^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;

export default function isISRC(str) {
assertString(str);
return isrc.test(str);
}
18 changes: 18 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,24 @@ describe('Validators', function () {
});
});

it('should validate ISRC code strings', function () {
test({
validator: 'isISRC',
valid: [
'USAT29900609',
'GBAYE6800011',
'USRC15705223',
'USCA29500702',
],
invalid: [
'USAT2990060',
'SRC15705223',
'US-CA29500702',
'USARC15705223',
],
});
});

it('should validate md5 strings', function () {
test({
validator: 'isMD5',
Expand Down
9 changes: 9 additions & 0 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,14 @@
return hexcolor.test(str);
}

// see http://isrc.ifpi.org/en/isrc-standard/code-syntax
var isrc = /^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;

function isISRC(str) {
assertString(str);
return isrc.test(str);
}

var md5 = /^[a-f0-9]{32}$/;

function isMD5(str) {
Expand Down Expand Up @@ -1353,6 +1361,7 @@
isHexadecimal: isHexadecimal,
isDivisibleBy: isDivisibleBy,
isHexColor: isHexColor,
isISRC: isISRC,
isMD5: isMD5,
isJSON: isJSON,
isEmpty: isEmpty,
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit e05149f

Please sign in to comment.