-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimizations and refactoring; moving js tests to ts
- Loading branch information
1 parent
5ce02d3
commit a9df87a
Showing
11 changed files
with
613 additions
and
487 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,42 @@ | ||
const uuid = "[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}"; | ||
const uuid = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"; | ||
|
||
const uuidRegExp = new RegExp(uuid, "i"); | ||
const extractUuidRegExp = new RegExp("^{?(" + uuid + ")}?$", "i"); | ||
const extractUuidFromUrlRegExp = new RegExp("(" + uuid + ")\\)$", "i"); | ||
//global here is fine because the state is reset inside string.replace function | ||
const removeBracketsFromGuidReg = new RegExp(`{(${uuid})}`, "g"); | ||
|
||
export function isUuid(value: string): boolean { | ||
const match = new RegExp(uuid, "i").exec(value); | ||
const match = uuidRegExp.exec(value); | ||
return !!match; | ||
} | ||
|
||
export function extractUuid(value: string): string | null { | ||
const match = new RegExp("^{?(" + uuid + ")}?$", "i").exec(value); | ||
const match = extractUuidRegExp.exec(value); | ||
return match ? match[1] : null; | ||
} | ||
|
||
export function extractUuidFromUrl(url: string): string | null { | ||
const match = new RegExp("(" + uuid + ")\\)$", "i").exec(url); | ||
const match = extractUuidFromUrlRegExp.exec(url); | ||
return match ? match[1] : null; | ||
} | ||
|
||
export function removeCurlyBracketsFromUuid(value: string): string { | ||
return value.replace(removeBracketsFromGuidReg, (_match, p1) => p1); | ||
} | ||
|
||
export function safelyRemoveCurlyBracketsFromUrl(url: string): string { | ||
//todo: in future I will need to replace this with a negative lookbehind and lookahead | ||
|
||
// Split the filter string by quotation marks | ||
const parts = url.split(/(["'].*?["'])/); | ||
return parts | ||
.map((part, index) => { | ||
// Only process parts that are not within quotes | ||
if (index % 2 === 0) { | ||
return removeCurlyBracketsFromUuid(part); | ||
} | ||
return part; | ||
}) | ||
.join(""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.