fill-range
Fill in a range of numbers or letters — "1".."5" → ["1","2","3","4","5"],
"a".."e" → ["a","b","c","d","e"], with an optional step and automatic
zero-padding. A faithful Rust port of the
fill-range npm package (the range
expander behind braces/micromatch). Zero dependencies and #![no_std].
use ;
assert_eq!;
assert_eq!;
assert_eq!; // auto-padded
assert_eq!; // descending
assert_eq!;
Why fill-range?
Expanding 1..100 or a..z (with steps, padding, and either direction) is the kind
of thing every shell, template engine, and glob library needs. This is the canonical
JS algorithm, ported faithfully so the edge cases — descending ranges, negatives,
zero-padding across the sign — all match.
[]
= "0.1"
API
| Item | Purpose |
|---|---|
fill(start, end) |
The range as a Vec<String> (step 1) |
fill_step(start, end, step) |
…with a step (magnitude; direction from the bounds) |
Bounds are passed as &str so leading zeros are preserved ("01"); they must both
be integers or both single letters. An invalid range returns an empty list.
Behavior
- Either direction:
fill("5", "1")counts down. - Negatives and crossing zero work (
fill("-3", "3")). - If any bound (or the step) has a leading zero, every value is zero-padded to the
longest bound's width — including
0and negatives (fill("-03", "03")→["-03", …, "000", …, "003"]). - A step of
0is treated as1; the step's sign is ignored.
To build a regex matching a numeric range (the npm package's toRegex option),
use the companion to-regex-range crate.
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
License
Licensed under either of Apache-2.0 or MIT at your option.