Current Dev State

This commit is contained in:
Tim Lorsbach
2025-06-23 20:13:54 +02:00
parent b4f9bb277d
commit ded50edaa2
22617 changed files with 4345095 additions and 174 deletions

View File

@ -0,0 +1,20 @@
{
"name": "source-map-url",
"version": "0.3.0",
"author": "Simon Lydell",
"license": "MIT",
"description": "Tools for working with sourceMappingURL comments.",
"keywords": [
"source map",
"sourceMappingURL",
"comment",
"annotation"
],
"main": "source-map-url.js",
"authors": [
"Simon Lydell"
],
"ignore": [
".*"
]
}

View File

@ -0,0 +1,42 @@
### Version 0.3.0 (2014-08-16) ###
- Changed: sourceMappingURL comments used to be matched only if they appeared
on their own line. However, the spec only says:
> The generated code may include a line at the end of the source, with the following form:
>
> //# sourceMappingURL=<url>
So now they are matched also when they appear on the same line as code.
- Removed: The `.set()` method. I couldnt decide how it should work
considering the above change. Moreover, it was unnecessarily complex (and
would have gotten worse) for very little gain. It is much easier to run
`.remove()` if needed, and then simply `code += "\n//# sourceMappingURL=" +
url` (using the appropriate comment syntax and newline). KISS.
- Changed: The `.insertBefore()` method now always inserts the string exactly
before the sourceMappingURL comment; not before the newline before the
comment (if any). Moreover, it does not ensure that the comment will be on a
new line anymore. This is up to the caller. KISS.
- Changed: The `.remove()` method no longer removes the newline before the
sourceMappingURL (if any).
- Changed: Renamed `.get()` to `.getFrom()`.
- Changed: Renamed `.remove()` to `.removeFrom()`.
- Added: The `.existsIn()` method.
### Version 0.2.0 (2014-02-23) ###
- Changed: A space is no longer inserted before the closing comment syntax. If
such a space is desired, it needs to be put in the closing comment syntax
itself (such as `["/*", " */"]` instead of `["/*", "*/"]`). (Backwards
incompatible change.)
### Version 0.1.0 (2014-02-22) ###
- Initial release.

View File

@ -0,0 +1,18 @@
{
"name": "source-map-url",
"version": "0.3.0",
"author": "Simon Lydell",
"license": "MIT",
"description": "Tools for working with sourceMappingURL comments.",
"keywords": [
"source map",
"sourceMappingURL",
"comment",
"annotation"
],
"main": "source-map-url.js",
"repo": "lydell/source-map-url",
"scripts": [
"source-map-url.js"
]
}

View File

@ -0,0 +1,73 @@
{
"_from": "source-map-url@~0.3.0",
"_id": "source-map-url@0.3.0",
"_inBundle": false,
"_integrity": "sha1-fsrxO1e80J2opAxdJp2zN5nUqvk=",
"_location": "/source-map-url",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "source-map-url@~0.3.0",
"name": "source-map-url",
"escapedName": "source-map-url",
"rawSpec": "~0.3.0",
"saveSpec": null,
"fetchSpec": "~0.3.0"
},
"_requiredBy": [
"/source-map-resolve"
],
"_resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.3.0.tgz",
"_shasum": "7ecaf13b57bcd09da8a40c5d269db33799d4aaf9",
"_spec": "source-map-url@~0.3.0",
"_where": "/home/manfred/enviPath/ketcher2/ketcher/node_modules/source-map-resolve",
"author": {
"name": "Simon Lydell"
},
"bugs": {
"url": "https://github.com/lydell/source-map-url/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Tools for working with sourceMappingURL comments.",
"devDependencies": {
"expect.js": "~0.3.1",
"jshint": "~2.4.3",
"mocha": "~1.17.1"
},
"homepage": "https://github.com/lydell/source-map-url#readme",
"keywords": [
"source map",
"sourceMappingURL",
"comment",
"annotation"
],
"license": "MIT",
"main": "source-map-url.js",
"name": "source-map-url",
"repository": {
"type": "git",
"url": "git+https://github.com/lydell/source-map-url.git"
},
"scripts": {
"lint": "jshint source-map-url.js test/ ",
"test": "npm run lint && npm run unit",
"unit": "mocha"
},
"testling": {
"harness": "mocha",
"files": "test/*.js",
"browsers": [
"ie/8..latest",
"chrome/latest",
"firefox/latest",
"opera/12",
"opera/latest",
"safari/5",
"iphone/6",
"android-browser/4"
]
},
"version": "0.3.0"
}

View File

