token-types
Advanced tools
Comparing version 0.10.0 to 1.0.0
231
lib/index.js
"use strict"; | ||
// A fast streaming parser library. | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var assert = require("assert"); | ||
const assert = require("assert"); | ||
// Possibly call flush() | ||
var maybeFlush = function (b, o, len, flush) { | ||
const maybeFlush = (b, o, len, flush) => { | ||
if (o + len > b.length) { | ||
@@ -22,6 +22,6 @@ if (typeof (flush) !== "function") { | ||
len: 1, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return buf.readUInt8(off); | ||
}, | ||
put: function (b, o, v, flush) { | ||
put(b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
@@ -32,3 +32,3 @@ assert.equal(typeof v, "number"); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
const no = maybeFlush(b, o, this.len, flush); | ||
b.writeUInt8(v, no); | ||
@@ -43,6 +43,6 @@ return (no - o) + this.len; | ||
len: 2, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return buf.readUInt16LE(off); | ||
}, | ||
put: function (b, o, v, flush) { | ||
put(b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
@@ -53,3 +53,3 @@ assert.equal(typeof v, "number"); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
const no = maybeFlush(b, o, this.len, flush); | ||
b.writeUInt16LE(v, no); | ||
@@ -64,6 +64,6 @@ return (no - o) + this.len; | ||
len: 2, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return buf.readUInt16BE(off); | ||
}, | ||
put: function (b, o, v, flush) { | ||
put(b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
@@ -74,3 +74,3 @@ assert.equal(typeof v, "number"); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
const no = maybeFlush(b, o, this.len, flush); | ||
b.writeUInt16BE(v, no); | ||
@@ -85,6 +85,6 @@ return (no - o) + this.len; | ||
len: 3, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return buf.readUIntLE(off, 3); | ||
}, | ||
put: function (b, o, v, flush) { | ||
put(b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
@@ -95,3 +95,3 @@ assert.equal(typeof v, "number"); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
const no = maybeFlush(b, o, this.len, flush); | ||
b.writeUIntLE(v, no, 3); | ||
@@ -106,6 +106,6 @@ return (no - o) + this.len; | ||
len: 3, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return buf.readUIntBE(off, 3); | ||
}, | ||
put: function (b, o, v, flush) { | ||
put(b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
@@ -116,3 +116,3 @@ assert.equal(typeof v, "number"); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
const no = maybeFlush(b, o, this.len, flush); | ||
b.writeUIntBE(v, no, 3); | ||
@@ -127,6 +127,6 @@ return (no - o) + this.len; | ||
len: 4, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return buf.readUInt32LE(off); | ||
}, | ||
put: function (b, o, v, flush) { | ||
put(b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
@@ -137,3 +137,3 @@ assert.equal(typeof v, "number"); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
const no = maybeFlush(b, o, this.len, flush); | ||
b.writeUInt32LE(v, no); | ||
@@ -148,6 +148,6 @@ return (no - o) + this.len; | ||
len: 4, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return buf.readUInt32BE(off); | ||
}, | ||
put: function (b, o, v, flush) { | ||
put(b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
@@ -158,3 +158,3 @@ assert.equal(typeof v, "number"); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
const no = maybeFlush(b, o, this.len, flush); | ||
b.writeUInt32BE(v, no); | ||
@@ -169,6 +169,6 @@ return (no - o) + this.len; | ||
len: 1, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return buf.readInt8(off); | ||
}, | ||
put: function (b, o, v, flush) { | ||
put(b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
@@ -179,3 +179,3 @@ assert.equal(typeof v, "number"); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
const no = maybeFlush(b, o, this.len, flush); | ||
b.writeInt8(v, no); | ||
@@ -190,6 +190,6 @@ return (no - o) + this.len; | ||
len: 2, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return buf.readInt16BE(off); | ||
}, | ||
put: function (b, o, v, flush) { | ||
put(b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
@@ -200,3 +200,3 @@ assert.equal(typeof v, "number"); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
const no = maybeFlush(b, o, this.len, flush); | ||
b.writeInt16BE(v, no); | ||
@@ -211,6 +211,6 @@ return (no - o) + this.len; | ||
len: 2, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return buf.readInt16LE(off); | ||
}, | ||
put: function (b, o, v, flush) { | ||
put(b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
@@ -221,3 +221,3 @@ assert.equal(typeof v, "number"); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
const no = maybeFlush(b, o, this.len, flush); | ||
b.writeInt16LE(v, no); | ||
@@ -232,6 +232,6 @@ return (no - o) + this.len; | ||
len: 3, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return buf.readIntLE(off, 3); | ||
}, | ||
put: function (b, o, v, flush) { | ||
put(b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
@@ -242,3 +242,3 @@ assert.equal(typeof v, "number"); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
const no = maybeFlush(b, o, this.len, flush); | ||
b.writeIntLE(v, no, 3); | ||
@@ -253,6 +253,6 @@ return (no - o) + this.len; | ||
len: 3, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return buf.readIntBE(off, 3); | ||
}, | ||
put: function (b, o, v, flush) { | ||
put(b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
@@ -263,3 +263,3 @@ assert.equal(typeof v, "number"); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
const no = maybeFlush(b, o, this.len, flush); | ||
b.writeIntBE(v, no, 3); | ||
@@ -274,6 +274,6 @@ return (no - o) + this.len; | ||
len: 4, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return buf.readInt32BE(off); | ||
}, | ||
put: function (b, o, v, flush) { | ||
put(b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
@@ -284,3 +284,3 @@ assert.equal(typeof v, "number"); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
const no = maybeFlush(b, o, this.len, flush); | ||
b.writeInt32BE(v, no); | ||
@@ -295,6 +295,6 @@ return (no - o) + this.len; | ||
len: 4, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return buf.readInt32LE(off); | ||
}, | ||
put: function (b, o, v, flush) { | ||
put(b, o, v, flush) { | ||
assert.equal(typeof o, "number"); | ||
@@ -305,3 +305,3 @@ assert.equal(typeof v, "number"); | ||
assert.ok(this.len <= b.length); | ||
var no = maybeFlush(b, o, this.len, flush); | ||
const no = maybeFlush(b, o, this.len, flush); | ||
b.writeInt32LE(v, no); | ||
@@ -316,6 +316,6 @@ return (no - o) + this.len; | ||
len: 8, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return readUIntLE(buf, off, this.len); | ||
}, | ||
put: function (b, o, v) { | ||
put(b, o, v) { | ||
return writeUIntLE(b, v, o, this.len); | ||
@@ -329,6 +329,6 @@ } | ||
len: 8, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return readIntLE(buf, off, this.len); | ||
}, | ||
put: function (b, off, v) { | ||
put(b, off, v) { | ||
return writeIntLE(b, v, off, this.len); | ||
@@ -342,6 +342,6 @@ } | ||
len: 8, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return readUIntBE(buf, off, this.len); | ||
}, | ||
put: function (b, o, v) { | ||
put(b, o, v) { | ||
return writeUIntBE(b, v, o, this.len); | ||
@@ -355,6 +355,6 @@ } | ||
len: 8, | ||
get: function (buf, off) { | ||
get(buf, off) { | ||
return readIntBE(buf, off, this.len); | ||
}, | ||
put: function (b, off, v) { | ||
put(b, off, v) { | ||
return writeIntBE(b, v, off, this.len); | ||
@@ -366,25 +366,23 @@ } | ||
*/ | ||
var IgnoreType = /** @class */ (function () { | ||
class IgnoreType { | ||
/** | ||
* @param len number of bytes to ignore | ||
*/ | ||
function IgnoreType(len) { | ||
constructor(len) { | ||
this.len = len; | ||
} | ||
// ToDo: don't read, but skip data | ||
IgnoreType.prototype.get = function (buf, off) { | ||
get(buf, off) { | ||
return null; | ||
}; | ||
return IgnoreType; | ||
}()); | ||
} | ||
} | ||
exports.IgnoreType = IgnoreType; | ||
var BufferType = /** @class */ (function () { | ||
function BufferType(len) { | ||
class BufferType { | ||
constructor(len) { | ||
this.len = len; | ||
} | ||
BufferType.prototype.get = function (buf, off) { | ||
get(buf, off) { | ||
return buf.slice(off, off + this.len); | ||
}; | ||
return BufferType; | ||
}()); | ||
} | ||
} | ||
exports.BufferType = BufferType; | ||
@@ -394,12 +392,11 @@ /** | ||
*/ | ||
var StringType = /** @class */ (function () { | ||
function StringType(len, encoding) { | ||
class StringType { | ||
constructor(len, encoding) { | ||
this.len = len; | ||
this.encoding = encoding; | ||
} | ||
StringType.prototype.get = function (buf, off) { | ||
get(buf, off) { | ||
return buf.toString(this.encoding, off, off + this.len); | ||
}; | ||
return StringType; | ||
}()); | ||
} | ||
} | ||
exports.StringType = StringType; | ||
@@ -410,17 +407,17 @@ /** | ||
*/ | ||
var AnsiStringType = /** @class */ (function () { | ||
function AnsiStringType(len) { | ||
class AnsiStringType { | ||
constructor(len) { | ||
this.len = len; | ||
} | ||
AnsiStringType.decode = function (buffer, off, until) { | ||
var str = ""; | ||
for (var i = off; i < until; ++i) { | ||
static decode(buffer, off, until) { | ||
let str = ""; | ||
for (let i = off; i < until; ++i) { | ||
str += AnsiStringType.codePointToString(AnsiStringType.singleByteDecoder(buffer[i])); | ||
} | ||
return str; | ||
}; | ||
AnsiStringType.inRange = function (a, min, max) { | ||
} | ||
static inRange(a, min, max) { | ||
return min <= a && a <= max; | ||
}; | ||
AnsiStringType.codePointToString = function (cp) { | ||
} | ||
static codePointToString(cp) { | ||
if (cp <= 0xFFFF) { | ||
@@ -433,8 +430,8 @@ return String.fromCharCode(cp); | ||
} | ||
}; | ||
AnsiStringType.singleByteDecoder = function (bite) { | ||
} | ||
static singleByteDecoder(bite) { | ||
if (AnsiStringType.inRange(bite, 0x00, 0x7F)) { | ||
return bite; | ||
} | ||
var codePoint = AnsiStringType.windows1252[bite - 0x80]; | ||
const codePoint = AnsiStringType.windows1252[bite - 0x80]; | ||
if (codePoint === null) { | ||
@@ -444,18 +441,16 @@ throw Error("invaliding encoding"); | ||
return codePoint; | ||
}; | ||
AnsiStringType.prototype.get = function (buf, off) { | ||
if (off === void 0) { off = 0; } | ||
} | ||
get(buf, 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; | ||
}()); | ||
} | ||
} | ||
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]; | ||
exports.AnsiStringType = AnsiStringType; | ||
@@ -469,5 +464,5 @@ /** | ||
byteLength = byteLength >>> 0; | ||
var val = buf[offset]; | ||
var mul = 1; | ||
var i = 0; | ||
let val = buf[offset]; | ||
let mul = 1; | ||
let i = 0; | ||
while (++i < byteLength && (mul *= 0x100)) { | ||
@@ -486,4 +481,4 @@ val += buf[offset + i] * mul; | ||
byteLength = byteLength >>> 0; | ||
var mul = 1; | ||
var i = 0; | ||
let mul = 1; | ||
let i = 0; | ||
buf[offset] = value & 0xFF; | ||
@@ -502,5 +497,5 @@ while (++i < byteLength && (mul *= 0x100)) { | ||
byteLength = byteLength >>> 0; | ||
var val = buf[offset]; | ||
var mul = 1; | ||
var i = 0; | ||
let val = buf[offset]; | ||
let mul = 1; | ||
let i = 0; | ||
while (++i < byteLength && (mul *= 0x100)) { | ||
@@ -521,5 +516,5 @@ val += buf[offset + i] * mul; | ||
offset = offset >>> 0; | ||
var i = 0; | ||
var mul = 1; | ||
var sub = 0; | ||
let i = 0; | ||
let mul = 1; | ||
let sub = 0; | ||
buf[offset] = value & 0xFF; | ||
@@ -542,4 +537,4 @@ while (++i < byteLength && (mul *= 0x100)) { | ||
byteLength = byteLength >>> 0; | ||
var val = buf[offset + --byteLength]; | ||
var mul = 1; | ||
let val = buf[offset + --byteLength]; | ||
let mul = 1; | ||
while (byteLength > 0 && (mul *= 0x100)) { | ||
@@ -559,4 +554,4 @@ val += buf[offset + --byteLength] * mul; | ||
byteLength = byteLength >>> 0; | ||
var i = byteLength - 1; | ||
var mul = 1; | ||
let i = byteLength - 1; | ||
let mul = 1; | ||
buf[offset + i] = value & 0xFF; | ||
@@ -576,5 +571,5 @@ while (--i >= 0 && (mul *= 0x100)) { | ||
byteLength = byteLength >>> 0; | ||
var i = byteLength; | ||
var mul = 1; | ||
var val = buf[offset + --i]; | ||
let i = byteLength; | ||
let mul = 1; | ||
let val = buf[offset + --i]; | ||
while (i > 0 && (mul *= 0x100)) { | ||
@@ -596,5 +591,5 @@ val += buf[offset + --i] * mul; | ||
offset = offset >>> 0; | ||
var i = byteLength - 1; | ||
var mul = 1; | ||
var sub = 0; | ||
let i = byteLength - 1; | ||
let mul = 1; | ||
let sub = 0; | ||
buf[offset + i] = value & 0xFF; | ||
@@ -601,0 +596,0 @@ while (--i >= 0 && (mul *= 0x100)) { |
{ | ||
"name": "token-types", | ||
"version": "0.10.0", | ||
"version": "1.0.0", | ||
"description": "Common token types for decoding and encoding binairy values", | ||
@@ -10,10 +10,11 @@ "author": { | ||
"scripts": { | ||
"build": "yarn run compile", | ||
"compile-src": "tsc -p src", | ||
"compile-test": "tsc -p test", | ||
"compile": "npm run compile-src && npm run compile-test", | ||
"prepare": "npm run compile", | ||
"compile": "yarn run compile-src && yarn run compile-test", | ||
"prepare": "yarn run compile", | ||
"lint": "tslint 'src/**/*.ts' --exclude 'src/**/*.d.ts' 'test/**/*.ts' --exclude 'test/**/*.d.ts'", | ||
"test": "mocha --require ts-node/register test", | ||
"cover-test": "nyc npm run test", | ||
"coveralls": "npm run cover-test && nyc report --reporter=text-lcov | coveralls" | ||
"cover-test": "nyc yarn run test", | ||
"coveralls": "yarn run cover-test && nyc report --reporter=text-lcov | coveralls" | ||
}, | ||
@@ -36,3 +37,3 @@ "engines": { | ||
"@types/mocha": "^5.2.5", | ||
"@types/node": "^10.7.1", | ||
"@types/node": "^10.9.4", | ||
"chai": "^4.1.2", | ||
@@ -42,8 +43,8 @@ "copyfiles": "^2.0.0", | ||
"mocha": "^5.2.0", | ||
"nyc": "^12.0.2", | ||
"nyc": "^13.0.1", | ||
"ts-node": "^7.0.1", | ||
"tslint": "^5.10.0", | ||
"typescript": "^3.0.1" | ||
"tslint": "^5.11.0", | ||
"typescript": "^3.0.3" | ||
}, | ||
"dependencies": {} | ||
} |
Sorry, the diff of this file is not supported yet
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
81990
744