Fill in a range of numbers or letters, positive or negative, optionally passing an increment or multiplier to use.
Installations
npm install fill-range
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=8
Node Version
20.12.1
NPM Version
10.7.0
Score
99.7
Supply Chain
100
Quality
81.6
Maintenance
100
Vulnerability
100
License
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
jonschlinkert
Download Statistics
Total Downloads
14,863,707,947
Last Day
12,778,654
Last Week
58,909,532
Last Month
269,344,388
Last Year
3,449,612,772
GitHub Statistics
56 Stars
135 Commits
15 Forks
6 Watching
3 Branches
8 Contributors
Bundle Size
5.67 kB
Minified
2.42 kB
Minified + Gzipped
Package Meta Information
Latest Version
7.1.1
Package Id
fill-range@7.1.1
Unpacked Size
16.35 kB
Size
5.59 kB
File Count
4
NPM Version
10.7.0
Node Version
20.12.1
Publised On
21 May 2024
Total Downloads
Cumulative downloads
Total Downloads
14,863,707,947
Last day
-4.7%
12,778,654
Compared to previous day
Last week
-15.7%
58,909,532
Compared to previous week
Last month
4.7%
269,344,388
Compared to previous month
Last year
5.3%
3,449,612,772
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
3
fill-range
![Linux Build Status](https://img.shields.io/travis/jonschlinkert/fill-range.svg?style=flat&label=Travis)
Fill in a range of numbers or letters, optionally passing an increment or
step
to use, or create a regex-compatible range withoptions.toRegex
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install
Install with npm:
1$ npm install --save fill-range
Usage
Expands numbers and letters, optionally using a step
as the last argument. (Numbers may be defined as JavaScript numbers or strings).
1const fill = require('fill-range'); 2// fill(from, to[, step, options]); 3 4console.log(fill('1', '10')); //=> ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] 5console.log(fill('1', '10', { toRegex: true })); //=> [1-9]|10
Params
from
: {String|Number} the number or letter to start withto
: {String|Number} the number or letter to end withstep
: {String|Number|Object|Function} Optionally pass a step to use.options
: {Object|Function}: See all available options
Examples
By default, an array of values is returned.
Alphabetical ranges
1console.log(fill('a', 'e')); //=> ['a', 'b', 'c', 'd', 'e'] 2console.log(fill('A', 'E')); //=> [ 'A', 'B', 'C', 'D', 'E' ]
Numerical ranges
Numbers can be defined as actual numbers or strings.
1console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ] 2console.log(fill('1', '5')); //=> [ 1, 2, 3, 4, 5 ]
Negative ranges
Numbers can be defined as actual numbers or strings.
1console.log(fill('-5', '-1')); //=> [ '-5', '-4', '-3', '-2', '-1' ] 2console.log(fill('-5', '5')); //=> [ '-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5' ]
Steps (increments)
1// numerical ranges with increments 2console.log(fill('0', '25', 4)); //=> [ '0', '4', '8', '12', '16', '20', '24' ] 3console.log(fill('0', '25', 5)); //=> [ '0', '5', '10', '15', '20', '25' ] 4console.log(fill('0', '25', 6)); //=> [ '0', '6', '12', '18', '24' ] 5 6// alphabetical ranges with increments 7console.log(fill('a', 'z', 4)); //=> [ 'a', 'e', 'i', 'm', 'q', 'u', 'y' ] 8console.log(fill('a', 'z', 5)); //=> [ 'a', 'f', 'k', 'p', 'u', 'z' ] 9console.log(fill('a', 'z', 6)); //=> [ 'a', 'g', 'm', 's', 'y' ]
Options
options.step
Type: number
(formatted as a string or number)
Default: undefined
Description: The increment to use for the range. Can be used with letters or numbers.
Example(s)
1// numbers 2console.log(fill('1', '10', 2)); //=> [ '1', '3', '5', '7', '9' ] 3console.log(fill('1', '10', 3)); //=> [ '1', '4', '7', '10' ] 4console.log(fill('1', '10', 4)); //=> [ '1', '5', '9' ] 5 6// letters 7console.log(fill('a', 'z', 5)); //=> [ 'a', 'f', 'k', 'p', 'u', 'z' ] 8console.log(fill('a', 'z', 7)); //=> [ 'a', 'h', 'o', 'v' ] 9console.log(fill('a', 'z', 9)); //=> [ 'a', 'j', 's' ]
options.strictRanges
Type: boolean
Default: false
Description: By default, null
is returned when an invalid range is passed. Enable this option to throw a RangeError
on invalid ranges.
Example(s)
The following are all invalid:
1fill('1.1', '2'); // decimals not supported in ranges 2fill('a', '2'); // incompatible range values 3fill(1, 10, 'foo'); // invalid "step" argument
options.stringify
Type: boolean
Default: undefined
Description: Cast all returned values to strings. By default, integers are returned as numbers.
Example(s)
1console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ]
2console.log(fill(1, 5, { stringify: true })); //=> [ '1', '2', '3', '4', '5' ]
options.toRegex
Type: boolean
Default: undefined
Description: Create a regex-compatible source string, instead of expanding values to an array.
Example(s)
1// alphabetical range 2console.log(fill('a', 'e', { toRegex: true })); //=> '[a-e]' 3// alphabetical with step 4console.log(fill('a', 'z', 3, { toRegex: true })); //=> 'a|d|g|j|m|p|s|v|y' 5// numerical range 6console.log(fill('1', '100', { toRegex: true })); //=> '[1-9]|[1-9][0-9]|100' 7// numerical range with zero padding 8console.log(fill('000001', '100000', { toRegex: true })); 9//=> '0{5}[1-9]|0{4}[1-9][0-9]|0{3}[1-9][0-9]{2}|0{2}[1-9][0-9]{3}|0[1-9][0-9]{4}|100000'
options.transform
Type: function
Default: undefined
Description: Customize each value in the returned array (or string). (you can also pass this function as the last argument to fill()
).
Example(s)
1// add zero padding 2console.log(fill(1, 5, value => String(value).padStart(4, '0'))); 3//=> ['0001', '0002', '0003', '0004', '0005']
About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
1$ npm install && npm test
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
1$ npm install -g verbose/verb#dev verb-generate-readme && verb
Contributors
Commits | Contributor |
---|---|
116 | jonschlinkert |
4 | paulmillr |
2 | realityking |
2 | bluelovers |
1 | edorivai |
1 | wtgtybhertgeghgtwtg |
Author
Jon Schlinkert
Please consider supporting me on Patreon, or start your own Patreon page!
![](https://c5.patreon.com/external/logo/become_a_patron_button@2x.png)
License
Copyright © 2019, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on April 08, 2019.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
SAST tool detected but not run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Warn: 0 commits out of 4 are checked with a SAST tool
Reason
Found 4/30 approved changesets -- score normalized to 1
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/jonschlinkert/fill-range/codeql.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/jonschlinkert/fill-range/codeql.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/jonschlinkert/fill-range/codeql.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/jonschlinkert/fill-range/codeql.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/jonschlinkert/fill-range/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/jonschlinkert/fill-range/test.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/jonschlinkert/fill-range/test.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:32
- Info: 0 out of 6 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/codeql.yml:1
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
4
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to fill-range
@types/fill-range
TypeScript definitions for fill-range
braces
Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support for the Bash 4.3 braces specification, without sacrificing speed.
@clevercanyon/fill-range.fork
Fill in a range of numbers or letters.
@bluelovers/fill-range
Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`