token-types
Advanced tools
Comparing version 0.9.1 to 0.9.2
@@ -66,2 +66,6 @@ /// <reference types="node" /> | ||
/** | ||
* 24-bit signed integer, Little Endian byte order | ||
*/ | ||
export declare const INT24_LE: IToken<number>; | ||
/** | ||
* 24-bit signed integer, Big Endian byte order | ||
@@ -103,1 +107,15 @@ */ | ||
} | ||
/** | ||
* ANSI Latin 1 String | ||
* Using windows-1252 / ISO 8859-1 decoding | ||
*/ | ||
export declare class AnsiStringType implements IGetToken<string> { | ||
len: number; | ||
private static windows1252; | ||
private static decode(buffer, off, until); | ||
private static inRange(a, min, max); | ||
private static codePointToString(cp); | ||
private static singleByteDecoder(bite); | ||
constructor(len: number); | ||
get(buf: Buffer, off?: number): string; | ||
} |
154
lib/index.js
@@ -8,4 +8,4 @@ "use strict"; | ||
if (o + len > b.length) { | ||
if (typeof (flush) !== 'function') { | ||
throw new Error('Buffer out of space and no valid flush() function found'); | ||
if (typeof (flush) !== "function") { | ||
throw new Error("Buffer out of space and no valid flush() function found"); | ||
} | ||
@@ -27,4 +27,4 @@ flush(b, o); | ||
put: function (b, o, v, flush) { | ||
assert.equal(typeof o, 'number'); | ||
assert.equal(typeof v, 'number'); | ||
assert.equal(typeof o, "number"); | ||
assert.equal(typeof v, "number"); | ||
assert.ok(v >= 0 && v <= 0xff); | ||
@@ -47,4 +47,4 @@ assert.ok(o >= 0); | ||
put: function (b, o, v, flush) { | ||
assert.equal(typeof o, 'number'); | ||
assert.equal(typeof v, 'number'); | ||
assert.equal(typeof o, "number"); | ||
assert.equal(typeof v, "number"); | ||
assert.ok(v >= 0 && v <= 0xffff); | ||
@@ -67,4 +67,4 @@ assert.ok(o >= 0); | ||
put: function (b, o, v, flush) { | ||
assert.equal(typeof o, 'number'); | ||
assert.equal(typeof v, 'number'); | ||
assert.equal(typeof o, "number"); | ||
assert.equal(typeof v, "number"); | ||
assert.ok(v >= 0 && v <= 0xffff); | ||
@@ -84,7 +84,7 @@ assert.ok(o >= 0); | ||
get: function (buf, off) { | ||
return buf[off] | (buf[off + 1] << 8) | (buf[off + 2] << 16); | ||
return buf.readUIntLE(off, 3); | ||
}, | ||
put: function (b, o, v, flush) { | ||
assert.equal(typeof o, 'number'); | ||
assert.equal(typeof v, 'number'); | ||
assert.equal(typeof o, "number"); | ||
assert.equal(typeof v, "number"); | ||
assert.ok(v >= 0 && v <= 0xffffff); | ||
@@ -94,5 +94,3 @@ assert.ok(o >= 0); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
b[no] = v & 0xff; | ||
b[no + 1] = (v >>> 8) & 0xff; | ||
b[no + 2] = (v >>> 16) & 0xff; | ||
b.writeUIntLE(v, no, 3); | ||
return (no - o) + this.len; | ||
@@ -107,7 +105,7 @@ } | ||
get: function (buf, off) { | ||
return (((buf[off] << 8) + buf[off + 1]) << 8) + buf[off + 2]; | ||
return buf.readUIntBE(off, 3); | ||
}, | ||
put: function (b, o, v, flush) { | ||
assert.equal(typeof o, 'number'); | ||
assert.equal(typeof v, 'number'); | ||
assert.equal(typeof o, "number"); | ||
assert.equal(typeof v, "number"); | ||
assert.ok(v >= 0 && v <= 0xffffff); | ||
@@ -117,5 +115,3 @@ assert.ok(o >= 0); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
b[no] = (v >>> 16) & 0xff; | ||
b[no + 1] = (v >>> 8) & 0xff; | ||
b[no + 2] = v & 0xff; | ||
b.writeUIntBE(v, no, 3); | ||
return (no - o) + this.len; | ||
@@ -133,4 +129,4 @@ } | ||
put: function (b, o, v, flush) { | ||
assert.equal(typeof o, 'number'); | ||
assert.equal(typeof v, 'number'); | ||
assert.equal(typeof o, "number"); | ||
assert.equal(typeof v, "number"); | ||
assert.ok(v >= 0 && v <= 0xffffffff); | ||
@@ -153,4 +149,4 @@ assert.ok(o >= 0); | ||
put: function (b, o, v, flush) { | ||
assert.equal(typeof o, 'number'); | ||
assert.equal(typeof v, 'number'); | ||
assert.equal(typeof o, "number"); | ||
assert.equal(typeof v, "number"); | ||
assert.ok(v >= 0 && v <= 0xffffffff); | ||
@@ -173,4 +169,4 @@ assert.ok(o >= 0); | ||
put: function (b, o, v, flush) { | ||
assert.equal(typeof o, 'number'); | ||
assert.equal(typeof v, 'number'); | ||
assert.equal(typeof o, "number"); | ||
assert.equal(typeof v, "number"); | ||
assert.ok(v >= -128 && v <= 127); | ||
@@ -193,4 +189,4 @@ assert.ok(o >= 0); | ||
put: function (b, o, v, flush) { | ||
assert.equal(typeof o, 'number'); | ||
assert.equal(typeof v, 'number'); | ||
assert.equal(typeof o, "number"); | ||
assert.equal(typeof v, "number"); | ||
assert.ok(v >= -32768 && v <= 32767); | ||
@@ -213,4 +209,4 @@ assert.ok(o >= 0); | ||
put: function (b, o, v, flush) { | ||
assert.equal(typeof o, 'number'); | ||
assert.equal(typeof v, 'number'); | ||
assert.equal(typeof o, "number"); | ||
assert.equal(typeof v, "number"); | ||
assert.ok(v >= -32768 && v <= 32767); | ||
@@ -225,2 +221,21 @@ assert.ok(o >= 0); | ||
/** | ||
* 24-bit signed integer, Little Endian byte order | ||
*/ | ||
exports.INT24_LE = { | ||
len: 3, | ||
get: function (buf, off) { | ||
return buf.readIntLE(off, 3); | ||
}, | ||
put: function (b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
assert.equal(typeof v, "number"); | ||
assert.ok(v >= -0x800000 && v <= 0x7fffff); | ||
assert.ok(o >= 0); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
b.writeIntLE(v, no, 3); | ||
return (no - o) + this.len; | ||
} | ||
}; | ||
/** | ||
* 24-bit signed integer, Big Endian byte order | ||
@@ -231,9 +246,7 @@ */ | ||
get: function (buf, off) { | ||
var v = exports.UINT24_BE.get(buf, off); | ||
return ((v & 0x800000) === 0x800000) ? | ||
(-0x800000 + (v & 0x7fffff)) : v; | ||
return buf.readIntBE(off, 3); | ||
}, | ||
put: function (b, o, v, flush) { | ||
assert.equal(typeof o, 'number'); | ||
assert.equal(typeof v, 'number'); | ||
assert.equal(typeof o, "number"); | ||
assert.equal(typeof v, "number"); | ||
assert.ok(v >= -0x800000 && v <= 0x7fffff); | ||
@@ -243,5 +256,3 @@ assert.ok(o >= 0); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
b[no] = (v >>> 16) & 0xff; | ||
b[no + 1] = (v >>> 8) & 0xff; | ||
b[no + 2] = v & 0xff; | ||
b.writeIntBE(v, no, 3); | ||
return (no - o) + this.len; | ||
@@ -259,4 +270,4 @@ } | ||
put: function (b, o, v, flush) { | ||
assert.equal(typeof o, 'number'); | ||
assert.equal(typeof v, 'number'); | ||
assert.equal(typeof o, "number"); | ||
assert.equal(typeof v, "number"); | ||
assert.ok(v >= -2147483648 && v <= 2147483647); | ||
@@ -279,4 +290,4 @@ assert.ok(o >= 0); | ||
put: function (b, o, v, flush) { | ||
assert.equal(typeof o, 'number'); | ||
assert.equal(typeof v, 'number'); | ||
assert.equal(typeof o, "number"); | ||
assert.equal(typeof v, "number"); | ||
assert.ok(v >= -2147483648 && v <= 2147483647); | ||
@@ -293,3 +304,3 @@ assert.ok(o >= 0); | ||
*/ | ||
var IgnoreType = (function () { | ||
var IgnoreType = /** @class */ (function () { | ||
/** | ||
@@ -308,3 +319,3 @@ * @param len number of bytes to ignore | ||
exports.IgnoreType = IgnoreType; | ||
var BufferType = (function () { | ||
var BufferType = /** @class */ (function () { | ||
function BufferType(len) { | ||
@@ -322,3 +333,3 @@ this.len = len; | ||
*/ | ||
var StringType = (function () { | ||
var StringType = /** @class */ (function () { | ||
function StringType(len, encoding) { | ||
@@ -334,1 +345,54 @@ this.len = len; | ||
exports.StringType = StringType; | ||
/** | ||
* ANSI Latin 1 String | ||
* Using windows-1252 / ISO 8859-1 decoding | ||
*/ | ||
var AnsiStringType = /** @class */ (function () { | ||
function AnsiStringType(len) { | ||
this.len = len; | ||
} | ||
AnsiStringType.decode = function (buffer, off, until) { | ||
var str = ""; | ||
for (var i = off; i < until; ++i) { | ||
str += AnsiStringType.codePointToString(AnsiStringType.singleByteDecoder(buffer[i])); | ||
} | ||
return str; | ||
}; | ||
AnsiStringType.inRange = function (a, min, max) { | ||
return min <= a && a <= max; | ||
}; | ||
AnsiStringType.codePointToString = function (cp) { | ||
if (cp <= 0xFFFF) { | ||
return String.fromCharCode(cp); | ||
} | ||
else { | ||
cp -= 0x10000; | ||
return String.fromCharCode((cp >> 10) + 0xD800, (cp & 0x3FF) + 0xDC00); | ||
} | ||
}; | ||
AnsiStringType.singleByteDecoder = function (bite) { | ||
if (AnsiStringType.inRange(bite, 0x00, 0x7F)) { | ||
return bite; | ||
} | ||
var codePoint = AnsiStringType.windows1252[bite - 0x80]; | ||
if (codePoint === null) { | ||
throw Error("invaliding encoding"); | ||
} | ||
return codePoint; | ||
}; | ||
AnsiStringType.prototype.get = function (buf, off) { | ||
if (off === void 0) { off = 0; } | ||
return AnsiStringType.decode(buf, off, off + 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]; | ||
return AnsiStringType; | ||
}()); | ||
exports.AnsiStringType = AnsiStringType; |
{ | ||
"name": "token-types", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "Common token types for decoding and encoding binairy values", | ||
@@ -26,3 +26,3 @@ "author": { | ||
}, | ||
"license": "BSD-3-Clause", | ||
"license": "MIT", | ||
"main": "./lib/index.js", | ||
@@ -34,14 +34,14 @@ "typings": "lib/index", | ||
"devDependencies": { | ||
"@types/chai": "^4.0.3", | ||
"@types/mocha": "^2.2.41", | ||
"@types/node": "^8.0.24", | ||
"chai": "^4.1.1", | ||
"@types/chai": "^4.0.4", | ||
"@types/mocha": "^2.2.43", | ||
"@types/node": "^8.0.32", | ||
"chai": "^4.1.2", | ||
"copyfiles": "^1.2.0", | ||
"coveralls": "^2.13.1", | ||
"mocha": "^3.5.0", | ||
"nyc": "^11.1.0", | ||
"source-map": "^0.5.6", | ||
"coveralls": "^2.13.3", | ||
"mocha": "^3.5.3", | ||
"nyc": "^11.2.1", | ||
"source-map": "^0.5.7", | ||
"ts-node": "^3.3.0", | ||
"tslint": "^5.6.0", | ||
"typescript": "^2.5.1", | ||
"tslint": "^5.7.0", | ||
"typescript": "^2.5.3", | ||
"typings": "^2.1.1" | ||
@@ -48,0 +48,0 @@ }, |
[![Build Status](https://travis-ci.org/Borewit/token-types.svg?branch=master)](https://travis-ci.org/Borewit/token-types) | ||
[![NPM version](https://badge.fury.io/js/token-types.svg)](https://npmjs.org/package/token-types) | ||
[![npm downloads](http://img.shields.io/npm/dm/token-types.svg)](https://npmjs.org/package/token-types) | ||
[![Dependencies](https://david-dm.org/Borewit/token-types.svg)](https://github.com/Borewit/token-types) | ||
[![Dependencies](https://david-dm.org/Borewit/token-types.svg)](https://david-dm.org/Borewit/token-types) | ||
[![coveralls](https://coveralls.io/repos/github/Borewit/token-types/badge.svg?branch=master)](https://coveralls.io/github/Borewit/token-types?branch=master) | ||
@@ -22,2 +22,6 @@ | ||
String types: | ||
* Windows-1252 | ||
* ISO-8859-1 | ||
One might notice that there is no support for 64-bit tokens, since JavaScript | ||
@@ -24,0 +28,0 @@ seems to limit value size to less than 2^64. Rather than wrapping up an |
@@ -22,3 +22,3 @@ { | ||
"object-literal-sort-keys": [false], | ||
"max-line-length": [true, 200], | ||
"max-line-length": false, | ||
"switch-default": false, | ||
@@ -25,0 +25,0 @@ "prefer-for-of": false, |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
39
19996
8
534
1