Skip to content

Commit eaac6f2

Browse files
fix(utils): quality improvements (#963)
* Simplify regex * Improve trailing slash * Remove regex inside regex * Add comment
1 parent b14d189 commit eaac6f2

4 files changed

Lines changed: 4 additions & 6 deletions

File tree

packages/utils/source/is-git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export const isGit = (value: string): boolean =>
2-
new RegExp(/(?:git|ssh|https?|git@[\w.-]+):(\/\/)?(.*?)(\.git)(\/?|#[\w.-]+?)$/).test(value);
2+
/(?:git|ssh|https?|git@[\w.-]+):(\/\/)?(.*?)(\.git)(\/?|#[\w.-]+?)$/.test(value);

packages/utils/source/set.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const set = <T>(object: T, path: string | string[], value: unknown): bool
1616
object[pathSegment] = {};
1717
}
1818

19+
// Prototype pollution check is not needed here, because getPathSegments filters out
1920
if (index === pathSegments.length - 1) {
2021
object[pathSegment] = value;
2122
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const trimTrailingSlash = (value: string): string => value.replaceAll(/\/+$/g, "");
1+
export const trimTrailingSlash = (value: string): string => value.replace(/\/+$/, "");

packages/utils/source/words.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
export const words = (value: string): string[] | null =>
2-
value.match(
3-
/[A-Z\u00C0-\u00D6\u00D8-\u00DE]?[a-z\u00DF-\u00F6\u00F8-\u00FF]+|[A-Z\u00C0-\u00D6\u00D8-\u00DE]+(?![a-z\u00DF-\u00F6\u00F8-\u00FF])|\d+/g,
4-
);
1+
export const words = (value: string): string[] | null => value.match(/\p{Lu}+(?!\p{Ll})|\p{Lu}?\p{Ll}+|\d+/gu);

0 commit comments

Comments
 (0)