填充范围

填入数字或字母范围,可选通过递增或
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日查阅.