source: imaps-frontend/node_modules/postcss/lib/list.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[d565449]1'use strict'
2
3let list = {
4 comma(string) {
5 return list.split(string, [','], true)
6 },
7
8 space(string) {
9 let spaces = [' ', '\n', '\t']
10 return list.split(string, spaces)
11 },
12
13 split(string, separators, last) {
14 let array = []
15 let current = ''
16 let split = false
17
18 let func = 0
19 let inQuote = false
20 let prevQuote = ''
21 let escape = false
22
23 for (let letter of string) {
24 if (escape) {
25 escape = false
26 } else if (letter === '\\') {
27 escape = true
28 } else if (inQuote) {
29 if (letter === prevQuote) {
30 inQuote = false
31 }
32 } else if (letter === '"' || letter === "'") {
33 inQuote = true
34 prevQuote = letter
35 } else if (letter === '(') {
36 func += 1
37 } else if (letter === ')') {
38 if (func > 0) func -= 1
39 } else if (func === 0) {
40 if (separators.includes(letter)) split = true
41 }
42
43 if (split) {
44 if (current !== '') array.push(current.trim())
45 current = ''
46 split = false
47 } else {
48 current += letter
49 }
50 }
51
52 if (last || current !== '') array.push(current.trim())
53 return array
54 }
55}
56
57module.exports = list
58list.default = list
Note: See TracBrowser for help on using the repository browser.