diff --git a/util.js b/src/util.js copy from util.js copy to src/util.js --- a/util.js +++ b/src/util.js @@ -1,10 +1,10 @@ -const MASK=0xffffffff; +export const MASK=0xffffffff; -function bytes2int32(arr){ +export function bytes2int32(arr){ return arr.reduce((acc,b,i)=>acc|b<<(i*8)); } -function bytes2int32s(arr){ +export function bytes2int32s(arr){ let res=[]; for(let i=0;iacc.concat(bytes)); } -function bytes2hex(arr){ +export function bytes2hex(arr){ return arr.map(x=>x.toString(16).padStart(2,"0")).join(""); } -function str2utf8(s){ +export function str2utf8(s){ let res=[]; let c=s.codePointAt(0); for(let i=0; c!==undefined; i++,c=s.codePointAt(i)){ @@ -54,7 +54,7 @@ function str2utf8(s){ return res; } -function utf82str(arr){ +export function utf82str(arr){ let res=[]; for(let i=0;iString.fromCodePoint(x)).join(""); } - -if(typeof module!=='undefined'&&module.hasOwnProperty('exports')){ - module.exports.bytes2int32=bytes2int32; - module.exports.bytes2int32s=bytes2int32s; - module.exports.int322bytes=int322bytes; - module.exports.int32s2bytes=int32s2bytes; - module.exports.bytes2hex=bytes2hex; - module.exports.str2utf8=str2utf8; - module.exports.utf82str=utf82str; -}