1// JavaScript
2(new Blob(['20€'])).size; // 5
3
4// Node js
5Buffer.from('20€').length; // 5
1 getStringMemorySize = function( _string ) {
2 "use strict";
3
4 var codePoint
5 , accum = 0
6 ;
7
8 for( var stringIndex = 0, endOfString = _string.length; stringIndex < endOfString; stringIndex++ ) {
9 codePoint = _string.charCodeAt( stringIndex );
10
11 if( codePoint < 0x100 ) {
12 accum += 1;
13 continue;
14 }
15
16 if( codePoint < 0x10000 ) {
17 accum += 2;
18 continue;
19 }
20
21 if( codePoint < 0x1000000 ) {
22 accum += 3;
23 } else {
24 accum += 4;
25 }
26 }
27
28 return accum * 2;
29 }
30