@bare-ts/lib
Advanced tools
Comparing version 0.2.0 to 0.3.0
// src/codec/float-array.ts | ||
import { ok as assert } from "assert"; | ||
import { BareError } from "../core/index.js"; | ||
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js"; | ||
@@ -15,3 +13,2 @@ import { readFixedData } from "./data.js"; | ||
import { writeU8FixedArray } from "./u8-array.js"; | ||
var NAN_NOT_ALLOWED = "NaN is not allowed"; | ||
var readF32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readF32FixedArrayLE : readF32FixedArrayBE; | ||
@@ -21,5 +18,2 @@ function readF32FixedArrayLE(bc, len) { | ||
const result = new Float32Array(readFixedData(bc, byteLen)); | ||
if (result.some(Number.isNaN)) { | ||
throw new BareError(bc.offset, NAN_NOT_ALLOWED); | ||
} | ||
return result; | ||
@@ -36,3 +30,2 @@ } | ||
function writeF32FixedArrayLE(bc, x) { | ||
assert(!x.every(Number.isNaN), NAN_NOT_ALLOWED); | ||
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength)); | ||
@@ -58,5 +51,2 @@ } | ||
const result = new Float64Array(readFixedData(bc, byteLen)); | ||
if (result.some(Number.isNaN)) { | ||
throw new BareError(bc.offset, NAN_NOT_ALLOWED); | ||
} | ||
return result; | ||
@@ -73,3 +63,2 @@ } | ||
function writeF64FixedArrayLE(bc, x) { | ||
assert(!x.every(Number.isNaN), NAN_NOT_ALLOWED); | ||
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength)); | ||
@@ -76,0 +65,0 @@ } |
// src/codec/i16-array.ts | ||
import { I16_BYTE_COUNT } from "../util/constants.js"; | ||
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js"; | ||
@@ -6,3 +7,2 @@ import { readFixedData } from "./data.js"; | ||
import { writeU8FixedArray } from "./u8-array.js"; | ||
var I16_BYTE_COUNT = 2; | ||
var readI16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readI16FixedArrayLE : readI16FixedArrayBE; | ||
@@ -9,0 +9,0 @@ function readI16Array(bc) { |
// src/codec/i32-array.ts | ||
import { I32_BYTE_COUNT } from "../util/constants.js"; | ||
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js"; | ||
@@ -6,3 +7,2 @@ import { readFixedData } from "./data.js"; | ||
import { writeU8FixedArray } from "./u8-array.js"; | ||
var I32_BYTE_COUNT = 4; | ||
var readI32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readI32FixedArrayLE : readI32FixedArrayBE; | ||
@@ -9,0 +9,0 @@ function readI32Array(bc) { |
// src/codec/i64-array.ts | ||
import { I64_BYTE_COUNT } from "../util/constants.js"; | ||
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js"; | ||
@@ -6,3 +7,2 @@ import { readFixedData } from "./data.js"; | ||
import { writeU8FixedArray } from "./u8-array.js"; | ||
var I64_BYTE_COUNT = 8; | ||
var readI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readI64FixedArrayLE : readI64FixedArrayBE; | ||
@@ -9,0 +9,0 @@ function readI64Array(bc) { |
@@ -36,3 +36,1 @@ import { type ByteCursor } from "../core/index.js"; | ||
export declare function writeUintSafe(bc: ByteCursor, x: number): void; | ||
export declare function readVoid(_dc: ByteCursor): undefined; | ||
export declare function writeVoid(_dc: ByteCursor, _x: undefined): void; |
// src/codec/primitive.ts | ||
import { ok as assert } from "assert"; | ||
import { assert } from "../util/assert.js"; | ||
import { BareError } from "../core/index.js"; | ||
import { | ||
INT_SAFE_MAX_BYTE_COUNT, | ||
NON_CANONICAL_REPRESENTATION, | ||
TOO_LARGE_NUMBER, | ||
UINT_MAX_BYTE_COUNT, | ||
UINT_SAFE_MAX_BYTE_COUNT | ||
} from "../util/constants.js"; | ||
import { | ||
isI16, | ||
@@ -15,5 +22,2 @@ isI32, | ||
} from "../util/validator.js"; | ||
var NAN_NOT_ALLOWED = "NaN is not allowed"; | ||
var NON_CANONICAL_REPRESENTATION = "must be canonical"; | ||
var TOO_LARGE_NUMBER = "too large number"; | ||
function readBool(bc) { | ||
@@ -33,5 +37,2 @@ const val = readU8(bc); | ||
const result = bc.view.getFloat32(bc.offset, true); | ||
if (Number.isNaN(result)) { | ||
throw new BareError(bc.offset, NAN_NOT_ALLOWED); | ||
} | ||
bc.offset += 4; | ||
@@ -41,6 +42,5 @@ return result; | ||
function writeF32(bc, x) { | ||
assert(!Number.isNaN(x), NAN_NOT_ALLOWED); | ||
bc.reserve(4); | ||
bc.view.setFloat32(bc.offset, x, true); | ||
assert(Math.abs(bc.view.getFloat32(bc.offset, true) - x) <= Number.EPSILON, TOO_LARGE_NUMBER); | ||
assert(Number.isNaN(x) || Math.abs(bc.view.getFloat32(bc.offset, true) - x) <= Number.EPSILON, TOO_LARGE_NUMBER); | ||
bc.offset += 4; | ||
@@ -51,5 +51,2 @@ } | ||
const result = bc.view.getFloat64(bc.offset, true); | ||
if (Number.isNaN(result)) { | ||
throw new BareError(bc.offset, NAN_NOT_ALLOWED); | ||
} | ||
bc.offset += 8; | ||
@@ -59,3 +56,2 @@ return result; | ||
function writeF64(bc, x) { | ||
assert(!Number.isNaN(x), NAN_NOT_ALLOWED); | ||
bc.reserve(8); | ||
@@ -140,3 +136,2 @@ bc.view.setFloat64(bc.offset, x, true); | ||
} | ||
var INT_SAFE_MAX_BYTE_COUNT = 8; | ||
function readIntSafe(bc) { | ||
@@ -243,3 +238,2 @@ const firstByte = readU8(bc); | ||
} | ||
var UINT_MAX_BYTE_COUNT = 10; | ||
function readUint(bc) { | ||
@@ -290,3 +284,2 @@ let low = readU8(bc); | ||
} | ||
var UINT_SAFE_MAX_BYTE_COUNT = 8; | ||
function readUintSafe(bc) { | ||
@@ -324,7 +317,2 @@ let result = readU8(bc); | ||
} | ||
function readVoid(_dc) { | ||
return void 0; | ||
} | ||
function writeVoid(_dc, _x) { | ||
} | ||
export { | ||
@@ -348,3 +336,2 @@ readBool, | ||
readUintSafe, | ||
readVoid, | ||
writeBool, | ||
@@ -366,5 +353,4 @@ writeF32, | ||
writeUint, | ||
writeUintSafe, | ||
writeVoid | ||
writeUintSafe | ||
}; | ||
//# sourceMappingURL=primitive.js.map |
// src/codec/string.ts | ||
import { BareError } from "../core/bare-error.js"; | ||
import { INVALID_UTF8_STRING } from "../util/constants.js"; | ||
import { readUintSafe, writeUintSafe } from "./primitive.js"; | ||
import { writeU8FixedArray } from "./u8-array.js"; | ||
var INVALID_UTF8_STRING = "invalid UTF-8 string"; | ||
function readString(bc) { | ||
@@ -118,4 +118,4 @@ return readFixedString(bc, readUintSafe(bc)); | ||
} | ||
var UTF8_DECODER = new TextDecoder("utf-8", { fatal: true }); | ||
var UTF8_ENCODER = new TextEncoder(); | ||
var UTF8_DECODER = /* @__PURE__ */ new TextDecoder("utf-8", { fatal: true }); | ||
var UTF8_ENCODER = /* @__PURE__ */ new TextEncoder(); | ||
export { | ||
@@ -122,0 +122,0 @@ readFixedString, |
// src/codec/u16-array.ts | ||
import { U16_BYTE_COUNT } from "../util/constants.js"; | ||
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js"; | ||
@@ -6,3 +7,2 @@ import { readFixedData } from "./data.js"; | ||
import { writeU8FixedArray } from "./u8-array.js"; | ||
var U16_BYTE_COUNT = 2; | ||
var readU16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readU16FixedArrayLE : readU16FixedArrayBE; | ||
@@ -9,0 +9,0 @@ function readU16Array(bc) { |
// src/codec/u32-array.ts | ||
import { U32_BYTE_COUNT } from "../util/constants.js"; | ||
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js"; | ||
@@ -6,3 +7,2 @@ import { readFixedData } from "./data.js"; | ||
import { writeU8FixedArray } from "./u8-array.js"; | ||
var U32_BYTE_COUNT = 4; | ||
var readU32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readU32FixedArrayLE : readU32FixedArrayBE; | ||
@@ -9,0 +9,0 @@ function readU32Array(bc) { |
// src/codec/u64-array.ts | ||
import { U64_BYTE_COUNT } from "../util/constants.js"; | ||
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js"; | ||
@@ -6,3 +7,2 @@ import { readFixedData } from "./data.js"; | ||
import { writeU8FixedArray } from "./u8-array.js"; | ||
var U64_BYTE_COUNT = 8; | ||
var readU64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readU64FixedArrayLE : readU64FixedArrayBE; | ||
@@ -9,0 +9,0 @@ function readU64Array(bc) { |
// src/core/byte-cursor.ts | ||
import { TOO_LARGE_BUFFER } from "../util/constants.js"; | ||
import { BareError } from "./bare-error.js"; | ||
var TOO_LARGE_BUFFER = "too large buffer"; | ||
var ByteCursor = class { | ||
@@ -5,0 +5,0 @@ constructor(bytes, config) { |
@@ -7,2 +7,7 @@ export interface Config { | ||
} | ||
export declare function Config(part: Partial<Config>): Config; | ||
export declare function Config({ initialBufferLength, maxBufferLength, textDecoderThreshold, textEncoderThreshold, }: { | ||
initialBufferLength?: number | undefined; | ||
maxBufferLength?: number | undefined; | ||
textDecoderThreshold?: number | undefined; | ||
textEncoderThreshold?: number | undefined; | ||
}): Config; |
// src/core/config.ts | ||
import { ok as assert } from "assert"; | ||
import { assert } from "../util/assert.js"; | ||
import { TOO_LARGE_NUMBER } from "../util/constants.js"; | ||
import { isU32 } from "../util/validator.js"; | ||
var TOO_LARGE_NUMBER = "too large number"; | ||
var initialBufferLength = 1024; | ||
var maxBufferLength = 1024 * 1024 * 32; | ||
var textDecoderThreshold = 256; | ||
var textEncoderThreshold = 256; | ||
function Config(part) { | ||
const config = Object.assign({ | ||
function Config({ | ||
initialBufferLength = 1024, | ||
maxBufferLength = 1024 * 1024 * 32, | ||
textDecoderThreshold = 256, | ||
textEncoderThreshold = 256 | ||
}) { | ||
const config = { | ||
initialBufferLength, | ||
@@ -15,3 +16,3 @@ maxBufferLength, | ||
textEncoderThreshold | ||
}, part); | ||
}; | ||
assert(isU32(config.initialBufferLength), TOO_LARGE_NUMBER); | ||
@@ -18,0 +19,0 @@ assert(isU32(config.maxBufferLength), TOO_LARGE_NUMBER); |
@@ -5,3 +5,7 @@ export declare class AssertionError extends Error { | ||
} | ||
export default function assert(test: boolean, message: Error | string): asserts test; | ||
export declare const ok: typeof assert; | ||
export declare function assert(test: boolean, message: string): asserts test; | ||
declare const Error: V8ErrorConstructor; | ||
interface V8ErrorConstructor extends ErrorConstructor { | ||
readonly captureStackTrace?: (e: Error, f: unknown) => void; | ||
} | ||
export {}; |
@@ -10,5 +10,2 @@ // src/util/assert.ts | ||
if (!test) { | ||
if (message instanceof Error) { | ||
throw message; | ||
} | ||
const e = new AssertionError(message); | ||
@@ -21,8 +18,6 @@ if (Error.captureStackTrace) { | ||
} | ||
var ok = assert; | ||
export { | ||
AssertionError, | ||
assert as default, | ||
ok | ||
assert | ||
}; | ||
//# sourceMappingURL=assert.js.map |
// src/util/util.ts | ||
var IS_LITTLE_ENDIAN_PLATFORM = new DataView(Uint16Array.of(1).buffer).getUint8(0) === 1; | ||
var IS_LITTLE_ENDIAN_PLATFORM = /* @__PURE__ */ new DataView(Uint16Array.of(1).buffer).getUint8(0) === 1; | ||
export { | ||
@@ -4,0 +4,0 @@ IS_LITTLE_ENDIAN_PLATFORM |
{ | ||
"name": "@bare-ts/lib", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "TypeScript library for BARE, a compact and simple binary-serialization format", | ||
@@ -31,8 +31,5 @@ "keywords": [ | ||
"types": "./dist/index.d.ts", | ||
"browser": { | ||
"assert": "./dist/util/assert.js" | ||
}, | ||
"exports": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs" | ||
"require": "./dist/index.cjs", | ||
"default": "./dist/index.js" | ||
}, | ||
@@ -54,2 +51,3 @@ "sideEffects": false, | ||
"clean": "rm -rf dist coverage", | ||
"prepare": "validate-commit-msg", | ||
"prepublishOnly": "npm run clean && npm test", | ||
@@ -66,3 +64,2 @@ "test": "npm run build && tsc -b tests && oletus tests/**/*.test.js", | ||
"devDependencies": { | ||
"@types/node": "^17.0.6", | ||
"esbuild": "~0.14.10", | ||
@@ -69,0 +66,0 @@ "oletus": "^3.2.0", |
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
5
50
87697
2408