@bluelovers/fill-range

中文文档
7.0.2发布于 2022/09/22MITTypeScriptESM + CJS近 30 天下载 7.2万

填入数字或字母范围,可选通过递增或 step 要使用,或创建与正则兼容的区域 options.toRegex

中文使用文档
文档目录13 节
  1. 安装
  2. 使用量
  3. 实例
  4. 选项
  5. 选项。步骤
  6. 选项
  7. 选项。字符串
  8. 选项。to Regex
  9. 选项
  10. 关于
  11. 贡献者
  12. 作者
  13. 许可证

填充范围 Donate NPM version NPM monthly downloads NPM total downloads Linux Build Status

填入数字或字母范围,可选通过递增或 step 要使用,或创建与正则兼容的区域 options.toRegex

请考虑跟随这个项目的作者, 乔恩·斯林克特,并考虑主演该项目以显示你的:心:和支持.

安装

安装方式 无数字 :

$ npm install --save fill-range

使用量

扩展数字和字母,可选择使用 step 作为最后的论点. (数字可以被定义为 JavaScript 数字或字符串)。 。 。 .

const fill = require('fill-range');
// fill(from, to[, step, options]);

console.log(fill('1', '10')); //=> ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
console.log(fill('1', '10', { toRegex: true })); //=> [1-9]|10

