in packages/core/src/utils/path.ts [13:74]
static parse(str: string): Directive[] {
const result: Directive[] = []
const coords: string[] = []
let currentPath: string
let parsed: number
let match: RegExpExecArray | null = null
let coordsStr: string
if (!str || !str.match) {
return result
}
const path = str.match(InvalidDirectiveReg)
if (!path) {
return result
}
for (let i = 0, n = path.length; i < n; i++) {
currentPath = path[i]
coordsStr = currentPath.slice(1).trim()
coords.length = 0
let command = currentPath.charAt(0)
const coordsParsed: Directive = [command]
if (command.toLowerCase() === 'a') {
for (let args; (args = ArcArgsReg.exec(coordsStr));) {
for (let j = 1; j < args.length; j++) {
coords.push(args[j])
}
}
}
else {
while ((match = FirstArgReg.exec(coordsStr))) {
coords.push(match[0])
}
}
for (let j = 0, jlen = coords.length; j < jlen; j++) {
parsed = parseFloat(coords[j])
if (!isNaN(parsed)) {
coordsParsed.push(parsed)
}
}
const commandLength = ArgLengths[command.toLowerCase()]
const repeatedCommand = RepeatedCommands[command] || command
if (coordsParsed.length - 1 > commandLength) {
for (let k = 1, klen = coordsParsed.length; k < klen; k += commandLength) {
result.push(([command] as Directive).concat(coordsParsed.slice(k, k + commandLength) as number[]) as Directive)
command = repeatedCommand
}
} else {
result.push(coordsParsed)
}
}
return result
}