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

doi-utils

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

doi-utils - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

22

dist/cjs/index.js

@@ -5,5 +5,7 @@ "use strict";

});
exports.validatePart = validatePart;
exports.validate = validate;
exports.normalize = normalize;
exports.buildUrl = buildUrl;
exports.default = void 0;
const DOI_VALIDATION_PATTERN = /^10.\d{4,9}\/[-._;()/:A-Z0-9]+$/i; // source: https://www.crossref.org/blog/dois-and-matching-regular-expressions/

@@ -15,12 +17,17 @@ // const DOI_URL_PATTERN = /(?:https?:\/\/)?(?:dx\.)?(?:www\.)?doi.org\//;

};
function validate(possibleDOI) {
function validatePart(possibleDOI) {
if (!possibleDOI) return false;
return possibleDOI.match(DOI_VALIDATION_PATTERN) !== null;
}
function validate(possibleDOI) {
if (!possibleDOI) return false;
return !!normalize(possibleDOI);
}
function normalize(possibleDOI) {
let doi = undefined;
if (validate(possibleDOI)) return possibleDOI;
if (!possibleDOI) return undefined;
if (validatePart(possibleDOI)) return possibleDOI;
if (possibleDOI.startsWith('doi:')) {
doi = possibleDOI.slice(4);
if (validate(doi)) return doi;
if (validatePart(doi)) return doi;
}

@@ -45,3 +52,3 @@ try {

}
if (validate(doi)) return doi;
if (validatePart(doi)) return doi;
return undefined;

@@ -54,3 +61,10 @@ }

}
var _default = {
validatePart,
validate,
normalize,
buildUrl
};
exports.default = _default;
//# sourceMappingURL=index.js.map

22

dist/cjs/index.spec.js

@@ -7,2 +7,6 @@ "use strict";

});
test('empty is not a validPart', ()=>{
expect((0, _index).validatePart()).toBe(false);
expect((0, _index).validatePart('')).toBe(false);
});
test('empty is not valid', ()=>{

@@ -12,9 +16,17 @@ expect((0, _index).validate()).toBe(false);

});
test.each([
'https://doi.org/10.1371/journal.pclm.0000068',
'doi:10.1234/56789',
'10.1234/56789',
'doi.org/10.1371/journal.pclm.0000068',
])('Validate works for %p', (valid)=>{
expect((0, _index).validate(valid)).toBe(true);
});
// can expand on here if needed
test.each([
[
':10.1234/56789a'
]
])('should not validate when it is %p', (invalid)=>{
expect((0, _index).validate(invalid)).toBe(false);
'https://doi.org/10.1371/journal.pclm.0000068',
':10.1234/56789a',
'doi:10.1234/56789',
])('should not validatePart when it is %p', (invalid)=>{
expect((0, _index).validatePart(invalid)).toBe(false);
});

@@ -21,0 +33,0 @@ });

@@ -8,2 +8,13 @@ const DOI_VALIDATION_PATTERN = /^10.\d{4,9}\/[-._;()/:A-Z0-9]+$/i; // source: https://www.crossref.org/blog/dois-and-matching-regular-expressions/

/**
* Validate that the input DOI string is valid.
*
* Uses DOI pattern described here: https://www.crossref.org/blog/dois-and-matching-regular-expressions/
*
* @param possibleDOI
* @returns true if DOI is valid
*/ export function validatePart(possibleDOI) {
if (!possibleDOI) return false;
return possibleDOI.match(DOI_VALIDATION_PATTERN) !== null;
}
/**
* Validate that the input string is valid.

@@ -17,3 +28,3 @@ *

if (!possibleDOI) return false;
return possibleDOI.match(DOI_VALIDATION_PATTERN) !== null;
return !!normalize(possibleDOI);
}

@@ -27,6 +38,7 @@ /**

let doi = undefined;
if (validate(possibleDOI)) return possibleDOI;
if (!possibleDOI) return undefined;
if (validatePart(possibleDOI)) return possibleDOI;
if (possibleDOI.startsWith('doi:')) {
doi = possibleDOI.slice(4);
if (validate(doi)) return doi;
if (validatePart(doi)) return doi;
}

@@ -51,3 +63,3 @@ try {

}
if (validate(doi)) return doi;
if (validatePart(doi)) return doi;
return undefined;

@@ -65,3 +77,9 @@ }

}
export default {
validatePart,
validate,
normalize,
buildUrl
};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import { validate, buildUrl, normalize } from './index';
import { validate, buildUrl, normalize, validatePart } from './index';
describe('validate', ()=>{

@@ -6,2 +6,6 @@ test('should return true if doi is correct', ()=>{

});
test('empty is not a validPart', ()=>{
expect(validatePart()).toBe(false);
expect(validatePart('')).toBe(false);
});
test('empty is not valid', ()=>{

@@ -11,9 +15,17 @@ expect(validate()).toBe(false);

});
test.each([
'https://doi.org/10.1371/journal.pclm.0000068',
'doi:10.1234/56789',
'10.1234/56789',
'doi.org/10.1371/journal.pclm.0000068',
])('Validate works for %p', (valid)=>{
expect(validate(valid)).toBe(true);
});
// can expand on here if needed
test.each([
[
':10.1234/56789a'
]
])('should not validate when it is %p', (invalid)=>{
expect(validate(invalid)).toBe(false);
'https://doi.org/10.1371/journal.pclm.0000068',
':10.1234/56789a',
'doi:10.1234/56789',
])('should not validatePart when it is %p', (invalid)=>{
expect(validatePart(invalid)).toBe(false);
});

@@ -20,0 +32,0 @@ });

/**
* Validate that the input DOI string is valid.
*
* Uses DOI pattern described here: https://www.crossref.org/blog/dois-and-matching-regular-expressions/
*
* @param possibleDOI
* @returns true if DOI is valid
*/
export declare function validatePart(possibleDOI?: string): boolean;
/**
* Validate that the input string is valid.

@@ -24,1 +33,8 @@ *

export declare function buildUrl(possibleDOI: string): string | undefined;
declare const _default: {
validatePart: typeof validatePart;
validate: typeof validate;
normalize: typeof normalize;
buildUrl: typeof buildUrl;
};
export default _default;
{
"name": "doi-utils",
"version": "1.0.4",
"version": "1.0.5",
"description": "Set of utility functions to help with handling DOI(Digital Object Identifier)",

@@ -5,0 +5,0 @@ "author": "Curvenote Inc. <support@curvenote.com>",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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