4.1. Installation#
Adding the NPM package#
You can install Slang NPM package simply by running the following npm
command:
Or if you are using yarn
for package management:
ESM vs CommonJS#
Slang is implemented in Rust, and compiled as a WASM component, which is exposed to TypeScript/JavaScript, and loaded asynchronously. If you are working with a modern ESM project, this will just work out of the box, with no additional configuration needed.
use-from-esm.mts
import assert from "node:assert";
import { Parser } from "@nomicfoundation/slang/parser";
test("top-level ESM import", () => {
const parser = Parser.create("0.8.28");
assert(parser);
});
But if you are working with a legacy CommonJS project, asynchronous imports are not supported. In that case, you can use the await import()
syntax to load Slang: