Skip to content

Commit 99492c2

Browse files
committed
Fix null returns
1 parent 4067803 commit 99492c2

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@ var doi = module.exports = function (opts) {
1212
}
1313

1414
doi.groups = function (str) {
15+
if (!str) { return }
1516
// Javascript fails at lookaheads for optional groups. This circumvents that
1617
// problem by just automatically removing and saving suffixes if they are in
1718
// as specific format - .a000 is the format used by PLoS, but this may need
1819
// to be filled out.
19-
var suffixes = [];
20-
var newStr = str.replace(/\.[a-zA-Z]{1}[0-9]{3}$/g, function(s){
20+
var suffixes = []
21+
var newStr = str.replace(/\.[a-zA-Z]{1}[0-9]{3}$/g, function (s) {
2122
suffixes.push(s)
2223
return ''
2324
})
2425
var match = doi().exec(newStr)
25-
match[0] = str;
26-
match.push((!!suffixes.length) ? suffixes[0] : '')
26+
if (match) {
27+
match[0] = str
28+
match.push((!!suffixes.length) ? suffixes[0] : '')
29+
}
2730
return match
2831
}
2932

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "doi-regex",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "Regular expression for matching DOIs",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)