@qnighy/marshal
Advanced tools
Comparing version 0.1.2 to 0.1.3
## Unreleased | ||
## 0.1.3 | ||
- It no longer depends on `Buffer` from Node.js https://github.com/qnighy/marshal-js/pull/4 | ||
- Note that you need the globally-defined `TextDecoder` to decode non-ASCII strings. | ||
## 0.1.2 | ||
@@ -4,0 +9,0 @@ |
@@ -0,1 +1,2 @@ | ||
import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray"; | ||
import _classCallCheck from "@babel/runtime-corejs3/helpers/classCallCheck"; | ||
@@ -5,3 +6,3 @@ import _createClass from "@babel/runtime-corejs3/helpers/createClass"; | ||
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat"; | ||
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice"; | ||
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from"; | ||
import { MarshalError } from "./error"; | ||
@@ -31,3 +32,2 @@ /** | ||
this.index = index; | ||
this.buf = Buffer.from(this.buf); | ||
} | ||
@@ -389,3 +389,3 @@ | ||
var byte = this.buf.readUInt8(this.index); | ||
var byte = this.buf[this.index]; | ||
this.index++; | ||
@@ -397,3 +397,11 @@ return byte; | ||
value: function readString() { | ||
return this.readBytes().toString("utf-8"); | ||
var bytes = this.readBytes(); | ||
if (typeof TextDecoder !== "function" && bytes.every(function (x) { | ||
return x < 128; | ||
})) { | ||
return String.fromCharCode.apply(String, _toConsumableArray(_Array$from(bytes))); | ||
} | ||
return new TextDecoder().decode(bytes); | ||
} | ||
@@ -403,4 +411,2 @@ }, { | ||
value: function readBytes() { | ||
var _context2; | ||
var length = this.readLength("string"); | ||
@@ -412,4 +418,3 @@ | ||
var bytes = _sliceInstanceProperty(_context2 = this.buf).call(_context2, this.index, this.index + length); | ||
var bytes = this.buf.subarray(this.index, this.index + length); | ||
this.index += length; | ||
@@ -416,0 +421,0 @@ return bytes; |
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
/** | ||
@@ -8,2 +7,2 @@ * Parses a data exported by Ruby's `Marshal.load`. | ||
*/ | ||
export declare function parse(buf: Buffer): unknown; | ||
export declare function parse(buf: Uint8Array): unknown; |
@@ -12,4 +12,6 @@ "use strict"; | ||
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice")); | ||
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from")); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/toConsumableArray")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck")); | ||
@@ -41,3 +43,2 @@ | ||
this.index = index; | ||
this.buf = Buffer.from(this.buf); | ||
} | ||
@@ -399,3 +400,3 @@ | ||
var byte = this.buf.readUInt8(this.index); | ||
var byte = this.buf[this.index]; | ||
this.index++; | ||
@@ -407,3 +408,11 @@ return byte; | ||
value: function readString() { | ||
return this.readBytes().toString("utf-8"); | ||
var bytes = this.readBytes(); | ||
if (typeof TextDecoder !== "function" && bytes.every(function (x) { | ||
return x < 128; | ||
})) { | ||
return String.fromCharCode.apply(String, (0, _toConsumableArray2.default)((0, _from.default)(bytes))); | ||
} | ||
return new TextDecoder().decode(bytes); | ||
} | ||
@@ -413,4 +422,2 @@ }, { | ||
value: function readBytes() { | ||
var _context2; | ||
var length = this.readLength("string"); | ||
@@ -422,3 +429,3 @@ | ||
var bytes = (0, _slice.default)(_context2 = this.buf).call(_context2, this.index, this.index + length); | ||
var bytes = this.buf.subarray(this.index, this.index + length); | ||
this.index += length; | ||
@@ -425,0 +432,0 @@ return bytes; |
{ | ||
"name": "@qnighy/marshal", | ||
"description": "Decoder for Ruby's Marshal", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"license": "MIT", | ||
@@ -37,4 +37,3 @@ "homepage": "https://github.com/qnighy/marshal-js", | ||
"dependencies": { | ||
"@babel/runtime-corejs3": "^7.14.9", | ||
"@types/node": "^16.4.11" | ||
"@babel/runtime-corejs3": "^7.14.9" | ||
}, | ||
@@ -48,2 +47,3 @@ "devDependencies": { | ||
"@jest/globals": "^27.0.6", | ||
"@types/node": "^16.4.11", | ||
"@typescript-eslint/eslint-plugin": "^4.29.0", | ||
@@ -50,0 +50,0 @@ "@typescript-eslint/parser": "^4.29.0", |
@@ -18,3 +18,3 @@ ## `@qnighy/marshal` | ||
const buf = Buffer.from([ | ||
const buf = Uint8Array.from([ | ||
4, 8, 123, 7, 58, 9, 110, 97, 109, 101, 73, 34, 8, 102, 111, 111, 6, 58, 6, | ||
@@ -35,3 +35,3 @@ 69, 84, 58, 12, 110, 117, 109, 98, 101, 114, 115, 91, 8, 105, 6, 105, 7, 105, | ||
- Parameters | ||
- `buf`: `Buffer` <br> | ||
- `buf`: `Uint8Array` <br> | ||
a binary data to parse | ||
@@ -38,0 +38,0 @@ - Returns |
@@ -9,3 +9,3 @@ import { MarshalError } from "./error"; | ||
*/ | ||
export function parse(buf: Buffer): unknown { | ||
export function parse(buf: Uint8Array): unknown { | ||
return new Parser(buf).read(); | ||
@@ -19,5 +19,3 @@ } | ||
constructor(private buf: Buffer, private index = 0) { | ||
this.buf = Buffer.from(this.buf); | ||
} | ||
constructor(private buf: Uint8Array, private index = 0) {} | ||
@@ -291,3 +289,3 @@ public read(): unknown { | ||
} | ||
const byte = this.buf.readUInt8(this.index); | ||
const byte = this.buf[this.index]; | ||
this.index++; | ||
@@ -298,6 +296,10 @@ return byte; | ||
private readString(): string { | ||
return this.readBytes().toString("utf-8"); | ||
const bytes = this.readBytes(); | ||
if (typeof TextDecoder !== "function" && bytes.every((x) => x < 128)) { | ||
return String.fromCharCode(...Array.from(bytes)); | ||
} | ||
return new TextDecoder().decode(bytes); | ||
} | ||
private readBytes(): Buffer { | ||
private readBytes(): Uint8Array { | ||
const length = this.readLength("string"); | ||
@@ -307,3 +309,3 @@ if (this.index + length > this.buf.byteLength) { | ||
} | ||
const bytes = this.buf.slice(this.index, this.index + length); | ||
const bytes = this.buf.subarray(this.index, this.index + length); | ||
this.index += length; | ||
@@ -310,0 +312,0 @@ return bytes; |
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
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
39541
1
1079
0
15
- Removed@types/node@^16.4.11
- Removed@types/node@16.18.119(transitive)