You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

string-byte-length

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-byte-length - npm Package Compare versions

Comparing version

to
2.0.0

build/src/main.d.ts

7

build/src/buffer.js
export const getNodeByteLength=function(string){
export const getNodeByteLength=(string)=>
return globalThis.Buffer.byteLength(string);
};
//# sourceMappingURL=buffer.js.map
globalThis.Buffer.byteLength(string);

@@ -5,3 +5,3 @@

export const getCharCodeByteLength=function(string){
export const getCharCodeByteLength=(string)=>{
const charLength=string.length;

@@ -14,3 +14,3 @@ let byteLength=charLength;

if(codepoint<=LAST_ASCII_CODEPOINT){
continue;
continue
}

@@ -20,3 +20,3 @@

byteLength+=1;
continue;
continue
}

@@ -27,3 +27,3 @@

if(codepoint<FIRST_HIGH_SURROGATE||codepoint>LAST_HIGH_SURROGATE){
continue;
continue
}

@@ -43,9 +43,9 @@

{
continue;
continue
}
charIndex+=1;
charIndex+=1
}
return byteLength;
return byteLength
};

@@ -64,3 +64,2 @@

const FIRST_LOW_SURROGATE=56320;
const LAST_LOW_SURROGATE=57343;
//# sourceMappingURL=char_code.js.map
const LAST_LOW_SURROGATE=57343;
export const createTextEncoderFunc=function(){
return getTextEncoderByteLength.bind(undefined,new TextEncoder);
};
export const createTextEncoderFunc=()=>
getTextEncoderByteLength.bind(undefined,new TextEncoder);
const getTextEncoderByteLength=function(textEncoder,string){
const getTextEncoderByteLength=(textEncoder,string)=>{
const encoderBuffer=getBuffer(string);
return textEncoder.encodeInto(string,encoderBuffer).written;
return textEncoder.encodeInto(string,encoderBuffer).written
};
const getBuffer=function(string){
const getBuffer=(string)=>{
const size=string.length*3;
if(size>CACHE_MAX_MEMORY){
return new Uint8Array(size);
return new Uint8Array(size)
}

@@ -22,6 +21,6 @@

cachedEncoderBuffer=new Uint8Array(size);
cachedEncoderBuffer=new Uint8Array(size)
}
return cachedEncoderBuffer;
return cachedEncoderBuffer
};

@@ -35,3 +34,2 @@

export const TEXT_ENCODER_MIN_LENGTH=100;
//# sourceMappingURL=encoder.js.map
export const TEXT_ENCODER_MIN_LENGTH=100;

@@ -6,22 +6,20 @@ import{getNodeByteLength}from"./buffer.js";

const getMainFunction=function(){
const getMainFunction=()=>{
if("Buffer"in globalThis&&"byteLength"in globalThis.Buffer){
return getNodeByteLength;
return getNodeByteLength
}
if("TextEncoder"in globalThis){
return getByteLength.bind(undefined,createTextEncoderFunc());
return getByteLength.bind(undefined,createTextEncoderFunc())
}
return getCharCodeByteLength;
return getCharCodeByteLength
};
const getByteLength=function(getTextEncoderByteLength,string){
return string.length<TEXT_ENCODER_MIN_LENGTH?
const getByteLength=(getTextEncoderByteLength,string)=>
string.length<TEXT_ENCODER_MIN_LENGTH?
getCharCodeByteLength(string):
getTextEncoderByteLength(string);
};
export default getMainFunction();
//# sourceMappingURL=main.js.map
export default getMainFunction();
{
"name": "string-byte-length",
"version": "1.6.0",
"version": "2.0.0",
"type": "module",
"exports": {
"types": "./build/types/main.d.ts",
"types": "./build/src/main.d.ts",
"default": "./build/src/main.js"
},
"main": "./build/src/main.js",
"types": "./build/types/main.d.ts",
"types": "./build/src/main.d.ts",
"files": [
"build/src/**/*.{js,json}",
"build/types/**/*.d.ts"
"build/src/**/*.{js,json,d.ts}",
"!build/src/**/*.test.js",
"!build/src/{helpers,fixtures}"
],

@@ -50,13 +51,12 @@ "sideEffects": false,

"directories": {
"lib": "src",
"test": "test"
"lib": "src"
},
"devDependencies": {
"@ehmicky/dev-tasks": "^1.0.102",
"spyd": "^0.6.0",
"test-each": "^5.5.0"
"@ehmicky/dev-tasks": "^2.0.80",
"spyd": "^0.6.1",
"test-each": "^6.0.0"
},
"engines": {
"node": ">=14.18.0"
"node": ">=16.17.0"
}
}
[![Node](https://img.shields.io/badge/-Node.js-808080?logo=node.js&colorA=404040&logoColor=66cc33)](https://www.npmjs.com/package/string-byte-length)
[![Browsers](https://img.shields.io/badge/-Browsers-808080?logo=firefox&colorA=404040)](https://unpkg.com/string-byte-length?module)
[![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript&colorA=404040&logoColor=0096ff)](/types/main.d.ts)
[![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript&colorA=404040&logoColor=0096ff)](/src/main.d.ts)
[![Codecov](https://img.shields.io/badge/-Tested%20100%25-808080?logo=codecov&colorA=404040)](https://codecov.io/gh/ehmicky/string-byte-length)
[![Minified size](https://img.shields.io/bundlephobia/minzip/string-byte-length?label&colorA=404040&colorB=808080&logo=webpack)](https://bundlephobia.com/package/string-byte-length)
[![Twitter](https://img.shields.io/badge/-Twitter-808080.svg?logo=twitter&colorA=404040)](https://twitter.com/intent/follow?screen_name=ehmicky)
[![Mastodon](https://img.shields.io/badge/-Mastodon-808080.svg?logo=mastodon&colorA=404040&logoColor=9590F9)](https://fosstodon.org/@ehmicky)
[![Medium](https://img.shields.io/badge/-Medium-808080.svg?logo=medium&colorA=404040)](https://medium.com/@ehmicky)

@@ -35,7 +35,10 @@

This package works in both Node.js >=14.18.0 and
[browsers](https://raw.githubusercontent.com/ehmicky/dev-tasks/main/src/tasks/build/browserslist).
It is an ES module and must be loaded using
This package works in both Node.js >=16.17.0 and
[browsers](https://raw.githubusercontent.com/ehmicky/dev-tasks/main/src/browserslist).
This is an ES module. It must be loaded using
[an `import` or `import()` statement](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c),
not `require()`.
not `require()`. If TypeScript is used, it must be configured to
[output ES modules](https://www.typescriptlang.org/docs/handbook/esm-node.html),
not CommonJS.

@@ -185,4 +188,4 @@ # Alternatives

<!--
<table><tr><td align="center"><a href="https://twitter.com/ehmicky"><img src="https://avatars2.githubusercontent.com/u/8136211?v=4" width="100px;" alt="ehmicky"/><br /><sub><b>ehmicky</b></sub></a><br /><a href="https://github.com/ehmicky/string-byte-length/commits?author=ehmicky" title="Code">💻</a> <a href="#design-ehmicky" title="Design">🎨</a> <a href="#ideas-ehmicky" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ehmicky/string-byte-length/commits?author=ehmicky" title="Documentation">📖</a></td></tr></table>
<table><tr><td align="center"><a href="https://fosstodon.org/@ehmicky"><img src="https://avatars2.githubusercontent.com/u/8136211?v=4" width="100px;" alt="ehmicky"/><br /><sub><b>ehmicky</b></sub></a><br /><a href="https://github.com/ehmicky/string-byte-length/commits?author=ehmicky" title="Code">💻</a> <a href="#design-ehmicky" title="Design">🎨</a> <a href="#ideas-ehmicky" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ehmicky/string-byte-length/commits?author=ehmicky" title="Documentation">📖</a></td></tr></table>
-->
<!-- ALL-CONTRIBUTORS-LIST:END -->