Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix clean-css/clean-css-cli#77 #1248

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 3 additions & 18 deletions lib/options/format.js
@@ -1,6 +1,7 @@
var systemLineBreak = require('os').EOL;

var override = require('../utils/override');
var normalizeValue = require('../utils/normalize-value');

var Breaks = {
AfterAtRule: 'afterAtRule',
Expand Down Expand Up @@ -49,11 +50,6 @@ var OPTION_NAME_VALUE_SEPARATOR = ':';
var HASH_VALUES_OPTION_SEPARATOR = ',';
var HASH_VALUES_NAME_VALUE_SEPARATOR = '=';

var FALSE_KEYWORD_1 = 'false';
var FALSE_KEYWORD_2 = 'off';
var TRUE_KEYWORD_1 = 'true';
var TRUE_KEYWORD_2 = 'on';

function breaks(value) {
var breakOptions = {};

Expand Down Expand Up @@ -149,6 +145,8 @@ function toHash(string) {
accumulator[name] = mapIndentWith(value);
} else if (name == 'breakWith') {
accumulator[name] = mapBreakWith(value);
} else {
accumulator[name] = normalizeValue(value);
}

return accumulator;
Expand All @@ -169,19 +167,6 @@ function hashValuesToHash(string) {
}, {});
}

function normalizeValue(value) {
switch (value) {
case FALSE_KEYWORD_1:
case FALSE_KEYWORD_2:
return false;
case TRUE_KEYWORD_1:
case TRUE_KEYWORD_2:
return true;
default:
return value;
}
}

function mapBreakWith(value) {
switch (value) {
case 'windows':
Expand Down
26 changes: 5 additions & 21 deletions lib/options/optimization-level.js
@@ -1,6 +1,7 @@
var roundingPrecisionFrom = require('./rounding-precision').roundingPrecisionFrom;

var override = require('../utils/override');
var normalizeValue = require('../utils/normalize-value');

var OptimizationLevel = {
Zero: '0',
Expand Down Expand Up @@ -53,10 +54,6 @@ DEFAULTS[OptimizationLevel.Two] = {

var ALL_KEYWORD_1 = '*';
var ALL_KEYWORD_2 = 'all';
var FALSE_KEYWORD_1 = 'false';
var FALSE_KEYWORD_2 = 'off';
var TRUE_KEYWORD_1 = 'true';
var TRUE_KEYWORD_2 = 'on';

var LIST_VALUE_SEPARATOR = ',';
var OPTION_SEPARATOR = ';';
Expand Down Expand Up @@ -93,7 +90,7 @@ function optimizationLevelFrom(source) {
}

if (typeof source == 'object') {
source = covertValuesToHashes(source);
source = convertValuesToHashes(source);
}

if (One in source && 'roundingPrecision' in source[One]) {
Expand Down Expand Up @@ -156,20 +153,7 @@ function defaults(level, value) {
return options;
}

function normalizeValue(value) {
switch (value) {
case FALSE_KEYWORD_1:
case FALSE_KEYWORD_2:
return false;
case TRUE_KEYWORD_1:
case TRUE_KEYWORD_2:
return true;
default:
return value;
}
}

function covertValuesToHashes(source) {
function convertValuesToHashes(source) {
var clonedSource = override(source, {});
var level;
var i;
Expand All @@ -186,14 +170,14 @@ function covertValuesToHashes(source) {
}

if (level in clonedSource && typeof clonedSource[level] == 'string') {
clonedSource[level] = covertToHash(clonedSource[level], level);
clonedSource[level] = convertToHash(clonedSource[level], level);
}
}

return clonedSource;
}

function covertToHash(asString, level) {
function convertToHash(asString, level) {
return asString
.split(OPTION_SEPARATOR)
.reduce(function(accumulator, directive) {
Expand Down
19 changes: 19 additions & 0 deletions lib/utils/normalize-value.js
@@ -0,0 +1,19 @@
var FALSE_KEYWORD_1 = 'false';
var FALSE_KEYWORD_2 = 'off';
var TRUE_KEYWORD_1 = 'true';
var TRUE_KEYWORD_2 = 'on';

function normalizeValue(value) {
switch (value) {
case FALSE_KEYWORD_1:
case FALSE_KEYWORD_2:
return false;
case TRUE_KEYWORD_1:
case TRUE_KEYWORD_2:
return true;
default:
return value;
}
}

module.exports = normalizeValue;