UNPKG

orcid-utils

Version:
3 lines (2 loc) 1.4 kB
"use strict";var e=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var D=(t,r)=>{for(var o in r)e(t,o,{get:r[o],enumerable:!0})},m=(t,r,o,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of d(r))!x.call(t,n)&&n!==o&&e(t,n,{get:()=>r[n],enumerable:!(i=h(r,n))||i.enumerable});return t};var b=t=>m(e({},"__esModule",{value:!0}),t);var I={};D(I,{ORCID:()=>F,inAcceptedFormat:()=>s,isValid:()=>g,toDashFormat:()=>a,toNoDashFormat:()=>c,toUriWithProtocol:()=>f,toUriWithoutProtocol:()=>u,validate:()=>l});module.exports=b(I);function s(t){if(typeof t!="string")throw TypeError("Input must be string");return/^((https?:\/\/)?orcid\.org\/)?([0-9]{4}-?){3}[0-9]{3}[0-9X]$/i.test(t)}function a(t){const r=c(t);return[0,4,8,12].map(o=>r.slice(o,o+4)).join("-")}function p(t){return t.replace(/-/g,"").slice(-16).toUpperCase()}function c(t){return l(t),p(t)}function f(t,r){return(r===void 0||r?"https":"http")+"://"+u(t)}function u(t){return"orcid.org/"+a(t)}function g(t){if(!s(t))return!1;const r=p(t);let o=0;for(let n=0;n<15;n++)o=(o+ +r[n])*2;const i=(12-o%11)%11;return r[15]===(i===10?"X":i+"")}function l(t){if(!g(t))throw Error("Invalid ORCID")}const F={isValid:g,validate:l,inAcceptedFormat:s,toDashFormat:a,toNoDashFormat:c,toUriWithProtocol:f,toUriWithoutProtocol:u}; //# sourceMappingURL=orcid.min.js.map