# source-map-url

> Tools for working with sourceMappingURL comments.

Latest version **0.4.1** (published 2021-02-01) · MIT license · 0 weekly downloads

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

## Install

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

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.4.1 |
| Published | 2021-02-01 |
| First published | 2014-02-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 46 |
| Author | Simon Lydell |
| Maintainers | lydell |
| Keywords | source map, sourceMappingURL, comment, annotation |

## Links

- npm: https://www.npmjs.com/package/source-map-url
- Repository: https://github.com/lydell/source-map-url
- Homepage: https://github.com/lydell/source-map-url#readme
- Issues: https://github.com/lydell/source-map-url/issues
- npm.io page: https://npm.io/package/source-map-url

## 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.4.1 (latest) — 2021-02-01
- 0.4.0 — 2015-11-12
- 0.3.0 — 2014-08-16
- 0.2.0 — 2014-02-23
- 0.1.0 — 2014-02-22

## README

Overview [![Build Status](https://travis-ci.org/lydell/source-map-url.png?branch=master)](https://travis-ci.org/lydell/source-map-url)
========

[![browser support](https://ci.testling.com/lydell/source-map-url.png)](https://ci.testling.com/lydell/source-map-url)

Tools for working with sourceMappingURL comments.

```js
var sourceMappingURL = require("source-map-url")

var code = [
  "!function(){...}();",
  "/*# sourceMappingURL=foo.js.map */"
].join("\n")

sourceMappingURL.existsIn(code)
// true

sourceMappingURL.getFrom(code)
// foo.js.map

code = sourceMappingURL.insertBefore(code, "// License: MIT\n")
// !function(){...}();
// // License: MIT
// /*# sourceMappingURL=foo.js.map */

code = sourceMappingURL.removeFrom(code)
// !function(){...}();
// // License: MIT

sourceMappingURL.existsIn(code)
// false

sourceMappingURL.getFrom(code)
// null

code += "//# sourceMappingURL=/other/file.js.map"
// !function(){...}();
// // License: MIT
// //# sourceMappingURL=/other/file.js.map
```


Installation
============

- `npm install source-map-url`
- `bower install source-map-url`
- `component install lydell/source-map-url`

Works with CommonJS, AMD and browser globals, through UMD.


Usage
=====

### `sourceMappingURL.getFrom(code)` ###

Returns the url of the sourceMappingURL comment in `code`. Returns `null` if
there is no such comment.

### `sourceMappingURL.existsIn(code)` ###

Returns `true` if there is a sourceMappingURL comment in `code`, or `false`
otherwise.

### `sourceMappingURL.removeFrom(code)` ###

Removes the sourceMappingURL comment in `code`. Does nothing if there is no
such comment. Returns the updated `code`.

### `sourceMappingURL.insertBefore(code, string)` ###

Inserts `string` before the sourceMappingURL comment in `code`. Appends
`string` to `code` if there is no such comment.

Lets you append something to a file without worrying about burying the
sourceMappingURL comment (by keeping it at the end of the file).

### `sourceMappingURL.regex` ###

The regex that is used to match sourceMappingURL comments. It matches both `//`
and `/**/` comments, thus supporting both JavaScript and CSS.


Tests
=====

Start by running `npm test`, which lints the code and runs the test suite in Node.js.

To run the tests in a browser, run `testling` (`npm install -g testling`) or `testling -u`.


License
=======

[The X11 (“MIT”) License](LICENSE).

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