参数

  • from数字 : {String}号码} 起始数字或字母
  • to数字 : {String}号码} 以
  • step数字 : {String {数量}{Object}{功能} 可选通过 a 步骤 用来使用.
  • options数字 : {对象{功能}: 见所有可用的 选项

实例

默认情况下,返回一系列值.

字母范围

console.log(fill('a', 'e')); //=> ['a', 'b', 'c', 'd', 'e']
console.log(fill('A', 'E')); //=> [ 'A', 'B', 'C', 'D', 'E' ]

数值范围

数字可以被定义为实际数字或字符串.

console.log(fill(1, 5));     //=> [ 1, 2, 3, 4, 5 ]
console.log(fill('1', '5')); //=> [ 1, 2, 3, 4, 5 ]

负范围

数字可以被定义为实际数字或字符串.

console.log(fill('-5', '-1')); //=> [ '-5', '-4', '-3', '-2', '-1' ]
console.log(fill('-5', '5')); //=> [ '-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5' ]

步骤(增减)

// numerical ranges with increments
console.log(fill('0', '25', 4)); //=> [ '0', '4', '8', '12', '16', '20', '24' ]
console.log(fill('0', '25', 5)); //=> [ '0', '5', '10', '15', '20', '25' ]
console.log(fill('0', '25', 6)); //=> [ '0', '6', '12', '18', '24' ]

// alphabetical ranges with increments
console.log(fill('a', 'z', 4)); //=> [ 'a', 'e', 'i', 'm', 'q', 'u', 'y' ]
console.log(fill('a', 'z', 5)); //=> [ 'a', 'f', 'k', 'p', 'u', 'z' ]
console.log(fill('a', 'z', 6)); //=> [ 'a', 'g', 'm', 's', 'y' ]

选项

选项。步骤

类型数字 : number (格式为字符串或数字)

默认数字 : undefined

说明: 用于范围的增量。 可以用字母或数字.

示例

// numbers
console.log(fill('1', '10', 2)); //=> [ '1', '3', '5', '7', '9' ]
console.log(fill('1', '10', 3)); //=> [ '1', '4', '7', '10' ]
console.log(fill('1', '10', 4)); //=> [ '1', '5', '9' ]

// letters
console.log(fill('a', 'z', 5)); //=> [ 'a', 'f', 'k', 'p', 'u', 'z' ]
console.log(fill('a', 'z', 7)); //=> [ 'a', 'h', 'o', 'v' ]
console.log(fill('a', 'z', 9)); //=> [ 'a', 'j', 's' ]

选项

类型数字 : boolean

默认数字 : false

说明:默认情况下, null 当一个无效区域被通过时返回。 启用此选项以丢出 RangeError 无效区域.

示例

以下全部无效 :

fill('1.1', '2');   // decimals not supported in ranges
fill('a', '2');     // incompatible range values
fill(1, 10, 'foo'); // invalid "step" argument

选项。字符串

类型数字 : boolean

默认数字 : undefined

说明: 将所有返回的值投入字符串。 默认情况下,整数作为数字还原.

示例

console.log(fill(1, 5));                    //=> [ 1, 2, 3, 4, 5 ]
console.log(fill(1, 5, { stringify: true })); //=> [ '1', '2', '3', '4', '5' ]

选项。to Regex

类型数字 : boolean

默认数字 : undefined

说明: 创建一个regex相容源字符串,而不是将值扩展为数组.

示例

// alphabetical range
console.log(fill('a', 'e', { toRegex: true })); //=> '[a-e]'
// alphabetical with step
console.log(fill('a', 'z', 3, { toRegex: true })); //=> 'a|d|g|j|m|p|s|v|y'
// numerical range
console.log(fill('1', '100', { toRegex: true })); //=> '[1-9]|[1-9][0-9]|100'
// numerical range with zero padding
console.log(fill('000001', '100000', { toRegex: true }));
//=> '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'

选项

类型数字 : function

默认数字 : undefined

说明: 自定义返回数组中的每个值(或 字符串) (中文(简体) ). (您也可以将此函数作为最后一个参数传递给 fill()(中文(简体) )。 。 。 .

示例

// add zero padding
console.log(fill(1, 5, value => String(value).padStart(4, '0')));
//=> ['0001', '0002', '0003', '0004', '0005']

关于

捐款

拉出请求和星星总是受欢迎的. 对于错误和特性请求, 请创建一个问题。 。 。 .

运行测试

运行和审查单元测试是熟悉图书馆及其API的好办法。 您可以使用以下命令安装依赖性并运行测试:

$ npm install && npm test
大楼文件

(此工程的 readme.md 由 动词请不要直接编辑读取器。 读取器的任何改动必须在 动词 md 读取我的模板。 )

要生成读取, 请运行以下命令 :

$ npm install -g verbose/verb#dev verb-generate-readme && verb

贡献者

| 提交 | 贡献者 |
| -- -- -- -- -- -- --
116个 扬施林克特 |
页:1 保罗米尔 |
|2| 现实 |
|2| 蓝爱人 |
| 1 | 埃多里瓦伊语name |
| 1 | wtgtybhertgeghgtwttg (英语) |

作者

乔恩·斯林克特

请考虑支持我在帕特里昂,或 启动您的 Patreon 页面来啊!

许可证

版权所有: 2019, 乔恩·斯林克特。 。 。 . 释放 MIT 许可证。 。 。 .


此文件由 动词基因读取器,v0.8.0,于2019年4月8日查阅.

版本与发布记录

@bluelovers/fill-range 共发布 2 个版本,首次发布于 2022/09/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
7.0.2latest2022/09/224 年前
7.0.12022/09/224 年前

关于 @bluelovers/fill-range 的常见问题

@bluelovers/fill-range 是什么?

填入数字或字母范围,可选通过递增或 step 要使用,或创建与正则兼容的区域 options.toRegex

如何安装 @bluelovers/fill-range?

在项目目录运行 npm install @bluelovers/fill-range,或使用 pnpm add / yarn add / bun add。

@bluelovers/fill-range 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bluelovers/fill-range 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bluelovers/fill-range 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=8。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bluelovers/fill-range 可以商用吗?

@bluelovers/fill-range 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bluelovers/fill-range 的下载量有多少?

根据 npm 官方下载统计,@bluelovers/fill-range 在 2026/10/09 – 2026/11/07 这 30 天内被下载 71,897 次,日均约 2,397 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bluelovers/fill-range 还在维护吗?

最新版本 7.0.2 发布于 2022/09/22(4 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/09/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。