From 13d505cbc12f307f780fff9e242b82ef2b3e0672 Mon Sep 17 00:00:00 2001 From: rlx Date: Sat, 16 Jan 2016 20:28:43 +0530 Subject: [PATCH] add dashes option to Ox.formatISBN --- source/Ox/js/Format.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/source/Ox/js/Format.js b/source/Ox/js/Format.js index d151dc1a..b04fb507 100644 --- a/source/Ox/js/Format.js +++ b/source/Ox/js/Format.js @@ -644,12 +644,12 @@ Ox.formatISBN Formats a string as an ISBN of a given length (10 or 13) (isbn, length) -> ISBN isbn ISBN length 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; }; /*@