You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: comprehensive rewrite and modernization of codenames library
- Refactored core API to support both default cities-20 and custom word lists
- Added comprehensive test coverage across all modules and themes
- Restructured project with proper TypeScript types and ESM exports
- Enhanced CLI with better theme handling and error messages
- Updated README with detailed API documentation and practical examples
- Added extensive blog post documentation for preview deployments
- Improved word list generation scripts and validation
- Added proper SPDX license headers to all source files
- Enhanced factory pattern for theme-specific codename functions
- Implemented robust error handling for edge cases and invalid inputs
A lightweight TypeScript library that converts any number into consistent, memorable codename from a curated word list. It's designed for use cases where human-readability is more important than collision resistance, such as generating preview URLs or readable test IDs.
10
10
11
11
```typescript
12
-
//Codename generator using the most memorable 20 cities
13
-
importcodenamefrom"codenames/cities-20";
12
+
//Default: uses the cities-20 word list
13
+
importcodenamefrom"codenames";
14
14
15
-
codename(1234); // "london", uses "cities"
15
+
codename(1234); // "london"
16
16
codename(1234); // "london" (always the same)
17
17
codename(5678); // "paris"
18
18
codename(6789); // "berlin"
19
+
20
+
// With custom words
21
+
codename(1234, ["one", "two", "three"]); // "two"
19
22
```
20
23
21
24
## Features
22
25
23
26
-**🎯 Deterministic** - Same input always produces the same codename
24
27
-**💬 Human-Readable** - Memorable names instead of random strings
25
28
-**🚀 Zero Dependencies** - Lightweight and fast with no external packages
26
-
-**⚡ Fast** - 50,000+ generations per second
27
-
-**📦 <3KB Core** - Ultra-minimal footprint, themes add ~2KB each
29
+
-**⚡ Fast & Tiny** - 50,000+ generations per second, <3KB core + ~2KB per theme
28
30
-**🌐 Universal Runtime** - Works in Node.js, Bun, Deno, browsers, and edge runtimes
29
31
-**🎨 Multiple Themes** - Cities, animals, colors, space, and more built-in themes
30
-
-**📦 Modern JavaScript** - TypeScript with full type safety, ESM package
31
-
-**📝 Customizable** - Create your own themes and word lists
32
32
-**🤖 CLI Included** - Generate codenames directly from your terminal
33
33
34
34
## Use Cases
35
35
36
-
-**Preview Deployments** - Generate unique URLs for pull requests
-**Session IDs** - User-friendly session identifiers for support
39
-
-**Feature Flags** - Human-friendly names for A/B tests
40
-
-**Test Environments** - Readable identifiers for testing pipelines
41
-
-**Test Data Generation** - Consistent test data generation
36
+
### Preview Deployments
37
+
38
+
Managing preview environments can get messy. You end up tracking which PR is deployed where, maintaining state, dealing with conflicts. Here's a simpler approach: use deterministic hashing to map PR numbers to memorable names.
With 20 city names, you get 20 deployment slots. No database needed. The same PR number always produces the same city name, so URLs stay consistent throughout the PR lifecycle.
53
+
54
+
Plus, it's easier to share "london.example.com" in Slack than "preview-env-1234.k8s.us-east-1.example.com".
55
+
56
+
### Other Uses
57
+
58
+
-**Docker Containers**: `docker run --name "app-${codename(buildId)}" myapp` → `app-tokyo`
59
+
-**Session IDs**: `vienna-support` is friendlier than `sess_kJ8Hg2Bx9`
60
+
-**Feature Flags**: `berlin-experiment` instead of `experiment_42`
0 commit comments