aboutsummaryrefslogtreecommitdiff
path: root/node_modules/clean-css/lib/options/format.js
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/clean-css/lib/options/format.js
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/clean-css/lib/options/format.js')
-rw-r--r--node_modules/clean-css/lib/options/format.js216
1 files changed, 216 insertions, 0 deletions
diff --git a/node_modules/clean-css/lib/options/format.js b/node_modules/clean-css/lib/options/format.js
new file mode 100644
index 00000000..48c7efa8
--- /dev/null
+++ b/node_modules/clean-css/lib/options/format.js
@@ -0,0 +1,216 @@
+var systemLineBreak = require('os').EOL;
+
+var override = require('../utils/override');
+
+var Breaks = {
+ AfterAtRule: 'afterAtRule',
+ AfterBlockBegins: 'afterBlockBegins',
+ AfterBlockEnds: 'afterBlockEnds',
+ AfterComment: 'afterComment',
+ AfterProperty: 'afterProperty',
+ AfterRuleBegins: 'afterRuleBegins',
+ AfterRuleEnds: 'afterRuleEnds',
+ BeforeBlockEnds: 'beforeBlockEnds',
+ BetweenSelectors: 'betweenSelectors'
+};
+
+var BreakWith = {
+ CarriageReturnLineFeed: '\r\n',
+ LineFeed: '\n',
+ System: systemLineBreak
+};
+
+var IndentWith = {
+ Space: ' ',
+ Tab: '\t'
+};
+
+var Spaces = {
+ AroundSelectorRelation: 'aroundSelectorRelation',
+ BeforeBlockBegins: 'beforeBlockBegins',
+ BeforeValue: 'beforeValue'
+};
+
+var DEFAULTS = {
+ breaks: breaks(false),
+ breakWith: BreakWith.System,
+ indentBy: 0,
+ indentWith: IndentWith.Space,
+ spaces: spaces(false),
+ wrapAt: false,
+ semicolonAfterLastProperty: false
+};
+
+var BEAUTIFY_ALIAS = 'beautify';
+var KEEP_BREAKS_ALIAS = 'keep-breaks';
+
+var OPTION_SEPARATOR = ';';
+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 = {};
+
+ breakOptions[Breaks.AfterAtRule] = value;
+ breakOptions[Breaks.AfterBlockBegins] = value;
+ breakOptions[Breaks.AfterBlockEnds] = value;
+ breakOptions[Breaks.AfterComment] = value;
+ breakOptions[Breaks.AfterProperty] = value;
+ breakOptions[Breaks.AfterRuleBegins] = value;
+ breakOptions[Breaks.AfterRuleEnds] = value;
+ breakOptions[Breaks.BeforeBlockEnds] = value;
+ breakOptions[Breaks.BetweenSelectors] = value;
+
+ return breakOptions;
+}
+
+function spaces(value) {
+ var spaceOptions = {};
+
+ spaceOptions[Spaces.AroundSelectorRelation] = value;
+ spaceOptions[Spaces.BeforeBlockBegins] = value;
+ spaceOptions[Spaces.BeforeValue] = value;
+
+ return spaceOptions;
+}
+
+function formatFrom(source) {
+ if (source === undefined || source === false) {
+ return false;
+ }
+
+ if (typeof source == 'object' && 'breakWith' in source) {
+ source = override(source, { breakWith: mapBreakWith(source.breakWith) });
+ }
+
+ if (typeof source == 'object' && 'indentBy' in source) {
+ source = override(source, { indentBy: parseInt(source.indentBy) });
+ }
+
+ if (typeof source == 'object' && 'indentWith' in source) {
+ source = override(source, { indentWith: mapIndentWith(source.indentWith) });
+ }
+
+ if (typeof source == 'object') {
+ return override(DEFAULTS, source);
+ }
+
+ if (typeof source == 'object') {
+ return override(DEFAULTS, source);
+ }
+
+ if (typeof source == 'string' && source == BEAUTIFY_ALIAS) {
+ return override(DEFAULTS, {
+ breaks: breaks(true),
+ indentBy: 2,
+ spaces: spaces(true)
+ });
+ }
+
+ if (typeof source == 'string' && source == KEEP_BREAKS_ALIAS) {
+ return override(DEFAULTS, {
+ breaks: {
+ afterAtRule: true,
+ afterBlockBegins: true,
+ afterBlockEnds: true,
+ afterComment: true,
+ afterRuleEnds: true,
+ beforeBlockEnds: true
+ }
+ });
+ }
+
+ if (typeof source == 'string') {
+ return override(DEFAULTS, toHash(source));
+ }
+
+ return DEFAULTS;
+}
+
+function toHash(string) {
+ return string
+ .split(OPTION_SEPARATOR)
+ .reduce(function (accumulator, directive) {
+ var parts = directive.split(OPTION_NAME_VALUE_SEPARATOR);
+ var name = parts[0];
+ var value = parts[1];
+
+ if (name == 'breaks' || name == 'spaces') {
+ accumulator[name] = hashValuesToHash(value);
+ } else if (name == 'indentBy' || name == 'wrapAt') {
+ accumulator[name] = parseInt(value);
+ } else if (name == 'indentWith') {
+ accumulator[name] = mapIndentWith(value);
+ } else if (name == 'breakWith') {
+ accumulator[name] = mapBreakWith(value);
+ }
+
+ return accumulator;
+ }, {});
+}
+
+function hashValuesToHash(string) {
+ return string
+ .split(HASH_VALUES_OPTION_SEPARATOR)
+ .reduce(function (accumulator, directive) {
+ var parts = directive.split(HASH_VALUES_NAME_VALUE_SEPARATOR);
+ var name = parts[0];
+ var value = parts[1];
+
+ accumulator[name] = normalizeValue(value);
+
+ return accumulator;
+ }, {});
+}
+
+
+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':
+ case 'crlf':
+ case BreakWith.CarriageReturnLineFeed:
+ return BreakWith.CarriageReturnLineFeed;
+ case 'unix':
+ case 'lf':
+ case BreakWith.LineFeed:
+ return BreakWith.LineFeed;
+ default:
+ return systemLineBreak;
+ }
+}
+
+function mapIndentWith(value) {
+ switch (value) {
+ case 'space':
+ return IndentWith.Space;
+ case 'tab':
+ return IndentWith.Tab;
+ default:
+ return value;
+ }
+}
+
+module.exports = {
+ Breaks: Breaks,
+ Spaces: Spaces,
+ formatFrom: formatFrom
+};