From 2072965e38579899cd47c7cad8f522193513e2ba Mon Sep 17 00:00:00 2001 From: Alexander Harding <2166114+aeharding@users.noreply.github.com> Date: Mon, 19 Feb 2024 22:32:16 -0600 Subject: [PATCH] Remove negative lookbehind workaround Negative lookbehinds were added in Safari 16.4, released March 26, 2023. https://caniuse.com/?search=negative%20lookbehind So, I plan on merging this PR around the end of March 2024 in a major version bump --- src/parser/parser.ts | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/src/parser/parser.ts b/src/parser/parser.ts index 4dd1f23..bc5b894 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -160,18 +160,17 @@ export abstract class AbstractParser { BECMG = "BECMG"; RMK = "RMK"; - // Safari does not currently support negative lookbehind - // #TOKENIZE_REGEX = /\s((?=\d\/\dSM)(? v); - - // Hack for safari below... - const splitRegex = /\s|=/; - const smRegex = /^\d\/\dSM$/; - const digitRegex = /^(P|M)?\d$/; - - // return input.split(this.#TOKENIZE_REGEX).filter((v) => v); - const splitted = input.split(splitRegex); - - for (let i = 0; i < splitted.length; i++) { - if (digitRegex.test(splitted[i])) { - if (splitted[i + 1] && smRegex.test(splitted[i + 1])) { - splitted.splice(i, 2, `${splitted[i]} ${splitted[i + 1]}`); - } - } - } - - return splitted.filter((t) => t); + return input.split(AbstractParser.#TOKENIZE_REGEX).filter((v) => v); } /** @@ -260,7 +240,7 @@ export abstract class AbstractParser { abstractWeatherContainer: IAbstractWeatherContainer, input: string, ): boolean { - if (input === this.#CAVOK) { + if (input === AbstractParser.#CAVOK) { abstractWeatherContainer.cavok = true; abstractWeatherContainer.visibility = { indicator: ValueIndicator.GreaterThan, @@ -278,7 +258,7 @@ export abstract class AbstractParser { return true; } - const command = this.#commonSupplier.get(input); + const command = AbstractParser.#commonSupplier.get(input); if (command) { try {