Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

token-types

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

token-types - npm Package Compare versions

Comparing version 5.0.1 to 6.0.0

24

lib/index.d.ts

@@ -1,4 +0,2 @@

/// <reference types="node" resolution-mode="require"/>
import { IToken, IGetToken } from '@tokenizer/token';
import { Buffer } from 'node:buffer';
import type { IToken, IGetToken } from '@tokenizer/token';
/**

@@ -124,14 +122,10 @@ * 8-bit unsigned integer

}
export declare class BufferType implements IGetToken<Uint8Array, Buffer> {
len: number;
constructor(len: number);
get(uint8Array: Uint8Array, off: number): Buffer;
}
/**
* Consume a fixed number of bytes from the stream and return a string with a specified encoding.
*/
export declare class StringType implements IGetToken<string, Buffer> {
export declare class StringType implements IGetToken<string> {
len: number;
encoding: BufferEncoding;
constructor(len: number, encoding: BufferEncoding);
encoding: string;
private textDecoder;
constructor(len: number, encoding: string);
get(uint8Array: Uint8Array, offset: number): string;

@@ -145,9 +139,5 @@ }

len: number;
private static windows1252;
private static decode;
private static inRange;
private static codePointToString;
private static singleByteDecoder;
private textDecoder;
constructor(len: number);
get(buffer: Buffer, offset?: number): string;
get(uint8Array: Uint8Array, offset?: number): string;
}
import * as ieee754 from 'ieee754';
import { Buffer } from 'node:buffer';
// Primitive types

@@ -380,10 +379,2 @@ function dv(array) {

}
export class BufferType {
constructor(len) {
this.len = len;
}
get(uint8Array, off) {
return Buffer.from(uint8Array.subarray(off, off + this.len));
}
}
/**

@@ -396,5 +387,6 @@ * Consume a fixed number of bytes from the stream and return a string with a specified encoding.

this.encoding = encoding;
this.textDecoder = new TextDecoder(encoding);
}
get(uint8Array, offset) {
return Buffer.from(uint8Array).toString(this.encoding, offset, offset + this.len);
return this.textDecoder.decode(uint8Array.subarray(offset, offset + this.len));
}

@@ -409,44 +401,7 @@ }

this.len = len;
this.textDecoder = new TextDecoder('windows-1252');
}
static decode(buffer, offset, until) {
let str = '';
for (let i = offset; i < until; ++i) {
str += AnsiStringType.codePointToString(AnsiStringType.singleByteDecoder(buffer[i]));
}
return str;
get(uint8Array, offset = 0) {
return this.textDecoder.decode(uint8Array.subarray(offset, offset + this.len));
}
static inRange(a, min, max) {
return min <= a && a <= max;
}
static codePointToString(cp) {
if (cp <= 0xFFFF) {
return String.fromCharCode(cp);
}
else {
cp -= 0x10000;
return String.fromCharCode((cp >> 10) + 0xD800, (cp & 0x3FF) + 0xDC00);
}
}
static singleByteDecoder(bite) {
if (AnsiStringType.inRange(bite, 0x00, 0x7F)) {
return bite;
}
const codePoint = AnsiStringType.windows1252[bite - 0x80];
if (codePoint === null) {
throw Error('invaliding encoding');
}
return codePoint;
}
get(buffer, offset = 0) {
return AnsiStringType.decode(buffer, offset, offset + this.len);
}
}
AnsiStringType.windows1252 = [8364, 129, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352,
8249, 338, 141, 381, 143, 144, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732,
8482, 353, 8250, 339, 157, 382, 376, 160, 161, 162, 163, 164, 165, 166, 167, 168,
169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200,
201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
248, 249, 250, 251, 252, 253, 254, 255];
{
"name": "token-types",
"version": "5.0.1",
"version": "6.0.0",
"description": "Common token types for decoding and encoding numeric and string values",

@@ -19,4 +19,4 @@ "author": {

"compile": "npm run compile-src && npm run compile-test",
"eslint": "eslint lib test --ext .ts --ignore-pattern *.d.ts",
"lint-ts": "tslint lib/index.ts --exclude '*.d.ts' 'test/**/*.ts' --exclude 'test/**/*.d.ts'",
"eslint": "eslint lib/**/*.ts --ignore-pattern lib/**/*.d.ts test/**/*.ts",
"lint-ts": "tslint lib/index.ts --exclude '*.d.ts' 'test/**/*.ts' --exclude 'test/**/*.d.ts,lib/**/*.d.ts'",
"lint-md": "remark -u preset-lint-recommended .",

