CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
utils.js94 linesDownload Raw Back to lib
1let { list } = require('postcss')2 3/**4 * Throw special error, to tell beniary,5 * that this error is from Autoprefixer.6 */7module.exports.error = function (text) {8  let err = new Error(text)9  err.autoprefixer = true10  throw err11}12 13/**14 * Return array, that doesn’t contain duplicates.15 */16module.exports.uniq = function (array) {17  return [...new Set(array)]18}19 20/**21 * Return "-webkit-" on "-webkit- old"22 */23module.exports.removeNote = function (string) {24  if (!string.includes(' ')) {25    return string26  }27 28  return string.split(' ')[0]29}30 31/**32 * Escape RegExp symbols33 */34module.exports.escapeRegexp = function (string) {35  return string.replace(/[$()*+-.?[\\\]^{|}]/g, '\\$&')36}37 38/**39 * Return regexp to check, that CSS string contain word40 */41module.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 * Change comma list50 */51module.exports.editList = function (value, callback) {52  let origin = list.comma(value)53  let changed = callback(origin, [])54 55  if (origin === changed) {56    return value57  }58 59  let join = value.match(/,\s*/)60  join = join ? join[0] : ', '61  return changed.join(join)62}63 64/**65 * Split the selector into parts.66 * It returns 3 level deep array because selectors can be comma67 * separated (1), space separated (2), and combined (3)68 * @param {String} selector selector string69 * @return {Array<Array<Array>>} 3 level deep array of split selector70 * @see utils.test.js for examples71 */72module.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 * Return true if a given value only contains numbers.82 * @param {*} value83 * @returns {boolean}84 */85module.exports.isPureNumber = function (value) {86  if (typeof value === 'number') {87    return true88  }89  if (typeof value === 'string') {90    return /^[0-9]+$/.test(value)91  }92  return false93}94