Sha256: 6df35bac40d4c449ae8e9078776e5c17c529337830a01472761902a546032f52

Contents?: true

Size: 1.2 KB

Versions: 27

Compression:

Stored size: 1.2 KB

Contents

'use strict'

let list = {
  comma(string) {
    return list.split(string, [','], true)
  },

  space(string) {
    let spaces = [' ', '\n', '\t']
    return list.split(string, spaces)
  },

  split(string, separators, last) {
    let array = []
    let current = ''
    let split = false

    let func = 0
    let inQuote = false
    let prevQuote = ''
    let escape = false

    for (let letter of string) {
      if (escape) {
        escape = false
      } else if (letter === '\\') {
        escape = true
      } else if (inQuote) {
        if (letter === prevQuote) {
          inQuote = false
        }
      } else if (letter === '"' || letter === "'") {
        inQuote = true
        prevQuote = letter
      } else if (letter === '(') {
        func += 1
      } else if (letter === ')') {
        if (func > 0) func -= 1
      } else if (func === 0) {
        if (separators.includes(letter)) split = true
      }

      if (split) {
        if (current !== '') array.push(current.trim())
        current = ''
        split = false
      } else {
        current += letter
      }
    }

    if (last || current !== '') array.push(current.trim())
    return array
  }
}

module.exports = list
list.default = list

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/postcss/lib/list.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/postcss/lib/list.js