fill-range 0.1.0

Fill in a range of numbers or letters: fill("1","5") -> [1,2,3,4,5], fill("a","e") -> [a,b,c,d,e]. A faithful port of the fill-range npm package. Zero dependencies, no_std.
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented3 out of 3 items with examples
  • Size
  • Source code size: 25.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 125.2 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • trananhtung/fill-range
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • trananhtung

fill-range

Crates.io Documentation CI License

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 fill_range::{fill, fill_step};

assert_eq!(fill("1", "5"), ["1", "2", "3", "4", "5"]);
assert_eq!(fill("a", "e"), ["a", "b", "c", "d", "e"]);
assert_eq!(fill("01", "05"), ["01", "02", "03", "04", "05"]); // auto-padded
assert_eq!(fill("5", "1"), ["5", "4", "3", "2", "1"]);        // descending
assert_eq!(fill_step("0", "10", 2), ["0", "2", "4", "6", "8", "10"]);

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.

[dependencies]
fill-range = "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 0 and negatives (fill("-03", "03") → ["-03", …, "000", …, "003"]).
  • A step of 0 is treated as 1; 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.

License

Licensed under either of Apache-2.0 or MIT at your option.