-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): use suglify to find commune by name
- Loading branch information
1 parent
8b666eb
commit 71fc88c
Showing
4 changed files
with
38 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Slugify a string by removing accents, converting to lowercase, and replacing | ||
* spaces with hyphens. | ||
* | ||
* @note It's used to generate the slugified name of the communes. | ||
* | ||
* Source: https://byby.dev/js-slugify-string | ||
*/ | ||
export function slugify(str: string): string { | ||
return str | ||
.normalize("NFKD") // split accented characters into their base characters and diacritical marks | ||
.replace(/[\u0300-\u036f]/g, "") // remove all the accents, which happen to be all in the \u03xx UNICODE block. | ||
.trim() // trim leading or trailing whitespace | ||
.replace("œ", "oe") // Remove invalid chars | ||
.toLowerCase() // convert to lowercase | ||
.replace(/[^a-z0-9 -]/g, "") // remove non-alphanumeric characters | ||
.replace(/\s+/g, "-") // replace spaces with hyphens | ||
.replace(/-+/g, "-"); // remove consecutive hyphens | ||
} |
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