Son CV dans un terminal web en Javascript!
https://terminal-cv.gregandev.fr
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.1 KiB
56 lines
1.1 KiB
'use strict'
|
|
|
|
let list = {
|
|
split(string, separators, last) {
|
|
let array = []
|
|
let current = ''
|
|
let split = false
|
|
|
|
let func = 0
|
|
let quote = false
|
|
let escape = false
|
|
|
|
for (let letter of string) {
|
|
if (escape) {
|
|
escape = false
|
|
} else if (letter === '\\') {
|
|
escape = true
|
|
} else if (quote) {
|
|
if (letter === quote) {
|
|
quote = false
|
|
}
|
|
} else if (letter === '"' || letter === "'") {
|
|
quote = 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
|
|
},
|
|
|
|
space(string) {
|
|
let spaces = [' ', '\n', '\t']
|
|
return list.split(string, spaces)
|
|
},
|
|
|
|
comma(string) {
|
|
return list.split(string, [','], true)
|
|
}
|
|
}
|
|
|
|
module.exports = list
|
|
list.default = list
|
|
|