UNPKG

@naria2/node

Version:

Cross-platform wrapper of aria2

2 lines (1 loc) 867 B
let c;const a=new Uint8Array(16);function n(){if(!c&&(c=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!c))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return c(a)}const e=[];for(let o=0;o<256;++o)e.push((o+256).toString(16).slice(1));function s(o,r=0){return e[o[r+0]]+e[o[r+1]]+e[o[r+2]]+e[o[r+3]]+"-"+e[o[r+4]]+e[o[r+5]]+"-"+e[o[r+6]]+e[o[r+7]]+"-"+e[o[r+8]]+e[o[r+9]]+"-"+e[o[r+10]]+e[o[r+11]]+e[o[r+12]]+e[o[r+13]]+e[o[r+14]]+e[o[r+15]]}const y=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),d={randomUUID:y};function i(o,r,p){if(d.randomUUID&&!r&&!o)return d.randomUUID();o=o||{};const t=o.random||(o.rng||n)();if(t[6]=t[6]&15|64,t[8]=t[8]&63|128,r){p=p||0;for(let u=0;u<16;++u)r[p+u]=t[u];return r}return s(t)}export{i as v4};