| 1 |
let { list } = require('postcss') |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
module.exports.error = function (text) { |
| 8 |
let err = new Error(text) |
| 9 |
err.autoprefixer = true |
| 10 |
throw err |
| 11 |
} |
| 12 |
|
| 13 |
|
| 14 |
s. |
| 15 |
|
| 16 |
module.exports.uniq = function (array) { |
| 17 |
return [...new Set(array)] |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
module.exports.removeNote = function (string) { |
| 24 |
if (!string.includes(' ')) { |
| 25 |
return string |
| 26 |
} |
| 27 |
|
| 28 |
return string.split(' ')[0] |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
module.exports.escapeRegexp = function (string) { |
| 35 |
return string.replace(/[$()*+-.?[\\\]^{|}]/g, '\\$&') |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
module.exports.regexp = function (word, escape = true) { |
| 42 |
if (escape) { |
| 43 |
word = this.escapeRegexp(word) |
| 44 |
} |
| 45 |
return new RegExp(`(^|[\\s,(])(${word}($|[\\s(,]))`, 'gi') |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
module.exports.editList = function (value, callback) { |
| 52 |
let origin = list.comma(value) |
| 53 |
let changed = callback(origin, []) |
| 54 |
|
| 55 |
if (origin === changed) { |
| 56 |
return value |
| 57 |
} |
| 58 |
|
| 59 |
let join = value.match(/,\s*/) |
| 60 |
join = join ? join[0] : ', ' |
| 61 |
return changed.join(join) |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
module.exports.splitSelector = function (selector) { |
| 73 |
return list.comma(selector).map(i => { |
| 74 |
return list.space(i).map(k => { |
| 75 |
return k.split(/(?=\.|#)/g) |
| 76 |
}) |
| 77 |
}) |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
module.exports.isPureNumber = function (value) { |
| 86 |
if (typeof value === 'number') { |
| 87 |
return true |
| 88 |
} |
| 89 |
if (typeof value === 'string') { |
| 90 |
return /^[0-9]+$/.test(value) |
| 91 |
} |
| 92 |
return false |
| 93 |
} |