Skip to content
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vscode/**
.vscode/**
my-repo*
test-*
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ echo "My Tool" | ./create-package

Package names are automatically sanitized:
- Converted to lowercase
- Any run of whitespace characters (spaces, tabs, etc.) is replaced with a single dash
- All other special characters are removed (only `[a-z0-9-]` are retained)
- Spaces and underscores are replaced with dashes
- Only `[a-z0-9-]` characters are retained (letters, numbers, dashes)
- Multiple consecutive dashes are collapsed into one
Expand All @@ -37,6 +39,11 @@ Package names are automatically sanitized:
# Creates: my-tool/my-tool
./create-package "My Tool"

# Creates: my-repo/my-repo
./create-package "my repo"

# Creates: my-repo2/my-repo2
./create-package "my ^ repo2"
# Creates: hello-world/hello-world
echo "Hello_World" | ./create-package

Expand Down
2 changes: 2 additions & 0 deletions create-package
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ fi

# Sanitize the package name:
# 1. Convert to lowercase
# 2. Replace any run of whitespace characters with a single dash
# 2. Replace spaces and underscores with dashes
# 3. Remove any characters that are not [a-z0-9-]
# 4. Collapse multiple consecutive dashes into one
# 5. Remove leading/trailing dashes
sanitized=$(echo "$package_name" | \
tr '[:upper:]' '[:lower:]' | \
sed 's/[[:space:]]\+/-/g' | \
tr ' _' '-' | \
sed 's/[^a-z0-9-]//g' | \
sed 's/-\+/-/g' | \
Expand Down