Files
SnowLuma/.pnpm-store/v11/files/22/a6d61716aa7e777c0a2bb374435a7eb4b60a81eb0154dd4dfda5cfa0cf5087e87b427386ca8feecc0bda2c92bf74170f44e604b0269584a6a3ba1e24414c33
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

62 lines
1.3 KiB
Plaintext

'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) {
if (typeof string !== 'string') return []
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) {
let value = current.trim()
if (last || value !== '') array.push(value)
current = ''
split = false
} else {
current += letter
}
}
let value = current.trim()
if (last || value !== '') array.push(value)
return array
}
}
module.exports = list
list.default = list