# combine-source-map

> Add source maps of multiple files, offset them and then combine them into one source map

Latest version **0.8.0** (published 2017-03-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install combine-source-map
pnpm add combine-source-map
yarn add combine-source-map
bun add combine-source-map
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.0 |
| Published | 2017-03-20 |
| First published | 2013-03-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/combine-source-map) |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 80 |
| Author | Thorsten Lorenz |
| Maintainers | thlorenz, zertosh |
| Keywords | source, map, sourcemap, bundle, combine, cat, sourceMappingUrl, browserify |

## Links

- npm: https://www.npmjs.com/package/combine-source-map
- Repository: https://github.com/thlorenz/combine-source-map
- Issues: https://github.com/thlorenz/combine-source-map/issues
- npm.io page: https://npm.io/package/combine-source-map

## Dependencies (4)

- [source-map](https://npm.io/package/source-map.md) ~0.5.3
- [lodash.memoize](https://npm.io/package/lodash.memoize.md) ~3.0.3
- [inline-source-map](https://npm.io/package/inline-source-map.md) ~0.6.0
- [convert-source-map](https://npm.io/package/convert-source-map.md) ~1.1.0

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 0.8.0 (latest) — 2017-03-20
- 0.7.2 — 2016-04-13
- 0.7.1 — 2015-07-23
- 0.7.0 — 2015-07-23
- 0.6.1 — 2015-05-12
- 0.5.0 — 2015-04-07
- 0.4.0 — 2015-01-25
- 0.3.0 — 2013-11-05
- 0.2.0 — 2013-09-25
- 0.1.3 — 2013-07-06
- 0.1.2 — 2013-04-14
- 0.1.1 — 2013-03-17
- 0.1.0 — 2013-03-16

## README

# combine-source-map [![build status](https://secure.travis-ci.org/thlorenz/combine-source-map.png)](http://travis-ci.org/thlorenz/combine-source-map)

Add source maps of multiple files, offset them and then combine them into one source map.

```js
var convert = require('convert-source-map');
var combine = require('combine-source-map');

var fooComment = '//# sourceMappingURL=data:application/json;base64,eyJ2Z [..] pzJylcbiJdfQ==';
var barComment = '//# sourceMappingURL=data:application/json;base64,eyJ2Z [..] VjaycpXG4iXX0=';

var fooFile = {
    source: '(function() {\n\n  console.log(require(\'./bar.js\'));\n\n}).call(this);\n' + '\n' + fooComment
  , sourceFile: 'foo.js'
};
var barFile = {
    source: '(function() {\n\n  console.log(alert(\'alerts suck\'));\n\n}).call(this);\n' + '\n' + barComment
  , sourceFile: 'bar.js'
};

var offset = { line: 2 };
var base64 = combine
  .create('bundle.js')
  .addFile(fooFile, offset)
  .addFile(barFile, { line: offset.line + 8 })
  .base64();

var sm = convert.fromBase64(base64).toObject();
console.log(sm);
```

```
{ version: 3,
  file: 'bundle.js',
  sources: [ 'foo.coffee', 'bar.coffee' ],
  names: [],
  mappings: ';;;AAAA;CAAA;CAAA,CAAA,CAAA,IAAO,GAAK;CAAZ;;;;;ACAA;CAAA;CAAA,CAAA,CAAA,IAAO,GAAK;CAAZ',
  sourcesContent:
   [ 'console.log(require \'./bar.js\')\n',
     'console.log(alert \'alerts suck\')\n' ] }
```

## Installation

    npm install combine-source-map

## API

### create()

```
/**
 * @name create
 * @function
 * @param file {String} optional name of the generated file
 * @param sourceRoot { String} optional sourceRoot of the map to be generated
 * @return {Object} Combiner instance to which source maps can be added and later combined
 */
```

### Combiner.prototype.addFile(opts, offset)

```
/**
 * Adds map to underlying source map.
 * If source contains a source map comment that has the source of the original file inlined it will offset these
 * mappings and include them.
 * If no source map comment is found or it has no source inlined, mappings for the file will be generated and included
 * 
 * @name addMap
 * @function
 * @param opts {Object} { sourceFile: {String}, source: {String} }
 * @param offset {Object} { line: {Number}, column: {Number} }
 */
```

### Combiner.prototype.base64()

```
/**
* @name base64
* @function
* @return {String} base64 encoded combined source map
*/
```

### Combiner.prototype.comment()

```
/**
 * @name comment
 * @function
 * @return {String} base64 encoded sourceMappingUrl comment of the combined source map
 */
```

### removeComments(src)

```
/**
 * @name removeComments
 * @function
 * @param src 
 * @return {String} src with all sourceMappingUrl comments removed
 */
```

## Example 

Read and run the [more elaborate example](https://github.com/thlorenz/combine-source-map/blob/master/example/two-files.js) 
in order to get a better idea how things work.

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