diff --git a/src/const.ts b/src/const.ts index 84f20c5..26cea53 100644 --- a/src/const.ts +++ b/src/const.ts @@ -1,3 +1,3 @@ export const TAG_UNESCAPED = ['\\', ' ', ';', '\r', '\n'] -export const TAG_UNESCAPED_REGEX = [/\\\\/g, / /g, /;/g, /\r/g, /\n/g] +export const TAG_UNESCAPED_REGEX = [/\\/g, / /g, /;/g, /\r/g, /\n/g] export const TAG_ESCAPED = ['\\\\', '\\s', '\\:', '\\r', '\\n'] diff --git a/src/formatting.ts b/src/formatting.ts index 0c13076..4ecd1b5 100644 --- a/src/formatting.ts +++ b/src/formatting.ts @@ -33,7 +33,7 @@ export function format ({ tags, source, command, params }: FormatArgs) { outs.push(command) - if (params) { + if (params?.length) { const paramCopy = [...params] let last = paramCopy.pop() diff --git a/src/line.ts b/src/line.ts index 473ecf4..53f10f4 100644 --- a/src/line.ts +++ b/src/line.ts @@ -56,8 +56,9 @@ export class Line { } } -function unescapeTag (value: string) { +function unescapeTag (value?: string) { let unescaped = '' + if (!value) return unescaped const escaped = value.split('') while (escaped.length) { const current = escaped.shift() as string @@ -102,7 +103,7 @@ function _tokenise (line: string) { if (!params.length) throw TypeError('Cannot tokenise command-less line') const command = (params.shift() as string).toLocaleUpperCase() - if (trailing) params.push(trailing) + if (typeof trailing === 'string') params.push(trailing) return new Line({ tags,