- Notifications
You must be signed in to change notification settings - Fork254
-
BetaWas this translation helpful?Give feedback.
All reactions
Answered by exqmjmzNov 24, 2023
problem solve.
The custom JavaScript library needs to be imported using the UMD approach.
library import success
Modified code:
// File log.js(function(global,factory){if(typeofdefine==="function"&&define.amd){define(["exports"],factory);}elseif(typeofexports!=="undefined"){factory(exports);}else{varmod={exports:{}};factory(mod.exports);global.ULID=mod.exports;}})(this,function(exports){"use strict";/** * Constructs a ULID generator closure that emits universally unique, * monotonic values. * * var generator = ULID(); * var ulid0 = gene…
Replies: 1 comment 1 reply
-
problem solve. Modified code: // File log.js(function(global,factory){if(typeofdefine==="function"&&define.amd){define(["exports"],factory);}elseif(typeofexports!=="undefined"){factory(exports);}else{varmod={exports:{}};factory(mod.exports);global.ULID=mod.exports;}})(this,function(exports){"use strict";/** * Constructs a ULID generator closure that emits universally unique, * monotonic values. * * var generator = ULID(); * var ulid0 = generator(); * var ulid1 = generator(); * assert(ulid0 < ulid1); */functionULID(){varBASE32=['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','J','K','M','N','P','Q','R','S','T','V','W','X','Y','Z'];varlast=-1;/* Pre-allocate work buffers / views */varulid=newUint8Array(16);vartime=newDataView(ulid.buffer,0,6);varrand=newUint8Array(ulid.buffer,6,10);vardest=newArray(26);functionencode(ulid){dest[0]=BASE32[ulid[0]>>5];dest[1]=BASE32[(ulid[0]>>0)&0x1f];for(vari=0;i<3;i++){dest[i*8+2]=BASE32[ulid[i*5+1]>>3];dest[i*8+3]=BASE32[(ulid[i*5+1]<<2|ulid[i*5+2]>>6)&0x1f];dest[i*8+4]=BASE32[(ulid[i*5+2]>>1)&0x1f];dest[i*8+5]=BASE32[(ulid[i*5+2]<<4|ulid[i*5+3]>>4)&0x1f];dest[i*8+6]=BASE32[(ulid[i*5+3]<<1|ulid[i*5+4]>>7)&0x1f];dest[i*8+7]=BASE32[(ulid[i*5+4]>>2)&0x1f];dest[i*8+8]=BASE32[(ulid[i*5+4]<<3|ulid[i*5+5]>>5)&0x1f];dest[i*8+9]=BASE32[(ulid[i*5+5]>>0)&0x1f];}returndest.join('');}returnfunction(){varnow=Date.now();if(now===last){/* 80-bit overflow is so incredibly unlikely that it's not * considered as a possiblity here. */for(vari=9;i>=0;i--)if(rand[i]++<255)break;}else{last=now;time.setUint16(0,(now/4294967296.0)|0);time.setUint32(2,now|0);window.crypto.getRandomValues(rand);}returnencode(ulid);};}functiongenerator(){varulid=newULID()returnulid()}// expose ulid to other modulesexports.generator=generator;}); UMD model example code // File log.js(function(global,factory){if(typeofdefine==="function"&&define.amd){define(["exports"],factory);}elseif(typeofexports!=="undefined"){factory(exports);}else{varmod={exports:{}};factory(mod.exports);global.log=mod.exports;}})(this,function(exports){"use strict";functionlog(){console.log("Example of UMD module system");}// expose log to other modulesexports.log=log;}); |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 1
1 reply
-
This is truly valuable! Thank you very much! |
BetaWas this translation helpful?Give feedback.
All reactions
Answer selected byFalkWolsky
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment