Socket
Socket
Sign inDemoInstall

colorguard

Package Overview
Dependencies
19
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.3.0

52

lib/colorguard.js

@@ -5,3 +5,5 @@ var walk = require('rework-walk');

var colorDiff = require('color-diff');
var SourceMapConsumer = require('source-map').SourceMapConsumer;
var colors = {};
var sourceMapConsumer;

@@ -27,16 +29,40 @@ function getWhitelistHashKey(pair) {

function renderConflictLine(data) {
// returns correct column number of the color declaration
// pipetteur finds the position from the beginning of value declaration,
// we need line position instead
function getColumnPositionRelativeToLine(position, which) {
return position.declaration.position[which].column + position.column + position.declaration.property.length;
}
function renderOriginalPosition (position) {
return position.source + ':' + position.line + ':' + position.column;
}
function renderConflictLine (data) {
return '_match_ (_hex_) [line: _lines_]'
.replace('_match_', data[0].match)
.replace('_hex_', data[0].color.hex())
.replace('_lines_', data.map(function (info) {
// Column calculation is not this simple :(
//return info.declaration.position.start.line + ':' + (info.declaration.position.start.column + info.column);
return info.declaration.position.start.line;
.replace('_match_', data.lines[0].match)
.replace('_hex_', data.lines[0].color.hex())
.replace('_lines_', data.lines.map(function (info, index) {
var result = info.declaration.position.start.line + ':' + getColumnPositionRelativeToLine(info, 'start');
if (data.originalLines && data.originalLines.length) {
result += ' (' + renderOriginalPosition(data.originalLines[index]) + ')';
}
return result;
}).join(', '));
}
exports.inspect = function (css, options) {
function getOriginalPosition (info) {
return sourceMapConsumer && sourceMapConsumer.originalPositionFor({
line: info.declaration.position.start.line,
column: getColumnPositionRelativeToLine(info, 'start')
});
}
exports.inspect = function (css, options, map) {
options = options || {};
colors = {};
if (map) {
sourceMapConsumer = new SourceMapConsumer(map);
}
var threshold = typeof options.threshold !== 'undefined' ? options.threshold : 3;

@@ -143,6 +169,8 @@ options.ignore = options.ignore || [];

rgb: colorNames[i],
lines: c1
lines: c1,
originalLines: sourceMapConsumer && c1.map(getOriginalPosition) || []
}, {
rgb: colorNames[j],
lines: c2
lines: c2,
originalLines: sourceMapConsumer && c2.map(getOriginalPosition) || []
}],

@@ -159,4 +187,4 @@ distance: diffAmount

infoBlock.message = '_1_ is too close (_diffAmount_) to _2_'
.replace('_1_', renderConflictLine(c1))
.replace('_2_', renderConflictLine(c2))
.replace('_1_', renderConflictLine(infoBlock.colors[0]))
.replace('_2_', renderConflictLine(infoBlock.colors[1]))
.replace('_diffAmount_', diffAmount);

@@ -163,0 +191,0 @@

{
"name": "colorguard",
"version": "0.2.0",
"version": "0.3.0",
"description": "Keep a watchful eye on your css colors",

@@ -38,2 +38,4 @@ "main": "index.js",

"rework-walk": "^1.0.0",
"source-map": "^0.2.0",
"source-map-resolve": "^0.3.1",
"yargs": "^1.2.6"

@@ -40,0 +42,0 @@ },

Sorry, the diff of this file is not supported yet

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