New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

get-dois

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-dois - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0-master-3043572058-26599a21

10

CHANGELOG.md

@@ -7,2 +7,12 @@ # Changelog

### New features
- Articles on Open Journal Systems that do not expose a DOI in the metadata can now still be recognised, as long as the document body is passed as well.
## [3.1.0] - 2019-12-09
### New features
- DC.identifier.DOI tags are now supported. In concrete terms, this should mean that more items on Figshare should now be recognised.
## [3.0.0] - 2019-08-17

@@ -9,0 +19,0 @@

@@ -11,2 +11,3 @@ "use strict";

'prism.doi',
'dc.identifier.doi',
];

@@ -34,2 +35,12 @@ function parseDoi(identifier) {

var identifiers = metaTagsWithIdentifier.map(function (tag) { return tag.getAttribute('content'); }).filter(isNotNull);
// Open Journal Systems does not necessarily list the DOI in the <head>,
// but if `domTree` includes the <body>, we can at least try to find the link
// there:
var ojsDoiLink = domTree.querySelector('.pkp_structure_main .doi .value a');
if (ojsDoiLink) {
var ojsDoiLinkHref = ojsDoiLink.getAttribute('href');
if (typeof ojsDoiLinkHref === 'string') {
identifiers.push(ojsDoiLinkHref);
}
}
var dois = identifiers.map(parseDoi).filter(isNotNull);

@@ -36,0 +47,0 @@ var uniqueDois = dois.filter(function (doi, index) { return dois.indexOf(doi) === index; });

@@ -209,2 +209,31 @@ "use strict";

});
// DC.identifier.DOI is used by some Figshare pages. See
// https://gitlab.com/Flockademic/get-dois/issues/7
describe('Detecting DOIs located in DC.identfier.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=\"DC.identifier.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=\"DC.identifier.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=\"DC.identifier.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=\"DC.identifier.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=\"DC.identifier.DOI\" content=\"info:doi:10.31219/osf.io/khbvy\">\n <meta name=\"DC.identifier.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']);
});
});
describe('Detecting DOIs located in meta tags identified by the `property` attribute', function () {

@@ -252,1 +281,17 @@ it('should not return identifiers that are not DOIs', function () {

});
describe('Detecting DOIs located in known elements in the <body>', function () {
it('returns DOIs listed for articles on Open Journal Systems', function () {
var dom = new jsdom_1.JSDOM(
// Stripped DOM from an actual OJS site:
"\n <div class=\"pkp_structure_content has_sidebar\">\n <div class=\"pkp_structure_main\" role=\"main\">\n <a id=\"pkp_content_main\"></a>\n <div class=\"page page_article\">\n <article class=\"obj_article_details\">\n <div class=\"row\">\n <div class=\"main_entry\">\n <section class=\"item doi\">\n <h2 class=\"label\">\n DOI:\n </h2>\n <span class=\"value\">\n <a href=\"https://doi.org/10.31219/osf.io/khbvy\">\n https://doi.org/10.31219/osf.io/khbvy\n </a>\n </span>\n </section>\n </div><!-- .main_entry -->\n <!-- .entry_details -->\n </div><!-- .row -->\n </article>\n </div><!-- .page -->\n </div><!-- pkp_structure_main -->\n </div>\n ");
var document = dom.window.document;
expect(index_1.getDois(document)).toEqual(['10.31219/osf.io/khbvy']);
});
it('does not return a DOI for articles on Open Journal Systems with invalid HTML', function () {
var dom = new jsdom_1.JSDOM(
// Stripped DOM from an actual OJS site:
"\n <div class=\"pkp_structure_content has_sidebar\">\n <div class=\"pkp_structure_main\" role=\"main\">\n <a id=\"pkp_content_main\"></a>\n <div class=\"page page_article\">\n <article class=\"obj_article_details\">\n <div class=\"row\">\n <div class=\"main_entry\">\n <section class=\"item doi\">\n <h2 class=\"label\">\n DOI:\n </h2>\n <span class=\"value\">\n <a data-comment=\"href attribute missing\">\n https://doi.org/10.31219/osf.io/khbvy\n </a>\n </span>\n </section>\n </div><!-- .main_entry -->\n <!-- .entry_details -->\n </div><!-- .row -->\n </article>\n </div><!-- .page -->\n </div><!-- pkp_structure_main -->\n </div>\n ");
var document = dom.window.document;
expect(index_1.getDois(document)).toEqual([]);
});
});

@@ -439,2 +439,62 @@ import { JSDOM } from 'jsdom';

// DC.identifier.DOI is used by some Figshare pages. See
// https://gitlab.com/Flockademic/get-dois/issues/7
describe('Detecting DOIs located in DC.identfier.DOI meta tags', () => {
it('should not return identifiers that are not DOIs', () => {
const dom = new JSDOM(
`<!DOCTYPE html><html><head>
<meta name="DC.identifier.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="DC.identifier.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="DC.identifier.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="DC.identifier.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="DC.identifier.DOI" content="info:doi:10.31219/osf.io/khbvy">
<meta name="DC.identifier.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']);
});
});
describe('Detecting DOIs located in meta tags identified by the `property` attribute', () => {

@@ -531,1 +591,73 @@ it('should not return identifiers that are not DOIs', () => {

});
describe('Detecting DOIs located in known elements in the <body>', () => {
it('returns DOIs listed for articles on Open Journal Systems', () => {
const dom = new JSDOM(
// Stripped DOM from an actual OJS site:
`
<div class="pkp_structure_content has_sidebar">
<div class="pkp_structure_main" role="main">
<a id="pkp_content_main"></a>
<div class="page page_article">
<article class="obj_article_details">
<div class="row">
<div class="main_entry">
<section class="item doi">
<h2 class="label">
DOI:
</h2>
<span class="value">
<a href="https://doi.org/10.31219/osf.io/khbvy">
https://doi.org/10.31219/osf.io/khbvy
</a>
</span>
</section>
</div><!-- .main_entry -->
<!-- .entry_details -->
</div><!-- .row -->
</article>
</div><!-- .page -->
</div><!-- pkp_structure_main -->
</div>
`
);
const document = dom.window.document;
expect(getDois(document)).toEqual(['10.31219/osf.io/khbvy']);
});
it('does not return a DOI for articles on Open Journal Systems with invalid HTML', () => {
const dom = new JSDOM(
// Stripped DOM from an actual OJS site:
`
<div class="pkp_structure_content has_sidebar">
<div class="pkp_structure_main" role="main">
<a id="pkp_content_main"></a>
<div class="page page_article">
<article class="obj_article_details">
<div class="row">
<div class="main_entry">
<section class="item doi">
<h2 class="label">
DOI:
</h2>
<span class="value">
<a data-comment="href attribute missing">
https://doi.org/10.31219/osf.io/khbvy
</a>
</span>
</section>
</div><!-- .main_entry -->
<!-- .entry_details -->
</div><!-- .row -->
</article>
</div><!-- .page -->
</div><!-- pkp_structure_main -->
</div>
`
);
const document = dom.window.document;
expect(getDois(document)).toEqual([]);
});
});

@@ -10,2 +10,3 @@ import './polyfills';

'prism.doi',
'dc.identifier.doi',
];

@@ -39,2 +40,14 @@

const identifiers = metaTagsWithIdentifier.map(tag => tag.getAttribute('content')).filter(isNotNull);
// Open Journal Systems does not necessarily list the DOI in the <head>,
// but if `domTree` includes the <body>, we can at least try to find the link
// there:
const ojsDoiLink = domTree.querySelector('.pkp_structure_main .doi .value a');
if (ojsDoiLink) {
const ojsDoiLinkHref = ojsDoiLink.getAttribute('href');
if (typeof ojsDoiLinkHref === 'string') {
identifiers.push(ojsDoiLinkHref);
}
}
const dois = identifiers.map(parseDoi).filter(isNotNull);

@@ -41,0 +54,0 @@ const uniqueDois = dois.filter((doi, index) => dois.indexOf(doi) === index);

8

package.json
{
"name": "get-dois",
"version": "3.0.0",
"version": "3.1.0-master-3043572058-26599a21",
"description": "Detect Digital Object Identifiers listed in the metadata of a DOM tree",

@@ -40,3 +40,7 @@ "scripts": {

"dependencies": {},
"peerDependencies": {}
"peerDependencies": {},
"volta": {
"node": "10.24.1",
"yarn": "1.22.19"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc