JS mendapatkan ukuran byte string
// JavaScript
(new Blob(['20€'])).size; // 5
// Node js
Buffer.from('20€').length; // 5
garzj
// JavaScript
(new Blob(['20€'])).size; // 5
// Node js
Buffer.from('20€').length; // 5
getStringMemorySize = function( _string ) {
"use strict";
var codePoint
, accum = 0
;
for( var stringIndex = 0, endOfString = _string.length; stringIndex < endOfString; stringIndex++ ) {
codePoint = _string.charCodeAt( stringIndex );
if( codePoint < 0x100 ) {
accum += 1;
continue;
}
if( codePoint < 0x10000 ) {
accum += 2;
continue;
}
if( codePoint < 0x1000000 ) {
accum += 3;
} else {
accum += 4;
}
}
return accum * 2;
}