Detalhes do pacote

@hanazuki/node-jsonnet

hanazuki843MIT AND Apache-2.03.0.0

Jsonnet addon for Node.js

jsonnet, node-addon, native, bindings

readme (leia-me)

node-jsonnet

@hanazuki/node-jsonnet is a libjsonnet binding for Node.js (native addon), which supports all the basic Jsonnet functionality including import and native callbacks (std.native). It also comes with TypeScript type definitions.

Synopsis

import { Jsonnet } from "@hanazuki/node-jsonnet";
const jsonnet = new Jsonnet();

// Evaluates a simple Jsonnet program into a JSON value
jsonnet.evaluateSnippet(`{a: 1 + 2, b: self.a * 3}`)
       .then(json => console.log(JSON.parse(json)));  // => { a: 3, b: 9 }

// Jsonnet programs can use JavaScript values through external variables (std.extVar)
// and native callbacks (std.native).
jsonnet.extCode("x", "4")
       .nativeCallback("add", (a, b) => Number(a) + Number(b), "a", "b")
       .evaluateSnippet(`std.extVar("x") * std.native("add")(1, 2)`)
       .then(json => console.log(JSON.parse(json)));  // => 12

The library is documented in the TypeScript type definitions at types/index.d.ts, and HTML documentation is also available online.

Installation Requirements

  • Node.js v20 or later
  • GCC or Clang C++ compiler that supports C++17
  • CMake 3.10 or later

License

@hanazuki/node-jsonnet is licensed under the MIT License (See LICENSE file for the terms). libjsonnet, whose source code is bundled in the distributed NPM packages of @hanazuki/node-jsonnet, is licensed under the Apache License, Version 2.0 (See third_party/jsonnet/LICENSE in this package or LICENSE file in the original repository). libjsonnet also bundles third-party software that is subject to other OSS licenses.

changelog (log de mudanças)

ChangeLog

v3.0.0 (2025-05-08)

  • [breaking] Node.js v14, v16 and v18 are no longer supported.
  • Update libjsonnet to v0.21.0.

v2.1.0 (2023-04-18)

v2.0.0 (2022-10-27)

  • [breaking] Node.js v10 and v12 are no longer supported.
  • Update libjsonnet to v0.19.0

v1.0.0 (2021-12-22)

v0.4.2 (2021-01-11)

  • Provide ES Module interface for Node.js >= 12 (#17)
  • Fix regression that using a native callback makes the program never finish (#18)

v0.4.1 (2020-11-23)

v0.4.0 (2020-09-04)

  • [breaking] NAPI_VERSION >= 6 is required
  • Fixed to work in multi-context application (worker threads)
  • Jsonnet.prototype.evaluate* methods now return evaluation errors as JsonnetError objects

v0.3.3 (2020-05-25)

v0.3.2 (2020-05-03)

  • Fixe bug where throwing in a native callback kills Node.js VM (such as jsonnet.nativeCallback("fun", () => { throw "fail"; })).

v0.3.1 (2020-05-03)

  • Updated dependencies.

v0.3.0 (2020-03-13)

  • Added Jsonnet.prototype.evaluateFileMulti, Jsonnet.prototype.evaluateSnippetMulti.
  • Added Jsonnet.prototype.evaluateFileStream, Jsonnet.prototype.evaluateSnippetStream.
  • Added Jsonnet.prototype.stringOutput.

v0.2.0

v0.1.1

v0.1.0