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

micro-packed

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micro-packed - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3

10

debugger.ts

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

import * as base from '@scure/base';
import { base64, hex } from '@scure/base';
import * as P from './index.js';

@@ -63,6 +63,6 @@

try {
return base.base64.decode(data);
return base64.decode(data);
} catch (e) {}
try {
return base.hex.decode(data);
return hex.decode(data);
} catch (e) {}

@@ -152,3 +152,3 @@ throw new Error(`PD: data has unknown string format: ${data}`);

for (let i = 0; i < data.length; i += perLine) {
res.push(base.hex.encode(data.slice(i, i + perLine)));
res.push(hex.encode(data.slice(i, i + perLine)));
}

@@ -159,3 +159,3 @@ return res.map((i) => `${bold}${i}${reset}`).join('\n');

function fmtValue(value: any) {
if (P.isBytes(value)) return `b(${green}${base.hex.encode(value)}${reset} len=${value.length})`;
if (P.isBytes(value)) return `b(${green}${hex.encode(value)}${reset} len=${value.length})`;
if (typeof value === 'string') return `s(${green}"${value}"${reset} len=${value.length})`;

@@ -162,0 +162,0 @@ if (typeof value === 'number' || typeof value === 'bigint') return `n(${value})`;

@@ -24,2 +24,9 @@ import { base64, bytes as baseBytes, hex as baseHex, str as baseStr, utf8 } from '@scure/base';

export function isBytes(a: unknown): a is Bytes {
return (
a instanceof Uint8Array ||
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')
);
}
/**

@@ -44,9 +51,2 @@ * Copies several Uint8Arrays into one.

export function isBytes(a: unknown): a is Bytes {
return (
a instanceof Uint8Array ||
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')
);
}
// Types

@@ -126,3 +126,3 @@ export type Bytes = Uint8Array;

// [0-32, 64-128], which means 'pos' is not enough to handle them
const _bitset = /* @__PURE__ */ {
const _bitset = {
BITS: 32,

@@ -488,2 +488,4 @@ FULL_MASK: -1 >>> 0, // 1<<32 will overflow

return (
elm !== null &&
typeof elm === 'object' &&
typeof (elm as CoderType<T>).encode === 'function' &&

@@ -669,16 +671,16 @@ typeof (elm as CoderType<T>).encodeStream === 'function' &&

export const U256LE = bigint(32, true);
export const U256BE = bigint(32, false);
export const I256LE = bigint(32, true, true);
export const I256BE = bigint(32, false, true);
export const U256LE = /* @__PURE__ */ bigint(32, true);
export const U256BE = /* @__PURE__ */ bigint(32, false);
export const I256LE = /* @__PURE__ */ bigint(32, true, true);
export const I256BE = /* @__PURE__ */ bigint(32, false, true);
export const U128LE = bigint(16, true);
export const U128BE = bigint(16, false);
export const I128LE = bigint(16, true, true);
export const I128BE = bigint(16, false, true);
export const U128LE = /* @__PURE__ */ bigint(16, true);
export const U128BE = /* @__PURE__ */ bigint(16, false);
export const I128LE = /* @__PURE__ */ bigint(16, true, true);
export const I128BE = /* @__PURE__ */ bigint(16, false, true);
export const U64LE = bigint(8, true);
export const U64BE = bigint(8, false);
export const I64LE = bigint(8, true, true);
export const I64BE = bigint(8, false, true);
export const U64LE = /* @__PURE__ */ bigint(8, true);
export const U64BE = /* @__PURE__ */ bigint(8, false);
export const I64LE = /* @__PURE__ */ bigint(8, true, true);
export const I64BE = /* @__PURE__ */ bigint(8, false, true);

@@ -692,16 +694,16 @@ // TODO: we can speed-up if integers are used. Unclear if it's worth to increase code size.

export const U32LE = int(4, true);
export const U32BE = int(4, false);
export const I32LE = int(4, true, true);
export const I32BE = int(4, false, true);
export const U32LE = /* @__PURE__ */ int(4, true);
export const U32BE = /* @__PURE__ */ int(4, false);
export const I32LE = /* @__PURE__ */ int(4, true, true);
export const I32BE = /* @__PURE__ */ int(4, false, true);
export const U16LE = int(2, true);
export const U16BE = int(2, false);
export const I16LE = int(2, true, true);
export const I16BE = int(2, false, true);
export const U16LE = /* @__PURE__ */ int(2, true);
export const U16BE = /* @__PURE__ */ int(2, false);
export const I16LE = /* @__PURE__ */ int(2, true, true);
export const I16BE = /* @__PURE__ */ int(2, false, true);
export const U8 = int(1, false);
export const I8 = int(1, false, true);
export const U8 = /* @__PURE__ */ int(1, false);
export const I8 = /* @__PURE__ */ int(1, false, true);
export const bool: CoderType<boolean> = wrap({
export const bool: CoderType<boolean> = /* @__PURE__ */ wrap({
size: 1,

@@ -748,3 +750,3 @@ encodeStream: (w: Writer, value: boolean) => w.byte(value ? 1 : 0),

export const cstring = string(NULL);
export const cstring = /* @__PURE__ */ string(NULL);

@@ -1155,4 +1157,5 @@ export const hex = (len: Length, le = false, withZero = false): CoderType<string> => {

for (const key in variants) {
mapValue[key] = variants[key][0];
tagValue[key] = variants[key][1];
const v = variants[key];
mapValue[key] = v[0];
tagValue[key] = v[1];
}

@@ -1287,5 +1290,6 @@ return tag(map(tagCoder, mapValue), tagValue) as any as CoderType<T>;

lines = lines.map((l) => l.replace('\r', '').trim());
if (checksum && lines[lines.length - 1].startsWith('=')) {
const last = lines.length - 1;
if (checksum && lines[last].startsWith('=')) {
const body = base64.decode(lines.slice(0, -1).join(''));
const cs = lines[lines.length - 1].slice(1);
const cs = lines[last].slice(1);
const realCS = base64.encode(checksum(body));

@@ -1302,3 +1306,3 @@ if (realCS !== cs)

// Does nothing at all
export const nothing = magic(bytes(0), EMPTY);
export const nothing = /* @__PURE__ */ magic(/* @__PURE__ */ bytes(0), EMPTY);

@@ -1305,0 +1309,0 @@ export function debug<T>(inner: CoderType<T>): CoderType<T> {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.diff = exports.decode = exports.table = void 0;
const base = require("@scure/base");
const base_1 = require("@scure/base");
const P = require("./index.js");

@@ -73,7 +73,7 @@ const UNKNOWN = '(???)';

try {
return base.base64.decode(data);
return base_1.base64.decode(data);
}
catch (e) { }
try {
return base.hex.decode(data);
return base_1.hex.decode(data);
}

@@ -157,3 +157,3 @@ catch (e) { }

for (let i = 0; i < data.length; i += perLine) {
res.push(base.hex.encode(data.slice(i, i + perLine)));
res.push(base_1.hex.encode(data.slice(i, i + perLine)));
}

@@ -164,3 +164,3 @@ return res.map((i) => `${bold}${i}${reset}`).join('\n');

if (P.isBytes(value))
return `b(${green}${base.hex.encode(value)}${reset} len=${value.length})`;
return `b(${green}${base_1.hex.encode(value)}${reset} len=${value.length})`;
if (typeof value === 'string')

@@ -167,0 +167,0 @@ return `s(${green}"${value}"${reset} len=${value.length})`;

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

import * as base from '@scure/base';
import { base64, hex } from '@scure/base';
import * as P from './index.js';

@@ -70,7 +70,7 @@ const UNKNOWN = '(???)';

try {
return base.base64.decode(data);
return base64.decode(data);
}
catch (e) { }
try {
return base.hex.decode(data);
return hex.decode(data);
}

@@ -153,3 +153,3 @@ catch (e) { }

for (let i = 0; i < data.length; i += perLine) {
res.push(base.hex.encode(data.slice(i, i + perLine)));
res.push(hex.encode(data.slice(i, i + perLine)));
}

@@ -160,3 +160,3 @@ return res.map((i) => `${bold}${i}${reset}`).join('\n');

if (P.isBytes(value))
return `b(${green}${base.hex.encode(value)}${reset} len=${value.length})`;
return `b(${green}${hex.encode(value)}${reset} len=${value.length})`;
if (typeof value === 'string')

@@ -163,0 +163,0 @@ return `s(${green}"${value}"${reset} len=${value.length})`;

@@ -22,2 +22,6 @@ import { base64, bytes as baseBytes, hex as baseHex, str as baseStr, utf8 } from '@scure/base';

}
export function isBytes(a) {
return (a instanceof Uint8Array ||
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
}
/**

@@ -42,6 +46,2 @@ * Copies several Uint8Arrays into one.

}
export function isBytes(a) {
return (a instanceof Uint8Array ||
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
}
// Utils

@@ -54,3 +54,3 @@ // Small bitset structure to store position of ranges that have been read.

// [0-32, 64-128], which means 'pos' is not enough to handle them
const _bitset = /* @__PURE__ */ {
const _bitset = {
BITS: 32,

@@ -439,3 +439,5 @@ FULL_MASK: -1 >>> 0, // 1<<32 will overflow

export function isCoder(elm) {
return (typeof elm.encode === 'function' &&
return (elm !== null &&
typeof elm === 'object' &&
typeof elm.encode === 'function' &&
typeof elm.encodeStream === 'function' &&

@@ -611,14 +613,14 @@ typeof elm.decode === 'function' &&

});
export const U256LE = bigint(32, true);
export const U256BE = bigint(32, false);
export const I256LE = bigint(32, true, true);
export const I256BE = bigint(32, false, true);
export const U128LE = bigint(16, true);
export const U128BE = bigint(16, false);
export const I128LE = bigint(16, true, true);
export const I128BE = bigint(16, false, true);
export const U64LE = bigint(8, true);
export const U64BE = bigint(8, false);
export const I64LE = bigint(8, true, true);
export const I64BE = bigint(8, false, true);
export const U256LE = /* @__PURE__ */ bigint(32, true);
export const U256BE = /* @__PURE__ */ bigint(32, false);
export const I256LE = /* @__PURE__ */ bigint(32, true, true);
export const I256BE = /* @__PURE__ */ bigint(32, false, true);
export const U128LE = /* @__PURE__ */ bigint(16, true);
export const U128BE = /* @__PURE__ */ bigint(16, false);
export const I128LE = /* @__PURE__ */ bigint(16, true, true);
export const I128BE = /* @__PURE__ */ bigint(16, false, true);
export const U64LE = /* @__PURE__ */ bigint(8, true);
export const U64BE = /* @__PURE__ */ bigint(8, false);
export const I64LE = /* @__PURE__ */ bigint(8, true, true);
export const I64BE = /* @__PURE__ */ bigint(8, false, true);
// TODO: we can speed-up if integers are used. Unclear if it's worth to increase code size.

@@ -631,13 +633,13 @@ // Also, numbers can't use >= 32 bits.

};
export const U32LE = int(4, true);
export const U32BE = int(4, false);
export const I32LE = int(4, true, true);
export const I32BE = int(4, false, true);
export const U16LE = int(2, true);
export const U16BE = int(2, false);
export const I16LE = int(2, true, true);
export const I16BE = int(2, false, true);
export const U8 = int(1, false);
export const I8 = int(1, false, true);
export const bool = wrap({
export const U32LE = /* @__PURE__ */ int(4, true);
export const U32BE = /* @__PURE__ */ int(4, false);
export const I32LE = /* @__PURE__ */ int(4, true, true);
export const I32BE = /* @__PURE__ */ int(4, false, true);
export const U16LE = /* @__PURE__ */ int(2, true);
export const U16BE = /* @__PURE__ */ int(2, false);
export const I16LE = /* @__PURE__ */ int(2, true, true);
export const I16BE = /* @__PURE__ */ int(2, false, true);
export const U8 = /* @__PURE__ */ int(1, false);
export const I8 = /* @__PURE__ */ int(1, false, true);
export const bool = /* @__PURE__ */ wrap({
size: 1,

@@ -687,3 +689,3 @@ encodeStream: (w, value) => w.byte(value ? 1 : 0),

};
export const cstring = string(NULL);
export const cstring = /* @__PURE__ */ string(NULL);
export const hex = (len, le = false, withZero = false) => {

@@ -1080,4 +1082,5 @@ const inner = bytes(len, le);

for (const key in variants) {
mapValue[key] = variants[key][0];
tagValue[key] = variants[key][1];
const v = variants[key];
mapValue[key] = v[0];
tagValue[key] = v[1];
}

@@ -1200,5 +1203,6 @@ return tag(map(tagCoder, mapValue), tagValue);

lines = lines.map((l) => l.replace('\r', '').trim());
if (checksum && lines[lines.length - 1].startsWith('=')) {
const last = lines.length - 1;
if (checksum && lines[last].startsWith('=')) {
const body = base64.decode(lines.slice(0, -1).join(''));
const cs = lines[lines.length - 1].slice(1);
const cs = lines[last].slice(1);
const realCS = base64.encode(checksum(body));

@@ -1214,3 +1218,3 @@ if (realCS !== cs)

// Does nothing at all
export const nothing = magic(bytes(0), EMPTY);
export const nothing = /* @__PURE__ */ magic(/* @__PURE__ */ bytes(0), EMPTY);
export function debug(inner) {

@@ -1217,0 +1221,0 @@ if (!isCoder(inner))

@@ -13,2 +13,3 @@ import type { Coder as BaseCoder } from '@scure/base';

export declare function equalBytes(a: Uint8Array, b: Uint8Array): boolean;
export declare function isBytes(a: unknown): a is Bytes;
/**

@@ -18,3 +19,2 @@ * Copies several Uint8Arrays into one.

export declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
export declare function isBytes(a: unknown): a is Bytes;
export type Bytes = Uint8Array;

@@ -21,0 +21,0 @@ export type Option<T> = T | undefined;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.magicBytes = exports.magic = exports.optional = exports.flagged = exports.flag = exports.bytesFormatted = exports.lazy = exports.validate = exports.apply = exports.hex = exports.cstring = exports.string = exports.bytes = exports.bool = exports.I8 = exports.U8 = exports.I16BE = exports.I16LE = exports.U16BE = exports.U16LE = exports.I32BE = exports.I32LE = exports.U32BE = exports.U32LE = exports.int = exports.I64BE = exports.I64LE = exports.U64BE = exports.U64LE = exports.I128BE = exports.I128LE = exports.U128BE = exports.U128LE = exports.I256BE = exports.I256LE = exports.U256BE = exports.U256LE = exports.bigint = exports.bits = exports.coders = exports.isCoder = exports.wrap = exports.checkBounds = exports.Writer = exports.Reader = exports.isBytes = exports.concatBytes = exports.equalBytes = exports.NULL = exports.EMPTY = void 0;
exports.magicBytes = exports.magic = exports.optional = exports.flagged = exports.flag = exports.bytesFormatted = exports.lazy = exports.validate = exports.apply = exports.hex = exports.cstring = exports.string = exports.bytes = exports.bool = exports.I8 = exports.U8 = exports.I16BE = exports.I16LE = exports.U16BE = exports.U16LE = exports.I32BE = exports.I32LE = exports.U32BE = exports.U32LE = exports.int = exports.I64BE = exports.I64LE = exports.U64BE = exports.U64LE = exports.I128BE = exports.I128LE = exports.U128BE = exports.U128LE = exports.I256BE = exports.I256LE = exports.U256BE = exports.U256LE = exports.bigint = exports.bits = exports.coders = exports.isCoder = exports.wrap = exports.checkBounds = exports.Writer = exports.Reader = exports.concatBytes = exports.isBytes = exports.equalBytes = exports.NULL = exports.EMPTY = void 0;
exports._TEST = exports.debug = exports.nothing = exports.base64armor = exports.pointer = exports.padRight = exports.padLeft = exports.ZeroPad = exports.bitset = exports.mappedTag = exports.tag = exports.map = exports.array = exports.prefix = exports.tuple = exports.struct = exports.constant = void 0;

@@ -27,2 +27,7 @@ const base_1 = require("@scure/base");

exports.equalBytes = equalBytes;
function isBytes(a) {
return (a instanceof Uint8Array ||
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
}
exports.isBytes = isBytes;
/**

@@ -48,7 +53,2 @@ * Copies several Uint8Arrays into one.

exports.concatBytes = concatBytes;
function isBytes(a) {
return (a instanceof Uint8Array ||
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
}
exports.isBytes = isBytes;
// Utils

@@ -61,3 +61,3 @@ // Small bitset structure to store position of ranges that have been read.

// [0-32, 64-128], which means 'pos' is not enough to handle them
const _bitset = /* @__PURE__ */ {
const _bitset = {
BITS: 32,

@@ -450,3 +450,5 @@ FULL_MASK: -1 >>> 0, // 1<<32 will overflow

function isCoder(elm) {
return (typeof elm.encode === 'function' &&
return (elm !== null &&
typeof elm === 'object' &&
typeof elm.encode === 'function' &&
typeof elm.encodeStream === 'function' &&

@@ -1111,4 +1113,5 @@ typeof elm.decode === 'function' &&

for (const key in variants) {
mapValue[key] = variants[key][0];
tagValue[key] = variants[key][1];
const v = variants[key];
mapValue[key] = v[0];
tagValue[key] = v[1];
}

@@ -1237,5 +1240,6 @@ return tag(map(tagCoder, mapValue), tagValue);

lines = lines.map((l) => l.replace('\r', '').trim());
if (checksum && lines[lines.length - 1].startsWith('=')) {
const last = lines.length - 1;
if (checksum && lines[last].startsWith('=')) {
const body = base_1.base64.decode(lines.slice(0, -1).join(''));
const cs = lines[lines.length - 1].slice(1);
const cs = lines[last].slice(1);
const realCS = base_1.base64.encode(checksum(body));

@@ -1252,3 +1256,3 @@ if (realCS !== cs)

// Does nothing at all
exports.nothing = magic((0, exports.bytes)(0), exports.EMPTY);
exports.nothing = magic(/* @__PURE__ */ (0, exports.bytes)(0), exports.EMPTY);
function debug(inner) {

@@ -1255,0 +1259,0 @@ if (!isCoder(inner))

{
"name": "micro-packed",
"version": "0.5.2",
"version": "0.5.3",
"description": "Define complex binary structures using composable primitives",

@@ -5,0 +5,0 @@ "files": [

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