-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for ORCID id of creator in Zenodo submission (#238)
- Loading branch information
1 parent
62d6f12
commit eea3faa
Showing
3 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
function generateCheckDigit(noHyphenOrcid) { | ||
// https://support.orcid.org/hc/en-us/articles/360006897674-Structure-of-the-ORCID-Identifier | ||
let total = 0; | ||
let zero = '0'.charCodeAt(0); | ||
for (let i = 0; i < 15; i++) { | ||
let digit = noHyphenOrcid.charCodeAt(i) - zero; | ||
total = (total + digit) * 2; | ||
} | ||
let result = (12 - (total % 11)) % 11; | ||
return result === 10 ? 'X' : String(result); | ||
} | ||
|
||
function okOrcid(orcid) { | ||
// based on https://github.com/zimeon/orcid-feed-js | ||
if (typeof orcid !== 'string') { | ||
return false; | ||
} | ||
let noHyphenOrcid = orcid.replace( | ||
/^(\d{4})-(\d{4})-(\d{4})-(\d\d\d[\dX])$/, | ||
'$1$2$3$4', | ||
); | ||
if (noHyphenOrcid === orcid) { | ||
return false; | ||
} | ||
if (noHyphenOrcid.charAt(15) !== generateCheckDigit(noHyphenOrcid)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
module.exports = okOrcid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
const okORCID = require('../../src/util/orcid'); | ||
|
||
it('test ORCID checksum calculation', () => { | ||
expect(okORCID('0000-0003-4894-4660')).toBe(true); | ||
expect(okORCID(undefined)).toBe(false); | ||
expect(okORCID(39070)).toBe(false); | ||
expect(okORCID('0000-0003-4894-4661')).toBe(false); | ||
}); |