@gmb/bitmark-parser 6.1.4 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { createRequire } from "module";
10
10
  // src/generated/package_info.ts
11
11
  var PACKAGE_INFO = {
12
12
  "name": "@gmb/bitmark-parser",
13
- "version": "6.1.4",
13
+ "version": "6.2.0",
14
14
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
15
15
  "license": "ISC",
16
16
  "description": "A parser for bitmark text, powered by WebAssembly."
@@ -50,7 +50,7 @@ function buildUnits(wasm2, input, inputIsBitmark) {
50
50
  if (isError(out)) throw new Error(out);
51
51
  const envelopes = JSON.parse(out);
52
52
  return envelopes.map((env, index) => ({
53
- view: { format: "json", index, total: envelopes.length, bit: env.bit },
53
+ view: { format: "json", index, total: envelopes.length, bit: env.bit ?? {} },
54
54
  // Per-bit transform consumes a one-bit JSON document.
55
55
  source: JSON.stringify([env])
56
56
  }));
@@ -1291,6 +1291,11 @@ var StringWriter = stubClass("StringWriter", INTERNAL_REASON);
1291
1291
  var FileWriter = stubClass("FileWriter", INTERNAL_REASON);
1292
1292
  var StreamWriter = stubClass("StreamWriter", INTERNAL_REASON);
1293
1293
 
1294
+ // src/types.ts
1295
+ function patchEntry(path2, op, value) {
1296
+ return value === void 0 ? { path: path2, op } : { path: path2, op, value };
1297
+ }
1298
+
1294
1299
  // src/index.ts
1295
1300
  var require2 = createRequire(import.meta.url);
1296
1301
  var wasm = require2("../wasm/bitmark_wasm.js");
@@ -1304,6 +1309,19 @@ function lex(input, options = {}) {
1304
1309
  function parse(input, options = {}) {
1305
1310
  return wasm.parse(input, options.mode ?? "optimized");
1306
1311
  }
1312
+ function parseBits(input, options = {}) {
1313
+ const out = wasm.convert(input, "auto", "json", options.mode ?? "optimized", false, 2, 1);
1314
+ if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
1315
+ return JSON.parse(out);
1316
+ }
1317
+ function generateBits(bits, options = {}) {
1318
+ const entries = bits.map(
1319
+ (b) => b !== null && typeof b === "object" && "bit" in b && typeof b.bit === "object" ? b : { bit: b }
1320
+ );
1321
+ const out = wasm.convert(JSON.stringify(entries), "json", "bitmark", options.mode ?? "optimized", false, 2, 1);
1322
+ if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
1323
+ return out;
1324
+ }
1307
1325
  function convert(input, options = {}) {
1308
1326
  return wasm.convert(
1309
1327
  input,
@@ -1388,11 +1406,14 @@ export {
1388
1406
  expand,
1389
1407
  fullize,
1390
1408
  generate,
1409
+ generateBits,
1391
1410
  info,
1392
1411
  legacy_exports as legacy,
1393
1412
  lex,
1394
1413
  optimize,
1395
1414
  parse,
1415
+ parseBits,
1416
+ patchEntry,
1396
1417
  splitBits,
1397
1418
  transform,
1398
1419
  transformParallel,