Comparing version 1.0.0-master-52557781f15ce177e9d2e2f51fdb8740cc23bb61 to 1.0.0-master-cf4a133e5f972dd142c46fa484a6c14d946e365d
@@ -11,2 +11,2 @@ # Changelog | ||
- First release! Provide a DOM tree, receive an array (potentially empty) of DOIs listed on the page | ||
- First release! Provide a DOM tree, receive an array (potentially empty) of DOIs listed on the page. Supports generic Dublin Core, Highwire Press tags, Eprints tags and BE Press tags. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("./polyfills"); | ||
var identifierAttributes = ['dc.identifier', 'citation_doi', 'dc.relation']; | ||
var identifierAttributes = [ | ||
'dc.identifier', | ||
'citation_doi', | ||
'dc.relation', | ||
'eprints.id_number', | ||
'eprints.official_url', | ||
'bepress_citation_doi', | ||
]; | ||
function parseDoi(identifier) { | ||
var withoutScheme = identifier.replace(/^(info:)?doi:/, ''); | ||
var withoutScheme = identifier.replace(/^((info:)?doi:)|(https?:\/\/(dx\.)?doi.org\/)/, ''); | ||
// A DOI is `10.`, followed by a number of digits, then a slash, and then any number of characters | ||
@@ -8,0 +15,0 @@ return /^10\.\d+\/.*$/.test(withoutScheme) ? withoutScheme : null; |
@@ -111,1 +111,87 @@ "use strict"; | ||
}); | ||
describe('Detecting DOIs located in eprints.id_number meta tags', function () { | ||
it('should not return identifiers that are not DOIs', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"eprints.id_number\" content=\"https://osf.io/khbvy/\">\n </head><p>No DOIs here!</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual([]); | ||
}); | ||
it('should return a naked DOI', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"eprints.id_number\" content=\"10.31219/osf.io/khbvy\">\n </head><p>Hello there</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('should return a DOI prefixed with `doi:`', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"eprints.id_number\" content=\"doi:10.31219/osf.io/khbvy\">\n </head><p>Hello there</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('should return a DOI prefixed with `info:doi:`', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"eprints.id_number\" content=\"info:doi:10.31219/osf.io/khbvy\">\n </head><p>Hello there</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('should return multiple DOIs when present', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"eprints.id_number\" content=\"info:doi:10.31219/osf.io/khbvy\">\n <meta name=\"eprints.id_number\" content=\"10.1371/journal.pbio.1002456\">\n </head><p>Hello there</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual(['10.31219/osf.io/khbvy', '10.1371/journal.pbio.1002456']); | ||
}); | ||
}); | ||
describe('Detecting DOIs located in eprints.official_url meta tags', function () { | ||
it('should not return identifiers that are not DOIs', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"eprints.official_url\" content=\"http://eprints.bbk.ac.uk/19432/\">\n </head><p>No DOIs here!</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual([]); | ||
}); | ||
it('should return a naked DOI', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"eprints.official_url\" content=\"10.31219/osf.io/khbvy\">\n </head><p>Hello there</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('should return a DOI prefixed with `https://doi.org/`', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"eprints.official_url\" content=\"https://doi.org/10.3138/jsp.49.1.26\">\n </head><p>Hello there</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual(['10.3138/jsp.49.1.26']); | ||
}); | ||
it('should return a DOI prefixed with `http://doi.org/`', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"eprints.official_url\" content=\"http://doi.org/10.3138/jsp.49.1.26\">\n </head><p>Hello there</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual(['10.3138/jsp.49.1.26']); | ||
}); | ||
it('should return a DOI prefixed with `https://dx.doi.org/`', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"eprints.official_url\" content=\"https://dx.doi.org/10.3138/jsp.49.1.26\">\n </head><p>Hello there</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual(['10.3138/jsp.49.1.26']); | ||
}); | ||
it('should return a DOI prefixed with `http://dx.doi.org/`', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"eprints.official_url\" content=\"http://dx.doi.org/10.3138/jsp.49.1.26\">\n </head><p>Hello there</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual(['10.3138/jsp.49.1.26']); | ||
}); | ||
}); | ||
describe('Detecting DOIs located in bepress_citation_doi meta tags', function () { | ||
it('should not return identifiers that are not DOIs', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"bepress_citation_doi\" content=\"https://osf.io/khbvy/\">\n </head><p>No DOIs here!</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual([]); | ||
}); | ||
it('should return a naked DOI', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"bepress_citation_doi\" content=\"10.31219/osf.io/khbvy\">\n </head><p>Hello there</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('should return a DOI prefixed with `doi:`', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"bepress_citation_doi\" content=\"doi:10.31219/osf.io/khbvy\">\n </head><p>Hello there</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('should return a DOI prefixed with `info:doi:`', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"bepress_citation_doi\" content=\"info:doi:10.31219/osf.io/khbvy\">\n </head><p>Hello there</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('should return multiple DOIs when present', function () { | ||
var dom = new jsdom_1.JSDOM("<!DOCTYPE html><html><head>\n <meta name=\"bepress_citation_doi\" content=\"info:doi:10.31219/osf.io/khbvy\">\n <meta name=\"bepress_citation_doi\" content=\"10.1371/journal.pbio.1002456\">\n </head><p>Hello there</p></html>"); | ||
var document = dom.window.document; | ||
expect(index_1.getDois(document)).toEqual(['10.31219/osf.io/khbvy', '10.1371/journal.pbio.1002456']); | ||
}); | ||
}); |
@@ -173,3 +173,2 @@ import { JSDOM } from 'jsdom'; | ||
describe('Detecting DOIs located in dc.relation meta tags', () => { | ||
@@ -233,1 +232,184 @@ it('should not return identifiers that are not DOIs', () => { | ||
describe('Detecting DOIs located in eprints.id_number meta tags', () => { | ||
it('should not return identifiers that are not DOIs', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="eprints.id_number" content="https://osf.io/khbvy/"> | ||
</head><p>No DOIs here!</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual([]); | ||
}); | ||
it('should return a naked DOI', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="eprints.id_number" content="10.31219/osf.io/khbvy"> | ||
</head><p>Hello there</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('should return a DOI prefixed with `doi:`', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="eprints.id_number" content="doi:10.31219/osf.io/khbvy"> | ||
</head><p>Hello there</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('should return a DOI prefixed with `info:doi:`', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="eprints.id_number" content="info:doi:10.31219/osf.io/khbvy"> | ||
</head><p>Hello there</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('should return multiple DOIs when present', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="eprints.id_number" content="info:doi:10.31219/osf.io/khbvy"> | ||
<meta name="eprints.id_number" content="10.1371/journal.pbio.1002456"> | ||
</head><p>Hello there</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual(['10.31219/osf.io/khbvy', '10.1371/journal.pbio.1002456']); | ||
}); | ||
}); | ||
describe('Detecting DOIs located in eprints.official_url meta tags', () => { | ||
it('should not return identifiers that are not DOIs', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="eprints.official_url" content="http://eprints.bbk.ac.uk/19432/"> | ||
</head><p>No DOIs here!</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual([]); | ||
}); | ||
it('should return a naked DOI', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="eprints.official_url" content="10.31219/osf.io/khbvy"> | ||
</head><p>Hello there</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('should return a DOI prefixed with `https://doi.org/`', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="eprints.official_url" content="https://doi.org/10.3138/jsp.49.1.26"> | ||
</head><p>Hello there</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual(['10.3138/jsp.49.1.26']); | ||
}); | ||
it('should return a DOI prefixed with `http://doi.org/`', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="eprints.official_url" content="http://doi.org/10.3138/jsp.49.1.26"> | ||
</head><p>Hello there</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual(['10.3138/jsp.49.1.26']); | ||
}); | ||
it('should return a DOI prefixed with `https://dx.doi.org/`', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="eprints.official_url" content="https://dx.doi.org/10.3138/jsp.49.1.26"> | ||
</head><p>Hello there</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual(['10.3138/jsp.49.1.26']); | ||
}); | ||
it('should return a DOI prefixed with `http://dx.doi.org/`', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="eprints.official_url" content="http://dx.doi.org/10.3138/jsp.49.1.26"> | ||
</head><p>Hello there</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual(['10.3138/jsp.49.1.26']); | ||
}); | ||
}); | ||
describe('Detecting DOIs located in bepress_citation_doi meta tags', () => { | ||
it('should not return identifiers that are not DOIs', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="bepress_citation_doi" content="https://osf.io/khbvy/"> | ||
</head><p>No DOIs here!</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual([]); | ||
}); | ||
it('should return a naked DOI', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="bepress_citation_doi" content="10.31219/osf.io/khbvy"> | ||
</head><p>Hello there</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('should return a DOI prefixed with `doi:`', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="bepress_citation_doi" content="doi:10.31219/osf.io/khbvy"> | ||
</head><p>Hello there</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('should return a DOI prefixed with `info:doi:`', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="bepress_citation_doi" content="info:doi:10.31219/osf.io/khbvy"> | ||
</head><p>Hello there</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual(['10.31219/osf.io/khbvy']); | ||
}); | ||
it('should return multiple DOIs when present', () => { | ||
const dom = new JSDOM( | ||
`<!DOCTYPE html><html><head> | ||
<meta name="bepress_citation_doi" content="info:doi:10.31219/osf.io/khbvy"> | ||
<meta name="bepress_citation_doi" content="10.1371/journal.pbio.1002456"> | ||
</head><p>Hello there</p></html>` | ||
); | ||
const document = dom.window.document; | ||
expect(getDois(document)).toEqual(['10.31219/osf.io/khbvy', '10.1371/journal.pbio.1002456']); | ||
}); | ||
}); |
11
index.ts
import './polyfills'; | ||
const identifierAttributes = [ 'dc.identifier', 'citation_doi', 'dc.relation' ]; | ||
const identifierAttributes = [ | ||
'dc.identifier', | ||
'citation_doi', | ||
'dc.relation', | ||
'eprints.id_number', | ||
'eprints.official_url', | ||
'bepress_citation_doi', | ||
]; | ||
function parseDoi(identifier: string): string | null { | ||
const withoutScheme = identifier.replace(/^(info:)?doi:/, ''); | ||
const withoutScheme = identifier.replace(/^((info:)?doi:)|(https?:\/\/(dx\.)?doi.org\/)/, ''); | ||
@@ -8,0 +15,0 @@ // A DOI is `10.`, followed by a number of digits, then a slash, and then any number of characters |
{ | ||
"name": "get-dois", | ||
"version": "1.0.0-master-52557781f15ce177e9d2e2f51fdb8740cc23bb61", | ||
"version": "1.0.0-master-cf4a133e5f972dd142c46fa484a6c14d946e365d", | ||
"description": "Detect Digital Object Identifiers listed in the metadata of a DOM tree", | ||
@@ -13,3 +13,8 @@ "scripts": { | ||
"digital-object-identifier", | ||
"dom" | ||
"dom", | ||
"dublin-core", | ||
"dc", | ||
"highwire", | ||
"eprints", | ||
"bepress" | ||
], | ||
@@ -16,0 +21,0 @@ "homepage": "https://gitlab.com/Flockademic/get-dois", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
199945
820