-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve namespace readability and potential optimization confli…
…ct (#2928) * fix: allow dash in namespace * feat: reduce multiple dashed and underscores into a single lodash or underscore * feat: support non-ascii namespace from filename * feat: validate st-namespace similarly to filename ns-resolve
- Loading branch information
Showing
8 changed files
with
78 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,30 @@ | ||
/* eslint-disable no-control-regex */ | ||
export function stripQuotation(str: string) { | ||
return str.replace(/^['"](.*?)['"]$/g, '$1'); | ||
} | ||
|
||
export function filename2varname(filename: string) { | ||
return string2varname(filename.replace(/(?=.*)\.\w+$/, '').replace(/\.st$/, '')); | ||
return string2varname( | ||
filename | ||
// remove extension (eg. .css) | ||
.replace(/(?=.*)\.\w+$/, '') | ||
// remove potential .st extension prefix | ||
.replace(/\.st$/, '') | ||
); | ||
} | ||
|
||
function string2varname(str: string) { | ||
return str.replace(/[^0-9a-zA-Z_]/gm, '').replace(/^[^a-zA-Z_]+/gm, ''); | ||
export function string2varname(str: string) { | ||
return ( | ||
str | ||
// allow only letters, numbers, dashes, underscores, and non-ascii | ||
.replace(/[\x00-\x7F]+/gm, (matchAscii) => { | ||
return matchAscii.replace(/[^0-9a-zA-Z_-]/gm, ''); | ||
}) | ||
// replace multiple dashes with single dash | ||
.replace(/--+/gm, '-') | ||
// replace multiple underscores with single underscore | ||
.replace(/__+/gm, '_') | ||
// remove leading digits from start | ||
.replace(/^\d+/gm, '') | ||
); | ||
} |
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
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