https://github.com/nothingrandom/publication-ids
Javascript / Typescript validator and parser for publication ids; DOI, PMID, PMCID, ISBN, and ISSN
https://github.com/nothingrandom/publication-ids
bun doi isbn isbn-13 node-module nodejs npm-package publishing typescript
Last synced: about 1 month ago
JSON representation
Javascript / Typescript validator and parser for publication ids; DOI, PMID, PMCID, ISBN, and ISSN
- Host: GitHub
- URL: https://github.com/nothingrandom/publication-ids
- Owner: nothingrandom
- License: mit
- Created: 2025-02-03T21:58:45.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-10-02T12:29:38.000Z (7 months ago)
- Last Synced: 2026-01-19T13:48:35.761Z (3 months ago)
- Topics: bun, doi, isbn, isbn-13, node-module, nodejs, npm-package, publishing, typescript
- Language: TypeScript
- Homepage:
- Size: 84 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.