Skip to content

Commit

Permalink
refactor: extractors are even more elegant
Browse files Browse the repository at this point in the history
  • Loading branch information
sghuang19 committed Feb 18, 2025
1 parent 32a01b0 commit 05e71e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 32 deletions.
8 changes: 2 additions & 6 deletions __test__/test.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Test Cases

<NButton>
<NButton> and <NButtonGroup>

<NButtonGroup>

<n-alert>

<n-config-provider>
<n-alert> and <n-config-provider>
14 changes: 7 additions & 7 deletions src/extractor.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
param(
[string] $FilePath
)
param( [string] $FilePath )

Get-Content $FilePath |
Select-String -AllMatches '(?<=<)(N[A-Z]|n-)[A-Za-z-]*' |
ForEach-Object { $_.Matches.Value } |
Sort-Object -Unique |
ForEach-Object {
$_ -match '^N[A-Z]' ?
$_ -clike 'N*' ?
$_ :
$_ -split '-' |
ForEach-Object { $_[0].ToString().ToUpper() + $_.Substring(1) } |
Join-String
(
$_ -split '-' |
ForEach-Object { (Get-Culture).TextInfo.ToTitleCase($_) } |
Join-String
)
} |
Sort-Object -Unique
26 changes: 7 additions & 19 deletions src/extractor.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
FILE_PATH=${1:-"slides.md"}

grep -o '<\(N[A-Z]\|n-\)[A-Za-z-]*' "$FILE_PATH" \
| sort | uniq \
| sort -u \
| sed -E 's/^<//' \
| while read -r line; do
case "$line" in
N[A-Z]*)
echo "$line"
;;
n-*)
echo "$line" \
| sed 's/-/ /g' \
| awk '{
for (i=1; i<=NF; i++)
$i=toupper(substr($i,1,1)) substr($i,2)
print $0
}' \
| sed 's/ //g'
;;
esac
done \
| sort | uniq
| awk -F'-' '$1 == "n" {
OFS=""
for (i=1; i<=NF; i++)
$i=toupper(substr($i,1,1)) substr($i,2)
} 1' \
| sort -u

0 comments on commit 05e71e3

Please sign in to comment.