https://github.com/shahradelahi/ts-braces
⚡ High-performance, V8-safe numeric & alphabetical range expander and regex compiler.
https://github.com/shahradelahi/ts-braces
alphabetical-range braces numeric-range range-expansion regex-compiler typescript v8-safe
Last synced: 29 days ago
JSON representation
⚡ High-performance, V8-safe numeric & alphabetical range expander and regex compiler.
- Host: GitHub
- URL: https://github.com/shahradelahi/ts-braces
- Owner: shahradelahi
- License: mit
- Created: 2026-06-18T09:38:47.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-06-19T11:17:59.000Z (about 1 month ago)
- Last Synced: 2026-06-19T13:09:01.077Z (about 1 month ago)
- Topics: alphabetical-range, braces, numeric-range, range-expansion, regex-compiler, typescript, v8-safe
- Language: TypeScript
- Homepage: https://npmjs.com/@se-oss/braces
- Size: 83 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
@se-oss/braces
_@se-oss/braces_ is a high-performance, V8-safe numeric and alphabetical range expander and regular expression compiler.
---
- [Installation](#-installation)
- [Usage](#-usage)
- [Documentation](#-documentation)
- [Contributing](#-contributing)
- [License](#license)
## 📦 Installation
```bash
pnpm add @se-oss/braces
```
Install using your favorite package manager
**npm**
```bash
npm install @se-oss/braces
```
**yarn**
```bash
yarn add @se-oss/braces
```
## 📖 Usage
### Range Expansion
Expand numeric or alphabetical range patterns with optional stepping.
```ts
import { expandRange } from '@se-oss/braces';
// Numeric ranges
expandRange('1..3'); // ['1', '2', '3']
// Alphabetical ranges
expandRange('a..c'); // ['a', 'b', 'c']
```
### Step Parameters
Specify a custom step interval for the range.
```ts
import { expandRange } from '@se-oss/braces';
expandRange('1..5..2'); // ['1', '3', '5']
```
### Zero-Padding Preservation
Automatically preserves leading zeros in numeric ranges.
```ts
import { expandRange } from '@se-oss/braces';
expandRange('01..03'); // ['01', '02', '03']
```
### Expansion Limit & Errors
Enforce safety limits on large range expansions to prevent resource exhaustion.
```ts
import { BraceLimitError, expandRange } from '@se-oss/braces';
try {
// Try to expand a huge range with a low threshold limit
expandRange('1..10000', 10);
} catch (error) {
if (error instanceof BraceLimitError) {
console.error('Expansion limit exceeded!');
}
}
```
### V8-Safe Regular Expression Compiler
Compile numeric ranges into highly optimized and V8-safe regular expression patterns.
```ts
import { compileNumericRange } from '@se-oss/braces';
const pattern = compileNumericRange(1, 250);
// returns: "[1-9]|[1-9]\d|1\d{2}|2[0-4]\d|250"
const regex = new RegExp(`^(?:${pattern})$`);
regex.test('99'); // true
regex.test('250'); // true
regex.test('251'); // false
```
## 📚 Documentation
For more information, please see the JSDoc comments or check the source code.
## 🤝 Contributing
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on [GitHub](https://github.com/shahradelahi/ts-braces).
Thanks again for your support, it is much appreciated! 🙏
## License
[MIT](/LICENSE) © [Shahrad Elahi](https://github.com/shahradelahi) and [contributors](https://github.com/shahradelahi/ts-braces/graphs/contributors).