sourcemap-validator
Advanced tools
Comparing version 0.0.5 to 1.0.0
37
index.js
var validate | ||
, validateMapping | ||
, toAscii | ||
, assert = require('assert') | ||
@@ -9,2 +10,16 @@ , SMConsumer = require('source-map').SourceMapConsumer | ||
// Lifted from UglifyJS | ||
toAscii = function (str, identifier) { | ||
return str.replace(/[\u0080-\uffff]/g, function(ch) { | ||
var code = ch.charCodeAt(0).toString(16); | ||
if (code.length <= 2 && !identifier) { | ||
while (code.length < 2) code = "0" + code; | ||
return "\\x" + code; | ||
} else { | ||
while (code.length < 4) code = "0" + code; | ||
return "\\u" + code; | ||
} | ||
}).replace(/\x0B/g, "\\x0B"); | ||
}; | ||
// Performs simple validation of a mapping | ||
@@ -26,3 +41,3 @@ validateMapping = function (mapping) { | ||
// Validates an entire sourcemap | ||
validate = function (srcs, min, map, opts) { | ||
validate = function (min, map, srcs) { | ||
var consumer | ||
@@ -32,2 +47,18 @@ , mappingCount = 0 | ||
srcs = srcs || {}; | ||
// If no map was given, try to extract it from min | ||
if(map == null) { | ||
try { | ||
var marker = '//@ sourceMappingURL=data:application/json;base64,' | ||
, offset = min.indexOf(marker); | ||
map = (new Buffer(min.substring(offset + marker.length), 'base64')).toString(); | ||
min = min.substring(0, offset); | ||
} | ||
catch (e) { | ||
throw new Error('No map argument provided, and no inline sourcemap found'); | ||
} | ||
} | ||
try { | ||
@@ -46,4 +77,2 @@ consumer = new SMConsumer(map) | ||
opts = opts || {}; | ||
each(srcs, function (src, file) { | ||
@@ -77,3 +106,5 @@ return splitSrcs[file] = src.split('\n'); // Split sources by line | ||
, '\'' + jsesc(mapping.name) + '\'' | ||
, '\'' + toAscii(mapping.name) + '\'' | ||
, '"' + jsesc(mapping.name, {quotes: 'double'}) + '"' | ||
, '"' + toAscii(mapping.name) + '"' | ||
]; | ||
@@ -80,0 +111,0 @@ |
@@ -14,3 +14,3 @@ { | ||
], | ||
"version": "0.0.5", | ||
"version": "1.0.0", | ||
"repository": { | ||
@@ -30,3 +30,3 @@ "type": "git", | ||
"devDependencies": { | ||
"uglify-js": "https://github.com/ben-ng/UglifyJS2/archive/sourcemap-offset-fix.tar.gz", | ||
"uglify-js": "2.4.x", | ||
"jake": "0.7.x" | ||
@@ -36,4 +36,4 @@ }, | ||
"engines": { | ||
"node": "0.8.x" | ||
"node": "0.10.x" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1310838
21
27155
0
93
3
4
1