@@ -48,22 +48,22 @@ "lint": "npm run lint-md && npm run eslint",

"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.0",
"@types/node": "^18.6.3",
"@typescript-eslint/eslint-plugin": "^5.32.0",
"@typescript-eslint/parser": "^5.32.0",
"c8": "^7.12.0",
"chai": "^4.3.6",
"@types/mocha": "^10.0.0",
"@types/node": "^20.14.9",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.14.1",
"c8": "^10.1.2",
"chai": "^5.1.1",
"del-cli": "^5.0.0",
"eslint": "^8.9.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.4.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^39.3.4",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsdoc": "^48.5.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-unicorn": "^43.0.2",
"eslint-plugin-unicorn": "^54.0.0",
"mocha": "^10.0.0",
"remark-cli": "^11.0.0",
"remark-preset-lint-recommended": "^6.1.2",
"remark-cli": "^12.0.1",
"remark-preset-lint-recommended": "^7.0.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
"typescript": "^5.5.2"
},

@@ -70,0 +70,0 @@ "dependencies": {

@@ -1,2 +0,2 @@

![Node.js CI](https://github.com/Borewit/token-types/workflows/Node.js%20CI/badge.svg)
[![Node.js CI](https://github.com/Borewit/token-types/actions/workflows/nodejs-ci.yml/badge.svg?branch=master)](https://github.com/Borewit/token-types/actions/workflows/nodejs-ci.yml?query=branch%3Amaster)
[![NPM version](https://badge.fury.io/js/token-types.svg)](https://npmjs.org/package/token-types)

@@ -6,4 +6,2 @@ [![npm downloads](http://img.shields.io/npm/dm/token-types.svg)](https://npmcharts.com/compare/token-types,strtok3?start=1200&interval=30)

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4723ce4613fc49cda8db5eed29f18834)](https://www.codacy.com/app/Borewit/token-types?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Borewit/token-types&amp;utm_campaign=Badge_Grade)
[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/Borewit/token-types.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Borewit/token-types/context:javascript)
[![Total alerts](https://img.shields.io/lgtm/alerts/g/Borewit/token-types.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Borewit/token-types/alerts/)
[![DeepScan grade](https://deepscan.io/api/teams/5165/projects/6940/branches/61852/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=5165&pid=6940&bid=61852)

@@ -14,4 +12,4 @@ [![Known Vulnerabilities](https://snyk.io/test/github/Borewit/token-types/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Borewit/token-types?targetFile=package.json)

A primitive token library used to read and write from a node `Buffer`.
Although it is possible to use this module directly, it is primary designed to be used with [strtok3 tokenizer](https://github.com/Borewit/strtok3).
A primitive token library used to read and write from a `Uint8Array`.
Although it is possible to use this module directly, it is primarily designed to be used with [strtok3 tokenizer](https://github.com/Borewit/strtok3).

@@ -46,3 +44,3 @@ ## Compatibility

import * as token from 'token-types';
(async () => {

@@ -56,3 +54,3 @@

tokenizer.close(); // Close the file
}
}
})();

@@ -65,3 +63,3 @@ ```

`node-strtok` supports a wide variety of numerical tokens out of the box:
`token-types` supports a wide variety of numeric tokens out of the box:

@@ -97,15 +95,19 @@ | Token | Number | Bits | Endianness |

### Other tokens
(*) The tokens exceed the JavaScript IEEE 754 64-bit Floating Point precision, decoding and encoding is best effort based.
String types:
* Windows-1252
* ISO-8859-1
*) The tokens exceed the JavaScript IEEE 754 64-bit Floating Point precision, decoding and encoding is best effort based.
### String tokens
### Custom token
StringType decoding is implemented using TextDecoder which supports a large number of encodings including but not limited to:
Complex tokens can be added, which makes very suitable for reading binary files or network messages:
* UTF-8 (the default)
* Windows-1252
* ISO-8859-1
Check out [the MDN web docs for the TextDecoder](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/encoding) for a complete list
### Custom tokens
Custom tokens can be added, suitable for reading binary files or network messages:
```js
ExtendedHeader = {
ExtendedHeader = {
len: 10,

@@ -112,0 +114,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc