123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- let { list } = require('postcss')
- module.exports.error = function (text) {
- let err = new Error(text)
- err.autoprefixer = true
- throw err
- }
- module.exports.uniq = function (array) {
- return [...new Set(array)]
- }
- module.exports.removeNote = function (string) {
- if (!string.includes(' ')) {
- return string
- }
- return string.split(' ')[0]
- }
- module.exports.escapeRegexp = function (string) {
- return string.replace(/[$()*+-.?[\\\]^{|}]/g, '\\$&')
- }
- module.exports.regexp = function (word, escape = true) {
- if (escape) {
- word = this.escapeRegexp(word)
- }
- return new RegExp(`(^|[\\s,(])(${word}($|[\\s(,]))`, 'gi')
- }
- module.exports.editList = function (value, callback) {
- let origin = list.comma(value)
- let changed = callback(origin, [])
- if (origin === changed) {
- return value
- }
- let join = value.match(/,\s*/)
- join = join ? join[0] : ', '
- return changed.join(join)
- }
- module.exports.splitSelector = function (selector) {
- return list.comma(selector).map(i => {
- return list.space(i).map(k => {
- return k.split(/(?=\.|#)/g)
- })
- })
- }
- module.exports.isPureNumber = function (value) {
- if (typeof value === 'number') {
- return true
- }
- if (typeof value === 'string') {
- return /^[0-9]+$/.test(value)
- }
- return false
- }
|