@ -0,0 +1,97 @@
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 breaking the
sourceMappingURL comment (which needs to be 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).

View File

@ -0,0 +1,57 @@
// Copyright 2014 Simon Lydell
// X11 (“MIT”) Licensed. (See LICENSE.)
void (function(root, factory) {
if (typeof define === "function" && define.amd) {
define(factory)
} else if (typeof exports === "object") {
module.exports = factory()
} else {
root.sourceMappingURL = factory()
}
}(this, function() {
var innerRegex = /[#@] sourceMappingURL=([^\s'"]*)/
var regex = RegExp(
"(?:" +
"/\\*" +
"(?:\\s*\r?\n(?://)?)?" +
"(?:" + innerRegex.source + ")" +
"\\s*" +
"\\*/" +
"|" +
"//(?:" + innerRegex.source + ")" +
")" +
"\\s*$"
)
return {
regex: regex,
_innerRegex: innerRegex,
getFrom: function(code) {
var match = code.match(regex)
return (match ? match[1] || match[2] || "" : null)
},
existsIn: function(code) {
return regex.test(code)
},
removeFrom: function(code) {
return code.replace(regex, "")
},
insertBefore: function(code, string) {
var match = code.match(regex)
if (match) {
return code.slice(0, match.index) + string + code.slice(match.index)
} else {
return code + string
}
}
}
}));

View File

@ -0,0 +1,321 @@
// Copyright 2014 Simon Lydell
// X11 (“MIT”) Licensed. (See LICENSE.)
var expect = require("expect.js")
var sourceMappingURL = require("../")
var comments = {
universal: [
"/*# sourceMappingURL=foo.js.map */"
],
js: [
"//# sourceMappingURL=foo.js.map"
],
block: [
"/*",
"# sourceMappingURL=foo.js.map",
"*/"
],
mix: [
"/*",
"//# sourceMappingURL=foo.js.map",
"*/"
]
}
function forEachComment(fn) {
forOf(comments, function(name, comment) {
var description = "the '" + name + "' syntax with "
fn(comment.join("\n"), description + "regular newlines")
fn(comment.join("\r\n"), description + "Windows newlines")
})
}
function forOf(obj, fn) {
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
fn(key, obj[key])
}
}
}
describe("sourceMappingURL", function() {
describe(".getFrom", function() {
forEachComment(function(comment, description) {
it("gets the url from " + description, function() {
expect(sourceMappingURL.getFrom("code\n" + comment))
.to.equal("foo.js.map")
expect(sourceMappingURL.getFrom("code" + comment))
.to.equal("foo.js.map")
expect(sourceMappingURL.getFrom(comment))
.to.equal("foo.js.map")
})
})
it("returns null if no comment", function() {
expect(sourceMappingURL.getFrom("code"))
.to.equal(null)
})
it("can return an empty string as url", function() {
expect(sourceMappingURL.getFrom("/*# sourceMappingURL= */"))
.to.equal("")
})
it("is detachable", function() {
var get = sourceMappingURL.getFrom
expect(get("/*# sourceMappingURL=foo */"))
.to.equal("foo")
})
})
describe(".existsIn", function() {
forEachComment(function(comment, description) {
it("returns true for " + description, function() {
expect(sourceMappingURL.existsIn("code\n" + comment))
.to.equal(true)
expect(sourceMappingURL.existsIn("code" + comment))
.to.equal(true)
expect(sourceMappingURL.existsIn(comment))
.to.equal(true)
})
})
it("returns false if no comment", function() {
expect(sourceMappingURL.existsIn("code"))
.to.equal(false)
})
it("is detachable", function() {
var has = sourceMappingURL.existsIn
expect(has("/*# sourceMappingURL=foo */"))
.to.equal(true)
})
})
describe(".removeFrom", function() {
forEachComment(function(comment, description) {
it("removes the comment for " + description, function() {
expect(sourceMappingURL.removeFrom("code\n" + comment))
.to.equal("code\n")
expect(sourceMappingURL.removeFrom("code" + comment))
.to.equal("code")
expect(sourceMappingURL.removeFrom(comment))
.to.equal("")
})
})
it("does nothing if no comment", function() {
expect(sourceMappingURL.removeFrom("code\n"))
.to.equal("code\n")
})
it("is detachable", function() {
var remove = sourceMappingURL.removeFrom
expect(remove("/*# sourceMappingURL=foo */"))
.to.equal("")
})
})
describe(".insertBefore", function() {
forEachComment(function(comment, description) {
it("inserts a string before the comment for " + description, function() {
expect(sourceMappingURL.insertBefore("code\n" + comment, "more code\n"))
.to.equal("code\nmore code\n" + comment)
expect(sourceMappingURL.insertBefore("code" + comment, "\nmore code"))
.to.equal("code\nmore code" + comment)
expect(sourceMappingURL.insertBefore(comment, "some code"))
.to.equal("some code" + comment)
})
})
it("appends if no comment", function() {
expect(sourceMappingURL.insertBefore("code", "\nmore code"))
.to.equal("code\nmore code")
})
it("is detachable", function() {
var insertBefore = sourceMappingURL.insertBefore
expect(insertBefore("/*# sourceMappingURL=foo */", "bar"))
.to.equal("bar/*# sourceMappingURL=foo */")
})
})
describe(".regex", function() {
it("includes ._innerRegex", function() {
expect(sourceMappingURL.regex.source)
.to.contain(sourceMappingURL._innerRegex.source)
})
var match = function(code) {
expect(code)
.to.match(sourceMappingURL.regex)
}
var noMatch = function(code) {
expect(code)
.not.to.match(sourceMappingURL.regex)
}
forEachComment(function(comment, description) {
it("matches " + description, function() {
match("code\n" + comment)
match("code" + comment)
match(comment)
})
it("matches " + description + ", with trailing whitespace", function() {
match(comment + " ")
match(comment + "\n")
match(comment + "\n\n\t\n \t ")
})
it("only matches " + description + " at the end of files", function() {
noMatch("code\n" + comment + " code")
noMatch("code" + comment + " code")
noMatch("code\n" + comment + "\ncode")
noMatch("code" + comment + "\ncode")
noMatch("code\n" + comment + "\n// Generated by foobar")
noMatch("code" + comment + "\n// Generated by foobar")
noMatch("alert\n('\\" + comment + "')")
noMatch("alert('\\" + comment + "')")
noMatch('alert\n("\\' + comment + '")')
noMatch('alert("\\' + comment + '")')
})
})
it("does not match some cases that are easy to mess up", function() {
noMatch(
"/* # sourceMappingURL=foo */"
)
noMatch(
"/*\n" +
" //# sourceMappingURL=foo\n" +
"*/"
)
noMatch(
"/*//# sourceMappingURL=foo\n" +
"*/"
)
noMatch(
"// # sourceMappingURL=foo"
)
})
it("is liberal regarding inner whitespace", function() {
match(
"/*# sourceMappingURL=foo*/"
)
match(
"/*# sourceMappingURL=foo */"
)
match(
"/*# sourceMappingURL=foo \t\n" +
"*/"
)
match(
"/* \n" +
"# sourceMappingURL=foo\n" +
"*/"
)
match(
"/*\n" +
"# sourceMappingURL=foo\n" +
" */"
)
match(
"/*\n" +
"# sourceMappingURL=foo\n" +
"\n" +
"\t\n" +
"*/"
)
})
})
describe("._innerRegex", function() {
it("matches the contents of sourceMappingURL comments", function() {
expect("# sourceMappingURL=http://www.example.com/foo/bar.js.map")
.to.match(sourceMappingURL._innerRegex)
})
it("captures the url in the first capture group", function() {
expect(sourceMappingURL._innerRegex.exec("# sourceMappingURL=foo")[1])
.to.equal("foo")
})
it("supports the legacy syntax", function() {
expect("@ sourceMappingURL=http://www.example.com/foo/bar.js.map")
.to.match(sourceMappingURL._innerRegex)
})
})
})

View File

@ -0,0 +1,55 @@
{
name: "source-map-url",
version: "0.3.0",
author: "Simon Lydell",
license: "MIT",
description: "Tools for working with sourceMappingURL comments.",
keywords: [
"source map",
"sourceMappingURL",
"comment",
"annotation"
],
main: "source-map-url.js",
overlay: {
npm: {
repository: "lydell/source-map-url",
scripts: {
lint: "jshint source-map-url.js test/ ",
unit: "mocha",
test: "npm run lint && npm run unit"
},
devDependencies: {
"mocha": "~1.17.1",
"expect.js": "~0.3.1",
"jshint": "~2.4.3"
},
testling: {
harness: "mocha",
files: "test/*.js",
browsers: [
"ie/8..latest",
"chrome/latest",
"firefox/latest",
"opera/12",
"opera/latest",
"safari/5",
"iphone/6",
"android-browser/4"
]
}
},
component: {
repo: "lydell/source-map-url",
scripts: [
"source-map-url.js"
]
},
bower: {
authors: ["Simon Lydell"],
ignore: [
".*"
]
}
}
}