A modification to https://gist.github.com/aurimasv/6693503 to output ISBN ranges for consumption by https://github.com/coolaj86/isbnjs. The range XML data can be generated from https://www.isbn-international.org/range_file_generation.
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
/* | |
***** BEGIN LICENSE BLOCK ***** | |
Generates ISBN registrant tables given XML Range Message | |
(from http://www.isbn-international.org/page/ranges) loaded in the browser | |
Copyright © 2013 Aurimas Vinckevicius (aurimas.dev~at~gmail.com) | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU Affero General Public License as | |
published by the Free Software Foundation, either version 3 of the | |
License, or (at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU Affero General Public License for more details. | |
You should have received a copy of the GNU Affero General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | |
***** END LICENSE BLOCK ***** | |
*/ | |
var prefVarName = 'prefs'; | |
var prefs = {}; | |
var same = {}; | |
var groups = document.getElementsByTagName('Group'); | |
for(var i=0, n=groups.length; i<n; i++) { | |
var prefix = groups[i].getElementsByTagName('Prefix')[0].textContent.split('-'); | |
var uccPrefix = prefix[0]; | |
prefix = prefix[1]; | |
var ranges = []; | |
var rules = groups[i].getElementsByTagName('Rule'); | |
for(var j=0, m=rules.length; j<m; j++) { | |
var range = rules[j].getElementsByTagName('Range')[0].textContent.split('-'); | |
var length = rules[j].getElementsByTagName('Length')[0].textContent * 1; | |
ranges.push(range[0].substr(0,length)); | |
ranges.push(range[1].substr(0,length)); | |
} | |
if(ranges.length) { | |
ranges = ranges.sort(function(a, b) { | |
if(a.length == b.length) return a==b?0:(a<b?-1:1); | |
return a.length - b.length; | |
}); | |
var agency = groups[i].getElementsByTagName('Agency')[0].textContent; | |
if(!prefs[uccPrefix]) prefs[uccPrefix] = {}; | |
prefs[uccPrefix][prefix] = {name:agency, ranges:ranges}; | |
} | |
} | |
var parsedGroups = {}; | |
for (var key in prefs['978']) { | |
var tempArray = []; | |
for (i=0,j=prefs['978'][key].ranges.length; i<j; i += 2) { tempArray.push(prefs['978'][key].ranges.slice(i, i+2)); } | |
parsedGroups[key] = {name:prefs['978'][key].name, ranges:tempArray}; | |
} | |
console.log(JSON.stringify(parsedGroups)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment