wishthis/node_modules/postcss/lib/list.js

59 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-08-17 09:47:40 +00:00
'use strict'
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
let list = {
comma(string) {
return list.split(string, [','], true)
},
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
space(string) {
let spaces = [' ', '\n', '\t']
return list.split(string, spaces)
},
2022-01-21 08:28:41 +00:00
2023-08-17 09:47:40 +00:00
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
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
} else if (letter === '"' || letter === "'") {
inQuote = true
prevQuote = letter
2022-01-21 08:28:41 +00:00
} else if (letter === '(') {
2023-08-17 09:47:40 +00:00
func += 1
2022-01-21 08:28:41 +00:00
} else if (letter === ')') {
2023-08-17 09:47:40 +00:00
if (func > 0) func -= 1
2022-01-21 08:28:41 +00:00
} else if (func === 0) {
2023-08-17 09:47:40 +00:00
if (separators.includes(letter)) split = true
2022-01-21 08:28:41 +00:00
}
if (split) {
2023-08-17 09:47:40 +00:00
if (current !== '') array.push(current.trim())
current = ''
split = false
2022-01-21 08:28:41 +00:00
} else {
2023-08-17 09:47:40 +00:00
current += letter
2022-01-21 08:28:41 +00:00
}
}
2023-08-17 09:47:40 +00:00
if (last || current !== '') array.push(current.trim())
return array
2022-01-21 08:28:41 +00:00
}
2023-08-17 09:47:40 +00:00
}
module.exports = list
list.default = list