# sourcemap-codec

> Encode/decode sourcemap mappings

Latest version **1.4.8** (published 2020-01-16) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install sourcemap-codec
pnpm add sourcemap-codec
yarn add sourcemap-codec
bun add sourcemap-codec
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.4.8 |
| Published | 2020-01-16 |
| First published | 2015-10-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 31.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 69 |
| Author | Rich Harris |
| Maintainers | rich_harris |
| Keywords | sourcemap, vlq |

## Links

- npm: https://www.npmjs.com/package/sourcemap-codec
- Repository: https://github.com/Rich-Harris/sourcemap-codec
- Issues: https://github.com/Rich-Harris/sourcemap-codec/issues
- npm.io page: https://npm.io/package/sourcemap-codec

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.4.8 (latest) — 2020-01-16
- 1.4.7 — 2020-01-03
- 1.4.6 — 2019-07-04
- 1.4.5 — 2019-07-03
- 1.4.4 — 2018-11-21
- 1.4.3 — 2018-09-20
- 1.4.2 — 2018-09-20
- 1.4.1 — 2018-03-13
- 1.4.0 — 2018-02-10
- 1.3.1 — 2017-04-13
- 1.3.0 — 2015-12-20
- 1.2.1 — 2015-10-23
- 1.2.0 — 2015-10-23
- 1.1.0 — 2015-10-18
- 1.0.0 — 2015-10-10

## README

# sourcemap-codec

Encode/decode the `mappings` property of a [sourcemap](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit).


## Why?

Sourcemaps are difficult to generate and manipulate, because the `mappings` property – the part that actually links the generated code back to the original source – is encoded using an obscure method called [Variable-length quantity](https://en.wikipedia.org/wiki/Variable-length_quantity). On top of that, each segment in the mapping contains offsets rather than absolute indices, which means that you can't look at a segment in isolation – you have to understand the whole sourcemap.

This package makes the process slightly easier.


## Installation

```bash
npm install sourcemap-codec
```


## Usage

```js
import { encode, decode } from 'sourcemap-codec';

var decoded = decode( ';EAEEA,EAAE,EAAC,CAAE;ECQY,UACC' );

assert.deepEqual( decoded, [
	// the first line (of the generated code) has no mappings,
	// as shown by the starting semi-colon (which separates lines)
	[],

	// the second line contains four (comma-separated) segments
	[
		// segments are encoded as you'd expect:
		// [ generatedCodeColumn, sourceIndex, sourceCodeLine, sourceCodeColumn, nameIndex ]

		// i.e. the first segment begins at column 2, and maps back to the second column
		// of the second line (both zero-based) of the 0th source, and uses the 0th
		// name in the `map.names` array
		[ 2, 0, 2, 2, 0 ],

		// the remaining segments are 4-length rather than 5-length,
		// because they don't map a name
		[ 4, 0, 2, 4 ],
		[ 6, 0, 2, 5 ],
		[ 7, 0, 2, 7 ]
	],

	// the final line contains two segments
	[
		[ 2, 1, 10, 19 ],
		[ 12, 1, 11, 20 ]
	]
]);

var encoded = encode( decoded );
assert.equal( encoded, ';EAEEA,EAAE,EAAC,CAAE;ECQY,UACC' );
```


# License

MIT

---
_Source: https://npm.io/package/sourcemap-codec · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
