Skip to content

Commit c0fc858

Browse files
authored
Add CLI Tool for nano-string-utils (#28)
* add cli tool * fix tests
1 parent a279606 commit c0fc858

File tree

7 files changed

+674
-3
lines changed

7 files changed

+674
-3
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ jobs:
5353
- name: Install dependencies
5454
run: npm ci
5555

56+
- name: Build the library
57+
run: npm run build
58+
5659
- name: Run tests
5760
run: npm test
5861

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.12.0] - 2025-09-17
11+
12+
### Added
13+
14+
- **CLI Tool** - Zero-dependency command-line interface for string utilities
15+
- New `nano-string` command available via `npx nano-string-utils` or global installation
16+
- Support for all 40+ library functions directly from the terminal
17+
- Pipe support for Unix-style command chaining
18+
- Options handling for complex functions (template, truncate, pad, etc.)
19+
- Comprehensive help system with global and per-function documentation
20+
- Smart argument parsing with JSON support for complex data
21+
- Boolean output with proper exit codes for validation functions
22+
- Full test coverage with 39 CLI-specific test cases
23+
- Examples: `nano-string slugify "Hello World"`, `echo "text" | nano-string kebabCase`
24+
1025
## [0.11.0] - 2025-09-17
1126

1227
### Added
1328

1429
- **Interactive Migration Guide** - Comprehensive guide for migrating from lodash/underscore
30+
1531
- Interactive documentation site with migration guide section
1632
- Complete function mapping table showing lodash → nano-string-utils equivalents
1733
- Step-by-step migration instructions with code examples
@@ -296,6 +312,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
296312
- 100% test coverage for utility functions
297313
- Modern build tooling with tsup and Vitest
298314

315+
[0.12.0]: https://github.com/Zheruel/nano-string-utils/releases/tag/v0.12.0
316+
[0.11.0]: https://github.com/Zheruel/nano-string-utils/releases/tag/v0.11.0
299317
[0.10.0]: https://github.com/Zheruel/nano-string-utils/releases/tag/v0.10.0
300318
[0.9.1]: https://github.com/Zheruel/nano-string-utils/releases/tag/v0.9.1
301319
[0.9.0]: https://github.com/Zheruel/nano-string-utils/releases/tag/v0.9.0

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,100 @@ camelCase("hello-world"); // 'helloWorld'
7676
truncate("Long text here", 10); // 'Long te...'
7777
```
7878

79+
## CLI
80+
81+
Nano String Utils includes a command-line interface for quick string transformations directly in your terminal.
82+
83+
### Installation
84+
85+
When installed globally or used with `npx`, the CLI is available as `nano-string`:
86+
87+
```bash
88+
# Global installation
89+
npm install -g nano-string-utils
90+
nano-string slugify "Hello World"
91+
92+
# Using npx (no installation required)
93+
npx nano-string-utils slugify "Hello World"
94+
```
95+
96+
### Basic Usage
97+
98+
```bash
99+
nano-string <function> <input> [options]
100+
```
101+
102+
### Examples
103+
104+
#### Simple transformations
105+
```bash
106+
nano-string slugify "Hello World!" # hello-world
107+
nano-string camelCase "hello-world" # helloWorld
108+
nano-string kebabCase "hello_world" # hello-world
109+
nano-string capitalize "hello" # Hello
110+
nano-string reverse "hello" # olleh
111+
```
112+
113+
#### Using pipes
114+
```bash
115+
echo "Hello World" | nano-string slugify # hello-world
116+
cat file.txt | nano-string truncate --length 50
117+
```
118+
119+
#### Functions with options
120+
```bash
121+
# Truncate with custom length
122+
nano-string truncate "Long text here" --length 10 # Long te...
123+
124+
# Template interpolation
125+
nano-string template "Hello {{name}}" --data '{"name":"World"}' # Hello World
126+
127+
# Pad strings
128+
nano-string padStart "hi" --length 5 --char "*" # ***hi
129+
130+
# Generate random strings
131+
nano-string randomString --length 10 # Generates 10-character string
132+
```
133+
134+
#### Validation functions
135+
```bash
136+
nano-string isEmail "[email protected]" # true
137+
nano-string isUrl "https://example.com" # true
138+
nano-string isASCII "hello" # true
139+
```
140+
141+
#### Analysis functions
142+
```bash
143+
nano-string wordCount "hello world test" # 3
144+
nano-string levenshtein "kitten" "sitting" # 3
145+
nano-string diff "hello" "hallo" # Shows differences
146+
```
147+
148+
### Available Commands
149+
150+
To see all available functions:
151+
```bash
152+
nano-string --help
153+
```
154+
155+
For help on a specific function:
156+
```bash
157+
nano-string slugify --help
158+
```
159+
160+
### Supported Functions
161+
162+
The CLI supports most functions from the library:
163+
- **Case Conversions**: slugify, camelCase, snakeCase, kebabCase, pascalCase, constantCase, dotCase, pathCase, sentenceCase, titleCase
164+
- **String Manipulation**: capitalize, reverse, truncate, excerpt, pad, padStart, padEnd
165+
- **Text Processing**: stripHtml, escapeHtml, deburr, normalizeWhitespace, removeNonPrintable, toASCII
166+
- **Validation**: isEmail, isUrl, isASCII
167+
- **Analysis**: wordCount, levenshtein, levenshteinNormalized, diff
168+
- **Generation**: randomString, hashString
169+
- **Unicode**: graphemes, codePoints
170+
- **Pluralization**: pluralize, singularize
171+
- **Templates**: template, templateSafe, highlight, fuzzyMatch
172+
79173
## API Reference
80174

81175
### String Transformation

0 commit comments

Comments
 (0)