UNPKG

publication-ids

Version:

Javascript / Typescript validator and parse for publication ids; DOI, PMID, PMCID, ISBN, and ISSN

150 lines (130 loc) 3.43 kB
# publication-ids Javascript / Typescript validator and parse for publication ids; DOI, PMID, PMCID, ISBN, and ISSN. Allows for validation of publication ids and parsing of publication ids from text. ## Installation ```bash npm install publication-ids ``` ## Usage #### CLI You can use the CLI to parse publication ids from the command line, this supports DOI, ISBN, ISSN, PubMed ID (PMID) and PubMed Central ID (PMCID). ```bash # DOI npx publication-ids "10.1234/5678" # Output: # [ # { # source: '10.1234/5678', # doi: '10.1234/5678', # isValid: true, # resolve: 'https://doi.org/10.1234/5678', # isbn: { isValid: false } # } # ] # ISBN npx publication-ids "978-3-16-148410-0" # Output: # [ # { # source: '978-3-16-148410-0', # isValid: true, # isbn10: '316148410X', # isbn13: '9783161484100' # } # ] # DOI, which is an ISBN chapter npx publication-ids "10.4324/9780203765449-11" # Output: # [ # { # source: '10.4324/9780203765449-11', # doi: '10.4324/9780203765449', # isValid: true, # resolve: 'https://doi.org/10.4324/9780203765449', # isbn: { # source: '9780203765449', # isValid: true, # isbn10: '0203765443', # isbn13: '9780203765449', # chapter: '11' # } # } # ] ``` #### Codebase ```ts import PublicationIds from 'publication-ids'; // To guess the type of publication id, use the parse function. // Parse will return an **array** of all possible publication ids that can be parsed from the input. // The input can be a string or an array of strings. const ids = PublicationIds.parse('10.1234/5678'); ids.map(id => { console.log(id); /* { source: '10.1234/5678'; isValid: true; doi: '10.1234/5678'; resolve: https://doi.org/10.1234/5678; } */ }); const dois = PublicationIds.parseDoi('10.1234/5678') dois.map(doi => { console.log(doi); /* { source: '10.1234/5678'; isValid: true; doi: '10.1234/5678'; resolve: https://doi.org/10.1234/5678; } */ // Due to the nature of the DOI system, it is not possible to validate a DOI without resolving it. fetch(doi.resolve) .then(response => response.ok) }); const isbns = PublicationIds.parseIsbn('978-3-16-148410-0'); isbns.map(isbn => { console.log(isbn); /* { source: '978-3-16-148410-0', isValid: true, isbn10: '3161484100', isbn13: '9783161484100', } */ // ISBNs can be validated without resolving them, due to a checksum in the ISBN. }); const issns = PublicationIds.parseIssn('0378-5955'); issns.map(issn => { console.log(issn); /* { source: '0378-5955', isValid: true, issn: '03785955', } */ // ISSNs can be validated without resolving them, due to a checksum in the ISBN. }); // PMIDs and PMCIDs can be parsed using the same function. const pmids = PublicationIds.parsePmid('PMC123456') pmids.map(pmid => { console.log(pmid); /* { source: 'PMC123456'; isValid: true; pmid: 'PMC123456'; resolve: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC123456/; } */ // Due to the nature of the PMID & PMCID system, it is not possible to validate a DOI without resolving it. fetch(doi.resolve) .then(response => response.ok) }); ``` ## Contributing Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.