/source-map

Source Map, based on TC39 spec reference implementation

MIT LicenseMIT

source-map

🚧 WIP at beta branch

Source Map, based on TC39 spec reference implementation.

Based on 18 September 2024 update.

Table of Contents

Install

deno:

deno add @miyauci/source-map

node:

npx jsr add @miyauci/source-map

Usage

Here are some modules.

decodeSourceMapFromJSONString is the implementation of decode a source map from a JSON string.

import { decodeSourceMapFromJSONString } from "@miyauci/source-map";

const sourceMap = `{
  "version": 3,
  "file": "helloworld.js",
  "sources": [
    "helloworld.coffee"
  ],
  "names": [],
  "mappings": "AAAA;AAAA,EAAA,OAAO,CAAC,GAAR,CAAY,aAAZ,CAAA,CAAA;AAAA"
}`;
declare const baseURL: URL;

const decodedSourceMap = decodeSourceMapFromJSONString(sourceMap, baseURL);

extractSourceMapURLWithoutParsing is the implementation of extract a Source Map URL from JavaScript without parsing.

import { extractSourceMapURLWithoutParsing } from "@miyauci/source-map";
import { expect } from "@std/expect";

const source = `// Here is source code

//# sourceMappingURL=foo.js.map
`;

const urlString = extractSourceMapURLWithoutParsing(source);
expect(urlString).toBe("foo.js.map");

For all modules, see API section.

API

See jsr doc for all APIs.

Contributing

See CONTRIBUTING.md

License

MIT © 2024 Tomoki Miyauchi