1. source-map-url
Tools for working with sourceMappingURL comments.
source-map-url
Package: source-map-url
Created by: lydell
Last modified: Sun, 26 Jun 2022 22:23:00 GMT
Version: 0.4.1
License: MIT
Downloads: 56,534,958
Repository: https://github.com/lydell/source-map-url

Install

npm install source-map-url
yarn add source-map-url

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.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code