# sourcemap-validator

> Map all the things, check all the maps

Latest version **2.1.0** (published 2019-09-10) · 0 weekly downloads

## Install

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

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2019-09-10 |
| First published | 2013-11-14 |
| Weekly downloads | 0 |
| TypeScript types | separate (@types/sourcemap-validator) |
| Module format | CommonJS |
| Node | 8.* \|\| >= 10.* |
| Dependencies | 4 |
| Unpacked size | 9.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Author | Ben Ng |
| Maintainers | benng, stefanpenner |
| Keywords | uglify, browserify, minify, minifyify, validate, validator, sourcemap |

## Links

- npm: https://www.npmjs.com/package/sourcemap-validator
- Repository: https://github.com/ben-ng/sourcemap-validator
- Homepage: https://github.com/ben-ng/sourcemap-validator#readme
- Issues: https://github.com/ben-ng/sourcemap-validator/issues
- npm.io page: https://npm.io/package/sourcemap-validator

## Dependencies (4)

- [jsesc](https://npm.io/package/jsesc.md) ~0.3.x
- [source-map](https://npm.io/package/source-map.md) ~0.1.x
- [lodash.foreach](https://npm.io/package/lodash.foreach.md) ^4.5.0
- [lodash.template](https://npm.io/package/lodash.template.md) ^4.5.0

## Alternatives

- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads

## Recent versions

- 2.1.0 (latest) — 2019-09-10
- 2.0.1 — 2019-09-10
- 2.0.0 — 2019-09-10
- 1.1.1 — 2019-07-11
- 1.1.0 — 2018-03-28
- 1.0.7 — 2018-02-13
- 1.0.6 — 2017-10-05
- 1.0.5 — 2016-11-01
- 1.0.4 — 2013-12-08
- 1.0.3 — 2013-12-08
- 1.0.2 — 2013-11-26
- 1.0.1 — 2013-11-14
- 1.0.0 — 2013-11-14
- 0.0.5 — 2013-11-14

## README

sourcemap-validator
===================

[![Build Status](https://travis-ci.org/ben-ng/sourcemap-validator.png)](https://travis-ci.org/ben-ng/sourcemap-validator)

Mapped all the things? Now validate all the maps.

## Usage

```js
validate(minifiedCode, [sourceMap], [sourceContent]);
```

 * `minifiedCode` is your minified code as a string
 * `sourceMap` is your sourcemap as a JSON string
    * Optional - If left empty, the inline sourcemap in `minifiedCode` will be used
 * `sourceContent` is a map to the raw source files
    * Optional - If left empty, the inline `sourceContent` in `sourceMap` will be used

## Examples

```js
var validate = require('sourcemap-validator')
  , fs = require('fs')
  , assert = require('assert')
  , min = fs.readFileSync('jquery.min.js', 'utf-8')
  , map = fs.readFileSync('jquery.min.map', 'utf-8');

assert.doesNotThrow(function () {
  validate(min, map, {'jquery.js': raw});
}, 'The sourcemap is not valid');
```

```js
var validate = require('sourcemap-validator')
  , fs = require('fs')
  , assert = require('assert')
  , min = fs.readFileSync('bundle.min.js', 'utf-8')
  , map = fs.readFileSync('bundle.min.map', 'utf-8');

// Browserify bundles have inline sourceContent in their maps
// so no need to pass a `sourceContent` object.
assert.doesNotThrow(function () {
  validate(min, map);
}, 'The sourcemap is not valid');
```

### validate(sourceContent, minifiedCode, mapJSON)

## Notes

The sourcemap spec isn't exactly very mature, so this module only aims to give you a Pretty Good™ idea of whether or not your sourcemap is correct.

### Quoted keys in object literals

If a sourcemap maps "literal" without the quotes to column 3, we will consider that valid.

**Example**
```js
var v = {
  literal: true
//^-- ok to map {name: literal, column: 3} here
};

var t = {
  "literal": true
//^-- ok to map {name: literal, column: 3} here, even though the token actually appears in column 4
};
```

See the discussion [here](https://github.com/mishoo/UglifyJS2/pull/303#issuecomment-27628362)

However, mapping something totally wrong like `"cookie"` to that index will throw an exception.

### Missing mappings

There is no way for the validator to know if you are missing mappings. It can only ensure that the ones you made are sensible. The validator will consider a sourcemap with zero mappings invalid as a sanity check, but if your map at least one sensisble mapping, it is a valid map.

## License
The MIT License (MIT)

Copyright (c) 2013 Ben Ng

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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