structurae
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -114,2 +114,23 @@ const { searchNaive, searchShiftOr } = require('./algorithms'); | ||
} | ||
/** | ||
* Returns the size in bytes of a given string. | ||
* | ||
* @param {string} string the string to check | ||
* @returns {number} the size in bytes | ||
*/ | ||
static getStringSize(string) { | ||
let size = 0; | ||
for (let i = 0; i < string.length; i++) { | ||
const code = string.codePointAt(i); | ||
if (code < 0x0080) size += 1; // 1-byte | ||
else if (code < 0x0800) size += 2; // 2-byte | ||
else if (code < 0x10000) size += 3; // 3-byte | ||
else { // 4-byte | ||
size += 4; | ||
i++; | ||
} | ||
} | ||
return size; | ||
} | ||
} | ||
@@ -119,2 +140,3 @@ | ||
* @type Int8Array | ||
* @private | ||
*/ | ||
@@ -121,0 +143,0 @@ StringView.masks = new Int8Array(256).fill(-1); |
{ | ||
"name": "structurae", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "Data structures for performance-sensitive modern JavaScript applications.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73152
1897