mvolz / isbn3

ISBN parser

Home Page:http://inventaire.github.io/isbn3/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

isbn3

Node

An ISBN JavaScript Library.

Please note that this is a fork of isbn2, which was a fork of isbn package which was forked from the original isbnjs project on Google Code.

Motivations to fork:

  • modularizing and updating the code for ES6, in a class-less way.
  • improve performance (see [#benchmark])

Demo

Summary

Install

From the command line:

npm install isbn3

Then in your JS file:

const ISBN = require('isbn3')

Alternatively, you can call the ES5 browserified version of the module from an HTML file, which sets the module object on window.ISBN:

<script type="application/javascript" src="./node_modules/dist/isbn.js"></script>

See ./index.html or the live demo for an example.

Functions

parse

ISBN.parse('1-933988-03-7')
// => {
// source: '1-933988-03-7',
// isValid: true,
// isIsbn10: true,
// isIsbn13: false,
// group: '1',
// publisher: '933988',
// article: '03',
// check: '7',
// isbn13: '9781933988030',
// isbn13h: '978-1-933988-03-0',
// check10: '7',
// check13: '0',
// groupname: 'English language',
// isbn10: '1933988037',
// isbn10h: '1-933988-03-7'
// }

ISBN.parse('1933988037')
// => idem but with source === '1933988037'

ISBN.parse('978-4-87311-336-4')
// => {
//   source: '978-4-87311-336-4',
//   isValid: true,
//   isIsbn10: false,
//   isIsbn13: true,
//   prefix: '978',
//   group: '4',
//   publisher: '87311',
//   article: '336',
//   check: '4',
//   isbn13: '9784873113364',
//   isbn13h: '978-4-87311-336-4',
//   check10: '9',
//   check13: '4',
//   groupname: 'Japan',
//   isbn10: '4873113369',
//   isbn10h: '4-87311-336-9'
// }

ISBN.parse('9784873113364')
// => idem but with source === '9784873113364'

ISBN.parse('978-4873113364')
// => idem but with source === '978-4873113364'

ISBN.parse('979-10-96908-02-8')
// {
//   source: '979-10-96908-02-8',
//   isValid: true,
//   isIsbn10: false,
//   isIsbn13: true,
//   prefix: '979',
//   group: '10',
//   publisher: '96908',
//   article: '02',
//   check: '8',
//   isbn13: '9791096908028',
//   isbn13h: '979-10-96908-02-8',
//   check10: '6',
//   check13: '8',
//   groupname: 'France'
// }

ISBN.parse('not an isbn')
// => null

asIsbn13

ISBN.asIsbn13('4-87311-336-9')           // 9784873113364
ISBN.asIsbn13('4-87311-336-9', true)     // 978-4-87311-336-4

asIsbn10

ISBN.asIsbn10('978-4-87311-336-4')       // 4873113369
ISBN.asIsbn10('978-4-87311-336-4', true) // 4-87311-336-9

hyphenate

ISBN.hyphenate('9784873113364')          // 978-4-87311-336-4

groups

ISBN.groups['978-99972']
// => {
//   name: 'Faroe Islands',
//   ranges: [ [ '0', '4' ], [ '50', '89' ], [ '900', '999' ] ]
// }

CLI

Installing the module globally (npm install -g isbn3) will make an isbn command available from your terminal. If you installed locally (npm install isbn3), the command can be accessed from the project directory at ./node_modules/.bin/isbn

So, from the terminal:

isbn <isbn> <format>

Valid ISBN input examples:
- 9781491574317
- 978-1-4915-7431-7
- 978-1491574317
- isbn:9781491574317
- 9781-hello-491574317

Formats:
- h: hyphen
- n: no hyphen
- 13: ISBN-13 without hyphen
- 13h: ISBN-13 with hyphen (default)
- 10: ISBN-10 without hyphen
- 10h: ISBN-10 with hyphen
- prefix, group, publisher, article, check, check10, check13: output ISBN part value
- data: output all this data as JSON

Benchmark

Indicative benchmark, nothing super scientific, YMMV.

Running npm run benchmark a few times on some Linux machine with Node.Js v8.12 produced in average the following mesure:

  • isbn3
  • load module: 6ms
  • parse 4960 non-hyphenated ISBNs in around 110ms
  • load module: 4.5ms
  • parse 4960 non-hyphenated ISBNs in around 285ms

The difference is mainly due to the generation of a map of groups in isbn3, which takes more time a initialization but makes groups lookups much faster.

Development

Test Suite

To run the lint/test suite use:

npm test

Update Groups

To get the latest ISBN groups from [isbn-international.org], use:

npm run get-groups

Results will be saved as a JavaScript object in ./groups.js

About

ISBN parser

http://inventaire.github.io/isbn3/


Languages

Language:JavaScript 96.8%Language:HTML 2.6%Language:Shell 0.6%