Sha256: a0518850439a18196545934954064cc1859dcdba30123b5834e62e8e5bec2f40

Contents?: true

Size: 1.79 KB

Versions: 17

Compression:

Stored size: 1.79 KB

Contents

# 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

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
isomorfeus-preact-10.5.7 node_modules/sourcemap-codec/README.md
isomorfeus-preact-10.5.6 node_modules/sourcemap-codec/README.md
isomorfeus-preact-10.5.5 node_modules/sourcemap-codec/README.md
isomorfeus-preact-10.5.4 node_modules/sourcemap-codec/README.md
isomorfeus-preact-10.5.3 node_modules/sourcemap-codec/README.md
isomorfeus-preact-10.5.2 node_modules/sourcemap-codec/README.md
condenser-0.3 lib/condenser/processors/node_modules/sourcemap-codec/README.md
condenser-0.2 lib/condenser/processors/node_modules/sourcemap-codec/README.md
condenser-0.1 lib/condenser/processors/node_modules/sourcemap-codec/README.md
condenser-0.0.12 lib/condenser/processors/node_modules/sourcemap-codec/README.md
condenser-0.0.11 lib/condenser/processors/node_modules/sourcemap-codec/README.md
condenser-0.0.10 lib/condenser/processors/node_modules/sourcemap-codec/README.md
condenser-0.0.9 lib/condenser/processors/node_modules/sourcemap-codec/README.md
condenser-0.0.8 lib/condenser/processors/node_modules/sourcemap-codec/README.md
condenser-0.0.7 lib/condenser/processors/node_modules/sourcemap-codec/README.md
condenser-0.0.5 lib/condenser/processors/node_modules/sourcemap-codec/README.md
condenser-0.0.4 lib/condenser/processors/node_modules/sourcemap-codec/README.md