Skip to content

Repository files navigation

@se-oss/braces
CI NPM Version MIT License npm bundle size Install Size

@se-oss/braces is a high-performance, V8-safe numeric and alphabetical range expander and regular expression compiler.


📦 Installation

pnpm add @se-oss/braces
Install using your favorite package manager

npm

npm install @se-oss/braces

yarn

yarn add @se-oss/braces

📖 Usage

Range Expansion

Expand numeric or alphabetical range patterns with optional stepping.

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.

import { expandRange } from '@se-oss/braces';

expandRange('1..5..2'); // ['1', '3', '5']

Zero-Padding Preservation

Automatically preserves leading zeros in numeric ranges.

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.

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.

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.

Thanks again for your support, it is much appreciated! 🙏

License

MIT © Shahrad Elahi and contributors.

About

⚡ High-performance, V8-safe numeric & alphabetical range expander and regex compiler.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages