Socket
Socket
Sign inDemoInstall

source-map-url

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    source-map-url

Tools for working with sourceMappingURL comments.


Version published
Weekly downloads
11M
decreased by-15.78%
Maintainers
1
Install size
8.49 kB
Created
Weekly downloads
 

Package description

What is source-map-url?

The source-map-url npm package is a utility for working with source map URLs. It allows you to extract, insert, or remove source map URLs within a file, typically JavaScript or CSS files. This can be useful for developers who need to manage source map links in their generated code.

What are source-map-url's main functionalities?

Extracting source map URL

This feature allows you to extract the source map URL from a string of code. The `getFrom` method returns the URL if it exists.

const sourceMapUrl = require('source-map-url');
const code = '/*# sourceMappingURL=/path/to/file.js.map */';
const extractedUrl = sourceMapUrl.getFrom(code);

Inserting source map URL

This feature enables you to insert a source map URL into a string of code. The `insertInto` method adds the specified URL at the end of the code.

const sourceMapUrl = require('source-map-url');
const code = 'function example() {}';
const newCode = sourceMapUrl.insertInto(code, '/path/to/file.js.map');

Removing source map URL

This feature is used to remove an existing source map URL from a string of code. The `removeFrom` method strips out the source map URL.

const sourceMapUrl = require('source-map-url');
const code = 'function example() {}\n/*# sourceMappingURL=/path/to/file.js.map */';
const newCode = sourceMapUrl.removeFrom(code);

Other packages similar to source-map-url

Readme

Source

Overview Build Status

browser support

Tools for working with sourceMappingURL comments.

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.

Keywords

FAQs

Last updated on 01 Feb 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc