add dashes option to Ox.formatISBN
This commit is contained in:
parent
cec3e63880
commit
13d505cbc1
1 changed files with 10 additions and 4 deletions
|
@ -644,12 +644,12 @@ Ox.formatISBN <f> Formats a string as an ISBN of a given length (10 or 13)
|
|||
(isbn, length) -> <s> ISBN
|
||||
isbn <s> ISBN
|
||||
length <n> length (10 or 13)
|
||||
> Ox.formatISBN('0-306-40615-2', 13)
|
||||
'9780306406157'
|
||||
> Ox.formatISBN('0-306-40615-2', 13, true)
|
||||
'978-0-306-40615-7'
|
||||
> Ox.formatISBN('978-0-306-40615-7', 10)
|
||||
'0306406152'
|
||||
@*/
|
||||
Ox.formatISBN = function(isbn, length) {
|
||||
Ox.formatISBN = function(isbn, length, dashes) {
|
||||
var ret = '';
|
||||
function getCheckDigit(isbn) {
|
||||
var mod = isbn.length == 10 ? 11 : 10
|
||||
|
@ -676,7 +676,13 @@ Ox.formatISBN = function(isbn, length) {
|
|||
ret = isbn.slice(0, -1) + getCheckDigit(isbn);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return dashes ? [
|
||||
ret.slice(-13, -10),
|
||||
ret.slice(-10, -9),
|
||||
ret.slice(-9, -6),
|
||||
ret.slice(-6, -1),
|
||||
ret.slice(-1)
|
||||
].join('-').replace(/^-/, '') : ret;
|
||||
};
|
||||
|
||||
/*@
|
||||
|
|
Loading…
Reference in a new issue