update formatISBN

This commit is contained in:
rlx 2016-01-11 15:15:12 +05:30
parent 598e676458
commit 8a96a0a095

View file

@ -662,13 +662,16 @@ Ox.formatISBN = function(isbn, length) {
) % mod + '').replace('10', 'X');
}
isbn = isbn.toUpperCase().replace(/[^\dX]/g, '');
if ((
(isbn.length == 10 && isbn.slice(0, -1).indexOf('X') == -1)
|| (isbn.length == 13 && isbn.slice(0, 3) == '978')
) && isbn.slice(-1) == getCheckDigit(isbn)) {
if (isbn.length == 10) {
isbn = isbn.slice(0, -1).replace(/\D/g, '') + isbn.slice(-1);
}
if (
(isbn.length == 10 || isbn.length == 13)
&& isbn.slice(-1) == getCheckDigit(isbn)
) {
if (isbn.length == length) {
ret = isbn
} else {
} else if (isbn.length == 10 || isbn.slice(0, 3) == '978') {
isbn = isbn.length == 10 ? '978' + isbn : isbn.slice(3);
ret = isbn.slice(0, -1) + getCheckDigit(isbn);
}