diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-03 15:35:00 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-03 15:35:00 +0200 |
commit | de98e0b232509d5f40c135d540a70e415272ff85 (patch) | |
tree | a79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/clean-css/lib/utils | |
parent | e0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff) |
node_modules
Diffstat (limited to 'node_modules/clean-css/lib/utils')
-rw-r--r-- | node_modules/clean-css/lib/utils/clone-array.js | 12 | ||||
-rw-r--r-- | node_modules/clean-css/lib/utils/format-position.js | 11 | ||||
-rw-r--r-- | node_modules/clean-css/lib/utils/has-protocol.js | 7 | ||||
-rw-r--r-- | node_modules/clean-css/lib/utils/is-data-uri-resource.js | 7 | ||||
-rw-r--r-- | node_modules/clean-css/lib/utils/is-http-resource.js | 7 | ||||
-rw-r--r-- | node_modules/clean-css/lib/utils/is-https-resource.js | 7 | ||||
-rw-r--r-- | node_modules/clean-css/lib/utils/is-import.js | 7 | ||||
-rw-r--r-- | node_modules/clean-css/lib/utils/is-remote-resource.js | 7 | ||||
-rw-r--r-- | node_modules/clean-css/lib/utils/natural-compare.js | 31 | ||||
-rw-r--r-- | node_modules/clean-css/lib/utils/override.js | 34 | ||||
-rw-r--r-- | node_modules/clean-css/lib/utils/split.js | 50 |
11 files changed, 180 insertions, 0 deletions
diff --git a/node_modules/clean-css/lib/utils/clone-array.js b/node_modules/clean-css/lib/utils/clone-array.js new file mode 100644 index 000000000..b95ee6843 --- /dev/null +++ b/node_modules/clean-css/lib/utils/clone-array.js @@ -0,0 +1,12 @@ +function cloneArray(array) { + var cloned = array.slice(0); + + for (var i = 0, l = cloned.length; i < l; i++) { + if (Array.isArray(cloned[i])) + cloned[i] = cloneArray(cloned[i]); + } + + return cloned; +} + +module.exports = cloneArray; diff --git a/node_modules/clean-css/lib/utils/format-position.js b/node_modules/clean-css/lib/utils/format-position.js new file mode 100644 index 000000000..0e3713c19 --- /dev/null +++ b/node_modules/clean-css/lib/utils/format-position.js @@ -0,0 +1,11 @@ +function formatPosition(metadata) { + var line = metadata[0]; + var column = metadata[1]; + var source = metadata[2]; + + return source ? + source + ':' + line + ':' + column : + line + ':' + column; +} + +module.exports = formatPosition; diff --git a/node_modules/clean-css/lib/utils/has-protocol.js b/node_modules/clean-css/lib/utils/has-protocol.js new file mode 100644 index 000000000..fa1b61fd5 --- /dev/null +++ b/node_modules/clean-css/lib/utils/has-protocol.js @@ -0,0 +1,7 @@ +var NO_PROTOCOL_RESOURCE_PATTERN = /^\/\//; + +function hasProtocol(uri) { + return !NO_PROTOCOL_RESOURCE_PATTERN.test(uri); +} + +module.exports = hasProtocol; diff --git a/node_modules/clean-css/lib/utils/is-data-uri-resource.js b/node_modules/clean-css/lib/utils/is-data-uri-resource.js new file mode 100644 index 000000000..58558110f --- /dev/null +++ b/node_modules/clean-css/lib/utils/is-data-uri-resource.js @@ -0,0 +1,7 @@ +var DATA_URI_PATTERN = /^data:(\S*?)?(;charset=[^;]+)?(;[^,]+?)?,(.+)/; + +function isDataUriResource(uri) { + return DATA_URI_PATTERN.test(uri); +} + +module.exports = isDataUriResource; diff --git a/node_modules/clean-css/lib/utils/is-http-resource.js b/node_modules/clean-css/lib/utils/is-http-resource.js new file mode 100644 index 000000000..5179c2ea9 --- /dev/null +++ b/node_modules/clean-css/lib/utils/is-http-resource.js @@ -0,0 +1,7 @@ +var HTTP_RESOURCE_PATTERN = /^http:\/\//; + +function isHttpResource(uri) { + return HTTP_RESOURCE_PATTERN.test(uri); +} + +module.exports = isHttpResource; diff --git a/node_modules/clean-css/lib/utils/is-https-resource.js b/node_modules/clean-css/lib/utils/is-https-resource.js new file mode 100644 index 000000000..c6938f57d --- /dev/null +++ b/node_modules/clean-css/lib/utils/is-https-resource.js @@ -0,0 +1,7 @@ +var HTTPS_RESOURCE_PATTERN = /^https:\/\//; + +function isHttpsResource(uri) { + return HTTPS_RESOURCE_PATTERN.test(uri); +} + +module.exports = isHttpsResource; diff --git a/node_modules/clean-css/lib/utils/is-import.js b/node_modules/clean-css/lib/utils/is-import.js new file mode 100644 index 000000000..72abc3287 --- /dev/null +++ b/node_modules/clean-css/lib/utils/is-import.js @@ -0,0 +1,7 @@ +var IMPORT_PREFIX_PATTERN = /^@import/i; + +function isImport(value) { + return IMPORT_PREFIX_PATTERN.test(value); +} + +module.exports = isImport; diff --git a/node_modules/clean-css/lib/utils/is-remote-resource.js b/node_modules/clean-css/lib/utils/is-remote-resource.js new file mode 100644 index 000000000..fb3b61f3d --- /dev/null +++ b/node_modules/clean-css/lib/utils/is-remote-resource.js @@ -0,0 +1,7 @@ +var REMOTE_RESOURCE_PATTERN = /^(\w+:\/\/|\/\/)/; + +function isRemoteResource(uri) { + return REMOTE_RESOURCE_PATTERN.test(uri); +} + +module.exports = isRemoteResource; diff --git a/node_modules/clean-css/lib/utils/natural-compare.js b/node_modules/clean-css/lib/utils/natural-compare.js new file mode 100644 index 000000000..7a5246762 --- /dev/null +++ b/node_modules/clean-css/lib/utils/natural-compare.js @@ -0,0 +1,31 @@ +// adapted from http://nedbatchelder.com/blog/200712.html#e20071211T054956 + +var NUMBER_PATTERN = /([0-9]+)/; + +function naturalCompare(value1, value2) { + var keys1 = ('' + value1).split(NUMBER_PATTERN).map(tryParseInt); + var keys2 = ('' + value2).split(NUMBER_PATTERN).map(tryParseInt); + var key1; + var key2; + var compareFirst = Math.min(keys1.length, keys2.length); + var i, l; + + for (i = 0, l = compareFirst; i < l; i++) { + key1 = keys1[i]; + key2 = keys2[i]; + + if (key1 != key2) { + return key1 > key2 ? 1 : -1; + } + } + + return keys1.length > keys2.length ? 1 : (keys1.length == keys2.length ? 0 : -1); +} + +function tryParseInt(value) { + return ('' + parseInt(value)) == value ? + parseInt(value) : + value; +} + +module.exports = naturalCompare; diff --git a/node_modules/clean-css/lib/utils/override.js b/node_modules/clean-css/lib/utils/override.js new file mode 100644 index 000000000..e7f84948c --- /dev/null +++ b/node_modules/clean-css/lib/utils/override.js @@ -0,0 +1,34 @@ +function override(source1, source2) { + var target = {}; + var key1; + var key2; + var item; + + for (key1 in source1) { + item = source1[key1]; + + if (Array.isArray(item)) { + target[key1] = item.slice(0); + } else if (typeof item == 'object' && item !== null) { + target[key1] = override(item, {}); + } else { + target[key1] = item; + } + } + + for (key2 in source2) { + item = source2[key2]; + + if (key2 in target && Array.isArray(item)) { + target[key2] = item.slice(0); + } else if (key2 in target && typeof item == 'object' && item !== null) { + target[key2] = override(target[key2], item); + } else { + target[key2] = item; + } + } + + return target; +} + +module.exports = override; diff --git a/node_modules/clean-css/lib/utils/split.js b/node_modules/clean-css/lib/utils/split.js new file mode 100644 index 000000000..c91625506 --- /dev/null +++ b/node_modules/clean-css/lib/utils/split.js @@ -0,0 +1,50 @@ +var Marker = require('../tokenizer/marker'); + +function split(value, separator) { + var openLevel = Marker.OPEN_ROUND_BRACKET; + var closeLevel = Marker.CLOSE_ROUND_BRACKET; + var level = 0; + var cursor = 0; + var lastStart = 0; + var lastValue; + var lastCharacter; + var len = value.length; + var parts = []; + + if (value.indexOf(separator) == -1) { + return [value]; + } + + if (value.indexOf(openLevel) == -1) { + return value.split(separator); + } + + while (cursor < len) { + if (value[cursor] == openLevel) { + level++; + } else if (value[cursor] == closeLevel) { + level--; + } + + if (level === 0 && cursor > 0 && cursor + 1 < len && value[cursor] == separator) { + parts.push(value.substring(lastStart, cursor)); + lastStart = cursor + 1; + } + + cursor++; + } + + if (lastStart < cursor + 1) { + lastValue = value.substring(lastStart); + lastCharacter = lastValue[lastValue.length - 1]; + if (lastCharacter == separator) { + lastValue = lastValue.substring(0, lastValue.length - 1); + } + + parts.push(lastValue); + } + + return parts; +} + +module.exports = split; |