-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
Also updated README.md
- Loading branch information
Showing
14 changed files
with
2,955 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = isISSN; | ||
|
||
var _assertString = require('./util/assertString'); | ||
|
||
var _assertString2 = _interopRequireDefault(_assertString); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
var issn = '^\\d{4}-?\\d{3}[\\dX]$'; | ||
|
||
function isISSN(str) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
|
||
(0, _assertString2.default)(str); | ||
var testIssn = issn; | ||
testIssn = options.require_hyphen ? testIssn.replace('?', '') : testIssn; | ||
testIssn = options.case_sensitive ? new RegExp(testIssn) : new RegExp(testIssn, 'i'); | ||
if (!testIssn.test(str)) { | ||
return false; | ||
} | ||
var issnDigits = str.replace('-', ''); | ||
var position = 8; | ||
var checksum = 0; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
|
||
try { | ||
for (var _iterator = issnDigits[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var digit = _step.value; | ||
|
||
var digitValue = digit.toUpperCase() === 'X' ? 10 : +digit; | ||
checksum += digitValue * position; | ||
--position; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
|
||
return checksum % 11 === 0; | ||
} | ||
module.exports = exports['default']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import assertString from './util/assertString'; | ||
|
||
const issn = '^\\d{4}-?\\d{3}[\\dX]$'; | ||
|
||
export default function isISSN(str, options = {}) { | ||
assertString(str); | ||
let testIssn = issn; | ||
testIssn = options.require_hyphen ? testIssn.replace('?', '') : testIssn; | ||
testIssn = options.case_sensitive ? new RegExp(testIssn) : new RegExp(testIssn, 'i'); | ||
if (!testIssn.test(str)) { | ||
return false; | ||
} | ||
const issnDigits = str.replace('-', ''); | ||
let position = 8; | ||
let checksum = 0; | ||
for (const digit of issnDigits) { | ||
const digitValue = digit.toUpperCase() === 'X' ? 10 : +digit; | ||
checksum += digitValue * position; | ||
--position; | ||
} | ||
return checksum % 11 === 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,6 +244,7 @@ describe('Sanitizers', function () { | |
'[email protected]': false, | ||
'[email protected]': false, | ||
'[email protected]': '[email protected]', | ||
'"foo@bar"@baz.com': '"foo@bar"@baz.com', | ||
}, | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.