Comparing version 2.1.4 to 2.1.5
@@ -14,5 +14,11 @@ /** | ||
export function UTF8Encode(js_str) { | ||
if ( typeof js_str !== "string" ) { | ||
throw new TypeError( "Given input argument must be a js string!" ); | ||
} | ||
let codePoints = []; | ||
for( let i = 0; i < js_str.length; i++ ) { | ||
let i=0; | ||
while( i < js_str.length ) { | ||
let codePoint = js_str.codePointAt(i); | ||
// 1-byte sequence | ||
@@ -47,5 +53,3 @@ if( (codePoint & 0xffffff80) === 0 ) { | ||
if( codePoint > 0xffff ){ | ||
i++; | ||
} | ||
i += (codePoint>0xFFFF) ? 2 : 1; | ||
} | ||
@@ -71,3 +75,4 @@ return new Uint8Array(codePoints); | ||
let codePoints = []; | ||
for( let i = 0; i < uint8.length; i++ ) { | ||
let i = 0; | ||
while( i < uint8.length ) { | ||
let codePoint = uint8[i] & 0xff; | ||
@@ -78,8 +83,9 @@ | ||
codePoints.push(codePoint); | ||
i += 1; | ||
} | ||
// 2-byte sequence (192 ~ 223) | ||
else if( (codePoint & 0xe0) === 0xc0 ){ | ||
else if( (codePoint & 0xE0) === 0xC0 ){ | ||
codePoint = ((0x1f & uint8[i]) << 6) | (0x3f & uint8[i + 1]); | ||
codePoints.push(codePoint); | ||
i += 1; | ||
i += 2; | ||
} | ||
@@ -92,3 +98,3 @@ // 3-byte sequence (224 ~ 239) | ||
codePoints.push(codePoint); | ||
i += 2; | ||
i += 3; | ||
} | ||
@@ -102,4 +108,7 @@ // 4-byte sequence (249 ~ ) | ||
codePoints.push(codePoint); | ||
i += 3; | ||
i += 4; | ||
} | ||
else { | ||
i += 1; | ||
} | ||
} | ||
@@ -112,5 +121,5 @@ | ||
const chunk = codePoints.splice(0, UTF8_DECODE_CHUNK_SIZE); | ||
result_string += String.fromCharCode(...chunk); | ||
result_string += String.fromCodePoint(...chunk); | ||
} | ||
return result_string; | ||
} |
{ | ||
"name": "extes", | ||
"version": "2.1.4", | ||
"version": "2.1.5", | ||
"description": "A tiny library that extends native js with some handy tools", | ||
@@ -5,0 +5,0 @@ "main": "index.mjs", |
34352
1171