fill-range-master/0000755000175000017500000000000013472205230013743 5ustar xavierxavierfill-range-master/.verb.md0000644000175000017500000001036313472205230015304 0ustar xavierxavier## Usage Expands numbers and letters, optionally using a `step` as the last argument. _(Numbers may be defined as JavaScript numbers or strings)_. ```js const fill = require('{%= name %}'); // 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 ``` **Params** - `from`: **{String|Number}** the number or letter to start with - `to`: **{String|Number}** the number or letter to end with - `step`: **{String|Number|Object|Function}** Optionally pass a [step](#optionsstep) to use. - `options`: **{Object|Function}**: See all available [options](#options) ## Examples By default, an array of values is returned. **Alphabetical ranges** ```js console.log(fill('a', 'e')); //=> ['a', 'b', 'c', 'd', 'e'] console.log(fill('A', 'E')); //=> [ 'A', 'B', 'C', 'D', 'E' ] ``` **Numerical ranges** Numbers can be defined as actual numbers or strings. ```js console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ] console.log(fill('1', '5')); //=> [ 1, 2, 3, 4, 5 ] ``` **Negative ranges** Numbers can be defined as actual numbers or strings. ```js 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' ] ``` **Steps (increments)** ```js // 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' ] ``` ## 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)** ```js // 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' ] ``` ### 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: ```js fill('1.1', '2'); // decimals not supported in ranges fill('a', '2'); // incompatible range values fill(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)** ```js console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ] console.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)** ```js // 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' ``` ### options.transform **Type**: `function` **Default**: `undefined` **Description**: Customize each value in the returned array (or [string](#optionstoRegex)). _(you can also pass this function as the last argument to `fill()`)_. **Example(s)** ```js // add zero padding console.log(fill(1, 5, value => String(value).padStart(4, '0'))); //=> ['0001', '0002', '0003', '0004', '0005'] ``` fill-range-master/.eslintrc.json0000644000175000017500000000732513472205230016546 0ustar xavierxavier{ "extends": [ "eslint:recommended" ], "env": { "browser": false, "es6": true, "node": true, "mocha": true }, "parserOptions":{ "ecmaVersion": 9, "sourceType": "module", "ecmaFeatures": { "modules": true, "experimentalObjectRestSpread": true } }, "globals": { "document": false, "navigator": false, "window": false }, "rules": { "accessor-pairs": 2, "arrow-spacing": [2, { "before": true, "after": true }], "block-spacing": [2, "always"], "brace-style": [2, "1tbs", { "allowSingleLine": true }], "comma-dangle": [2, "never"], "comma-spacing": [2, { "before": false, "after": true }], "comma-style": [2, "last"], "constructor-super": 2, "curly": [2, "multi-line"], "dot-location": [2, "property"], "eol-last": 2, "eqeqeq": [2, "allow-null"], "generator-star-spacing": [2, { "before": true, "after": true }], "handle-callback-err": [2, "^(err|error)$" ], "indent": [2, 2, { "SwitchCase": 1 }], "key-spacing": [2, { "beforeColon": false, "afterColon": true }], "keyword-spacing": [2, { "before": true, "after": true }], "new-cap": [2, { "newIsCap": true, "capIsNew": false }], "new-parens": 2, "no-array-constructor": 2, "no-caller": 2, "no-class-assign": 2, "no-cond-assign": 2, "no-const-assign": 2, "no-control-regex": 2, "no-debugger": 2, "no-delete-var": 2, "no-dupe-args": 2, "no-dupe-class-members": 2, "no-dupe-keys": 2, "no-duplicate-case": 2, "no-empty-character-class": 2, "no-eval": 2, "no-ex-assign": 2, "no-extend-native": 2, "no-extra-bind": 2, "no-extra-boolean-cast": 2, "no-extra-parens": [2, "functions"], "no-fallthrough": 2, "no-floating-decimal": 2, "no-func-assign": 2, "no-implied-eval": 2, "no-inner-declarations": [2, "functions"], "no-invalid-regexp": 2, "no-irregular-whitespace": 2, "no-iterator": 2, "no-label-var": 2, "no-labels": 2, "no-lone-blocks": 2, "no-mixed-spaces-and-tabs": 2, "no-multi-spaces": 2, "no-multi-str": 2, "no-multiple-empty-lines": [2, { "max": 1 }], "no-native-reassign": 0, "no-negated-in-lhs": 2, "no-new": 2, "no-new-func": 2, "no-new-object": 2, "no-new-require": 2, "no-new-wrappers": 2, "no-obj-calls": 2, "no-octal": 2, "no-octal-escape": 2, "no-proto": 0, "no-redeclare": 2, "no-regex-spaces": 2, "no-return-assign": 2, "no-self-compare": 2, "no-sequences": 2, "no-shadow-restricted-names": 2, "no-spaced-func": 2, "no-sparse-arrays": 2, "no-this-before-super": 2, "no-throw-literal": 2, "no-trailing-spaces": 0, "no-undef": 2, "no-undef-init": 2, "no-unexpected-multiline": 2, "no-unneeded-ternary": [2, { "defaultAssignment": false }], "no-unreachable": 2, "no-unused-vars": [2, { "vars": "all", "args": "none" }], "no-useless-call": 0, "no-with": 2, "one-var": [0, { "initialized": "never" }], "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], "padded-blocks": [0, "never"], "quotes": [2, "single", "avoid-escape"], "radix": 2, "semi": [2, "always"], "semi-spacing": [2, { "before": false, "after": true }], "space-before-blocks": [2, "always"], "space-before-function-paren": [2, "never"], "space-in-parens": [2, "never"], "space-infix-ops": 2, "space-unary-ops": [2, { "words": true, "nonwords": false }], "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], "use-isnan": 2, "valid-typeof": 2, "wrap-iife": [2, "any"], "yoda": [2, "never"] } } fill-range-master/LICENSE0000644000175000017500000000210313472205230014744 0ustar xavierxavierThe MIT License (MIT) Copyright (c) 2014-present, Jon Schlinkert. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. fill-range-master/test/0000755000175000017500000000000013472205230014722 5ustar xavierxavierfill-range-master/test/custom-expand.js0000644000175000017500000000171013472205230020046 0ustar xavierxavier'use strict'; require('mocha'); const assert = require('assert'); const exact = require('./support/exact'); const fill = require('..'); describe('custom function for expansions:', () => { it('should expose the current value as the first param.', () => { exact(fill(1, 5, value => value), [1, 2, 3, 4, 5]); }); it('should expose the character code for non-integers', () => { let arr = fill('a', 'e', code => String.fromCharCode(code)); exact(arr, ['a', 'b', 'c', 'd', 'e']); }); it('should expose padding `maxLength` on options', () => { let arr = fill('01', '05', value => { return String(value).padStart(String(value).length + 3, '0'); }); exact(arr, ['0001', '0002', '0003', '0004', '0005']); }); it('should expose the index as the fifth param.', () => { let arr = fill('a', 'e', (code, index) => { return String.fromCharCode(code) + index; }); exact(arr, ['a0', 'b1', 'c2', 'd3', 'e4']); }); }); fill-range-master/test/padding.js0000644000175000017500000000745613472205230016702 0ustar xavierxavier'use strict'; require('mocha'); const util = require('util'); const assert = require('assert').strict; const fill = require('..'); describe('padding: numbers', () => { it('should pad incremented numbers:', () => { assert.deepEqual(fill('01', '03'), ['01', '02', '03']); assert.deepEqual(fill('01', '3'), ['01', '02', '03']); assert.deepEqual(fill('1', '03'), ['01', '02', '03']); assert.deepEqual(fill('0001', '0003'), ['0001', '0002', '0003']); assert.deepEqual(fill('-10', '00'), ['-10', '-09', '-08', '-07', '-06', '-05', '-04', '-03', '-02', '-01', '000']); assert.deepEqual(fill('05', '010'), ['005','006','007','008','009','010']); assert.deepEqual(fill('05', '100'), ['005','006','007','008','009','010','011','012','013','014','015','016','017','018','019','020','021','022','023','024','025','026','027','028','029','030','031','032','033','034','035','036','037','038','039','040','041','042','043','044','045','046','047','048','049','050','051','052','053','054','055','056','057','058','059','060','061','062','063','064','065','066','067','068','069','070','071','072','073','074','075','076','077','078','079','080','081','082','083','084','085','086','087','088','089','090','091','092','093','094','095','096','097','098','099','100']); }); it('should pad decremented numbers:', () => { assert.deepEqual(fill('03', '01'), ['03', '02', '01']); assert.deepEqual(fill('3', '01'), ['03', '02', '01']); assert.deepEqual(fill('003', '1'), ['003', '002', '001']); assert.deepEqual(fill('003', '001'), ['003', '002', '001']); assert.deepEqual(fill('3', '001'), ['003', '002', '001']); assert.deepEqual(fill('03', '001'), ['003', '002', '001']); }); it('should pad decremented numbers with regex source string', () => { assert.deepEqual(fill('03', '01', { toRegex: true }), '0?[1-3]'); assert.deepEqual(fill('3', '01', { toRegex: true }), '0?[1-3]'); assert.deepEqual(fill('003', '1', { toRegex: true }), '0{0,2}[1-3]'); assert.deepEqual(fill('003', '001', { toRegex: true }), '0{0,2}[1-3]'); assert.deepEqual(fill('3', '001', { toRegex: true }), '0{0,2}[1-3]'); assert.deepEqual(fill('03', '001', { toRegex: true }), '0{0,2}[1-3]'); assert.deepEqual(fill('001', '020', { toRegex: true }), '0{0,2}[1-9]|0?1[0-9]|0?20'); }); it('should pad with strict zeros', () => { assert.deepEqual(fill('03', '01', { toRegex: true, strictZeros: true }), '0[1-3]'); assert.deepEqual(fill('3', '01', { toRegex: true, strictZeros: true }), '0[1-3]'); assert.deepEqual(fill('003', '1', { toRegex: true, strictZeros: true }), '00[1-3]'); assert.deepEqual(fill('003', '001', { toRegex: true, strictZeros: true }), '00[1-3]'); assert.deepEqual(fill('3', '001', { toRegex: true, strictZeros: true }), '00[1-3]'); assert.deepEqual(fill('03', '001', { toRegex: true, strictZeros: true }), '00[1-3]'); assert.deepEqual(fill('001', '020', { toRegex: true, strictZeros: true }), '00[1-9]|01[0-9]|020'); }); it('should pad stepped numbers', () => { assert.deepEqual(fill('1', '05', '3'), ['01','04']); assert.deepEqual(fill('1', '5', '03'), ['01','04']); assert.deepEqual(fill('1', '5', '0003'), ['0001','0004']); assert.deepEqual(fill('1', '005', '3'), ['001','004']); assert.deepEqual(fill('00', '1000', '200'), ['0000','0200', '0400', '0600', '0800', '1000']); assert.deepEqual(fill('0', '01000', '200'), ['00000','00200', '00400', '00600', '00800', '01000']); assert.deepEqual(fill('001', '5', '3'), ['001','004']); assert.deepEqual(fill('02', '10', 2), ['02', '04', '06', '08', '10']); assert.deepEqual(fill('002', '10', 2), ['002', '004', '006', '008', '010']); assert.deepEqual(fill('002', '010', 2), ['002', '004', '006', '008', '010']); assert.deepEqual(fill('-04', 4, 2), ['-04', '-02', '000', '002', '004']); }); }); fill-range-master/test/ranges.js0000644000175000017500000001022213472205230016534 0ustar xavierxavier'use strict'; require('mocha'); const assert = require('assert'); const exact = require('./support/exact'); const fill = require('..'); describe('ranges', () => { describe('alphabetical', () => { it('should increment alphabetical ranges', () => { exact(fill('a'), ['a']); exact(fill('a', 'a'), ['a']); exact(fill('a', 'b'), ['a', 'b']); exact(fill('a', 'e'), ['a', 'b', 'c', 'd', 'e']); exact(fill('A', 'E'), ['A', 'B', 'C', 'D', 'E']); }); it('should decrement alphabetical ranges', () => { exact(fill('E', 'A'), ['E', 'D', 'C', 'B', 'A']); exact(fill('a', 'C'), ['a','`','_','^',']',"\\",'[','Z','Y','X','W','V','U','T','S','R','Q','P','O','N','M','L','K','J','I','H','G','F','E','D','C']); exact(fill('z', 'm'), ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm']); }); }); describe('alphanumeric', () => { it('should increment alphanumeric ranges', () => { exact(fill('9', 'B'), ['9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B']); exact(fill('A', '10'), ['A', '@', '?', '>', '=', '<', ';', ':', '9', '8', '7', '6', '5', '4', '3', '2', '1']); exact(fill('a', '10'), ['a', '`', '_', '^', ']', '\\', '[', 'Z', 'Y', 'X', 'W', 'V', 'U', 'T', 'S', 'R', 'Q', 'P', 'O', 'N', 'M', 'L', 'K', 'J', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A', '@', '?', '>', '=', '<', ';', ':', '9', '8', '7', '6', '5', '4', '3', '2', '1']); }); it('should step alphanumeric ranges', () => { exact(fill('9', 'B', 3), [ '9', '<', '?', 'B' ]); }); it('should decrement alphanumeric ranges', () => { exact(fill('C', '9'), ['C', 'B', 'A', '@', '?', '>', '=', '<', ';', ':', '9']); }); }); describe('ranges: letters', () => { it('should increment alphabetical ranges', () => { exact(fill('a'), ['a']); exact(fill('a', 'a'), ['a']); exact(fill('a', 'b'), ['a', 'b']); exact(fill('a', 'e'), ['a', 'b', 'c', 'd', 'e']); exact(fill('A', 'E'), ['A', 'B', 'C', 'D', 'E']); }); it('should decrement alphabetical ranges', () => { exact(fill('E', 'A'), ['E', 'D', 'C', 'B', 'A']); exact(fill('a', 'C'), ['a','`','_','^',']',"\\",'[','Z','Y','X','W','V','U','T','S','R','Q','P','O','N','M','L','K','J','I','H','G','F','E','D','C']); exact(fill('z', 'm'), ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm']); }); }); describe('numbers', () => { it('should increment numerical *string* ranges', () => { exact(fill('1'), ['1']); exact(fill('1', '1'), ['1']); exact(fill('1', '2'), ['1', '2']); exact(fill('1', '10'), ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']); exact(fill('1', '3'), ['1', '2', '3']); exact(fill('5', '8'), ['5', '6', '7', '8']); exact(fill('1', '9'), ['1', '2', '3', '4', '5', '6', '7', '8', '9']); }); it('should increment numerical *number* ranges', () => { exact(fill(1, 3), [1, 2, 3]); exact(fill(1, 9), [1, 2, 3, 4, 5, 6, 7, 8, 9]); exact(fill(5, 8), [5, 6, 7, 8]); }); it('should increment numerical ranges that are a combination of number and string', () => { exact(fill('1', 9), ['1', '2', '3', '4', '5', '6', '7', '8', '9']); exact(fill('2', 5), ['2', '3', '4', '5']); }); it('should decrement numerical *string* ranges', () => { exact(fill('0', '-5'), ['0', '-1', '-2', '-3', '-4', '-5']); exact(fill('-1', '-5'), ['-1', '-2', '-3', '-4', '-5']); }); it('should decrement numerical *number* ranges', () => { exact(fill(-10, -1), [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1]); exact(fill(0, -5), [0, -1, -2, -3, -4, -5]); }); it('should handle *string* ranges ranges that are positive and negative:', () => { exact(fill('9', '-4'), ['9', '8', '7', '6', '5', '4', '3', '2', '1', '0', '-1', '-2', '-3', '-4']); exact(fill('-5', '5'), ['-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5']); }); it('should handle *number* ranges ranges that are positive and negative:', () => { exact(fill(9, -4), [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4]); exact(fill(-5, 5), [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]); }); }); }); fill-range-master/test/invalid.js0000644000175000017500000000153113472205230016706 0ustar xavierxavier'use strict'; require('mocha'); const assert = require('assert'); const fill = require('..'); describe('invalid ranges', () => { it('should return an empty array when options.strict is not true', () => { assert.deepEqual(fill('1', '0f'), []); assert.deepEqual(fill('1', '10', 'ff'), []); assert.deepEqual(fill('1', '10.f'), []); assert.deepEqual(fill('1', '10f'), []); assert.deepEqual(fill('1', '20', '2f'), []); assert.deepEqual(fill('1', '20', 'f2'), []); assert.deepEqual(fill('1', '2f'), []); assert.deepEqual(fill('1', '2f', '2'), []); assert.deepEqual(fill('1', 'f2'), []); assert.deepEqual(fill('1', 'ff'), []); assert.deepEqual(fill('1', 'ff', '2'), []); assert.deepEqual(fill('1.1', '2.1'), []); assert.deepEqual(fill('1.2', '2'), []); assert.deepEqual(fill('1.20', '2'), []); }); }); fill-range-master/test/verify-matches.js0000644000175000017500000000523513472205230020213 0ustar xavierxavier/*! * fill-range * * Copyright (c) 2014-2017, Jon Schlinkert. * Released under the MIT License. */ 'use strict'; require('mocha'); const assert = require('assert'); const expand = require('./support/expand'); const exact = require('./support/exact'); const fill = require('..'); let count = 0; const toRegex = (...args) => new RegExp(`^(${fill(...args)})$`); function matcher(...args) { let regex = toRegex(...args); return num => { return regex.test(String(num)); }; } function verifyRange(min, max, from, to) { let fn = matcher(min, max, { toRegex: true }); let range = expand(from, to); let len = range.length, i = -1; while (++i < len) { let num = range[i]; if (min <= num && num <= max) { assert(fn(num)); } else { assert(!fn(num)); } count++; } } describe('validate ranges', function() { after(function() { let num = (+(+(count).toFixed(2))).toLocaleString(); console.log(); console.log(' ', num, 'patterns tested'); }); it('should support equal numbers:', function() { verifyRange(1, 1, 0, 100); verifyRange(65443, 65443, 65000, 66000); verifyRange(192, 1000, 0, 1000); }); it('should support large numbers:', function() { verifyRange(100019999300000, 100020000300000, 100019999999999, 100020000100000); }); it('should support repeated digits:', function() { verifyRange(10331, 20381, 0, 99999); }); it('should support repeated zeros:', function() { verifyRange(10031, 20081, 0, 59999); verifyRange(10000, 20000, 0, 59999); }); it('should support zero one:', function() { verifyRange(10301, 20101, 0, 99999); }); it('should support repetead ones:', function() { verifyRange(102, 111, 0, 1000); }); it('should support small diffs:', function() { verifyRange(102, 110, 0, 1000); verifyRange(102, 130, 0, 1000); }); it('should support random ranges:', function() { verifyRange(4173, 7981, 0, 99999); }); it('should support one digit numbers:', function() { verifyRange(3, 7, 0, 99); }); it('should support one digit at bounds:', function() { verifyRange(1, 9, 0, 1000); }); it('should support power of ten:', function() { verifyRange(1000, 8632, 0, 99999); }); it('should work with numbers of varying lengths:', function() { verifyRange(1030, 20101, 0, 99999); verifyRange(13, 8632, 0, 10000); }); it('should support small ranges:', function() { verifyRange(9, 11, 0, 100); verifyRange(19, 21, 0, 100); }); it('should support big ranges:', function() { verifyRange(90, 98009, 0, 98999); verifyRange(999, 10000, 1, 20000); }); }); fill-range-master/test/support/0000755000175000017500000000000013472205230016436 5ustar xavierxavierfill-range-master/test/support/exact.js0000644000175000017500000000041413472205230020077 0ustar xavierxavier'use strict'; const util = require('util'); const assert = require('assert'); module.exports = (actual, expected) => { assert(Array.isArray(actual)); let a = util.inspect(actual); let b = util.inspect(expected); assert.strictEqual(a, b, `${a} !== ${b}`); }; fill-range-master/test/support/expand.js0000644000175000017500000000032213472205230020250 0ustar xavierxavier'use strict'; module.exports = (start, stop, step = 1) => { let arr = new Array((stop - start) / step); let num = 0; for (var i = start; i <= stop; i += step) { arr[num++] = i; } return arr; }; fill-range-master/test/options.js0000644000175000017500000001036713472205230016762 0ustar xavierxavier'use strict'; require('mocha'); const util = require('util'); const assert = require('assert'); const exact = require('./support/exact'); const fill = require('..'); describe('options', () => { describe('options.stringify', () => { it('should cast values to strings', () => { let opts = { stringify: true }; exact(fill('1', '10', '1', opts), ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']); exact(fill(2, 10, '2', opts), ['2', '4', '6', '8', '10']); exact(fill(2, 10, 1, opts), ['2', '3', '4', '5', '6', '7', '8', '9', '10']); exact(fill(2, 10, 3, opts), ['2', '5', '8']); }); }); describe('options.transform', () => { it('should cast values to strings', () => { let transform = value => String(value); exact(fill('1', '10', '1', { transform }), ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']); exact(fill(2, 10, '2', { transform }), ['2', '4', '6', '8', '10']); exact(fill(2, 10, 1, { transform }), ['2', '3', '4', '5', '6', '7', '8', '9', '10']); exact(fill(2, 10, 3, { transform }), ['2', '5', '8']); }); }); describe('options.toRegex', () => { let opts = { toRegex: true }; it('should create regex ranges for numbers in ascending order', () => { assert.equal(fill(2, 8, opts), '[2-8]'); assert.equal(fill(2, 10, opts), '[2-9]|10'); assert.equal(fill(2, 100, opts), '[2-9]|[1-9][0-9]|100'); }); it('should create regex ranges with positive and negative numbers', () => { assert.equal(fill(-10, 10, opts), '-[1-9]|-?10|[0-9]'); assert.equal(fill(-10, 10, 2, opts), '0|2|4|6|8|10|-(?:2|4|6|8|10)'); assert.equal(fill(-10, 0, 2, opts), '0|-(?:2|4|6|8|10)'); assert.equal(fill(-10, -2, 2, opts), '-(?:2|4|6|8|10)'); }); it('should create regex ranges for numbers in descending order', () => { assert.equal(fill(8, 2, opts), '[2-8]'); }); it('should create regex ranges when a step is given', () => { assert.equal(fill(8, 2, { toRegex: true, step: 2 }), '2|4|6|8'); assert.equal(fill(2, 8, { toRegex: true, step: 2 }), '2|4|6|8'); }); it('should support zero-padding', () => { assert.equal(fill('002', '008', opts), '0{0,2}[2-8]'); assert.equal(fill('02', '08', opts), '0?[2-8]'); assert.equal(fill('02', '10', opts), '0?[2-9]|10'); assert.equal(fill('002', '100', opts), '0{0,2}[2-9]|0?[1-9][0-9]|100'); }); it('should support negative zero-padding', () => { assert.equal(fill('-002', '-100', opts), '-0{0,3}[2-9]|-0{0,2}[1-9][0-9]|-0?100'); assert.equal(fill('-02', '-08', opts), '-0{0,2}[2-8]'); assert.equal(fill('-02', '-100', opts), '-0{0,3}[2-9]|-0{0,2}[1-9][0-9]|-0?100'); assert.equal(fill('-02', '100', opts), '-0{0,2}[12]|0{0,2}[0-9]|0?[1-9][0-9]|100'); }); it('should create regex ranges for alpha chars defined in ascending order', () => { assert.equal(fill('a', 'b', opts), '[a-b]'); assert.equal(fill('A', 'b', opts), '[A-b]'); assert.equal(fill('Z', 'a', opts), '[Z-a]'); }); it('should create regex ranges for alpha chars defined in descending order', () => { assert.equal(fill('z', 'A', opts), '[A-z]'); }); }); describe('options.wrap', () => { let opts = { toRegex: true, wrap: true }; it('should not wrap regex ranges with a single condition in parentheses', () => { assert.equal(fill(2, 8, opts), '[2-8]'); }); it('should wrap regex ranges in parentheses', () => { assert.equal(fill(2, 10, opts), '(?:[2-9]|10)'); assert.equal(fill(2, 100, opts), '(?:[2-9]|[1-9][0-9]|100)'); }); it('should wrap ranges with positive and negative numbers in parentheses', () => { assert.equal(fill(-10, -2, 2, opts), '(?:-(?:2|4|6|8|10))'); assert.equal(fill(-10, 0, 2, opts), '(?:0|-(?:2|4|6|8|10))'); assert.equal(fill(-10, 10, 2, opts), '(?:0|2|4|6|8|10|-(?:2|4|6|8|10))'); assert.equal(fill(-10, 10, opts), '(?:-[1-9]|-?10|[0-9])'); }); }); describe('options.capture', () => { it('should wrap the returned string in parans', () => { let opts = { toRegex: true, capture: true }; assert.equal(fill(-10, 10, 2, opts), '(0|2|4|6|8|10|-(2|4|6|8|10))'); assert.equal(fill(-10, 10, opts), '(-[1-9]|-?10|[0-9])'); }); }); }); fill-range-master/test/special.js0000644000175000017500000000173713472205230016710 0ustar xavierxavier'use strict'; require('mocha'); const assert = require('assert'); const exact = require('./support/exact'); const fill = require('..'); describe('special cases', () => { describe('negative zero', () => { it('should handle negative zero', () => { exact(fill('-5', '-0', '-1'), ['-5', '-4', '-3', '-2', '-1', '0']); exact(fill('1', '-0', 1), ['1', '0']); exact(fill('1', '-0', 0), ['1', '0']); exact(fill('1', '-0', '0'), ['1', '0']); exact(fill('1', '-0', '1'), ['1', '0']); exact(fill('-0', '-0', '1'), ['0']); exact(fill('-0', '0', '1'), ['0']); exact(fill('-0', '5', '1'), ['0', '1', '2', '3', '4', '5']); exact(fill(-0, 5), [0, 1, 2, 3, 4, 5]); exact(fill(5, -0, 5), [5, 0]); exact(fill(5, -0, 2), [5, 3, 1]); exact(fill(0, 5, 2), [0, 2, 4]); }); it('should adjust padding for negative numbers:', () => { exact(fill('-01', '5'), ['-01','000','001','002','003','004','005']); }); }); }); fill-range-master/test/errors.js0000644000175000017500000000220313472205230016571 0ustar xavierxavier'use strict'; require('mocha'); const assert = require('assert'); const fill = require('..'); describe('error handling', () => { it('should throw when range arguments are invalid and `strictRanges` is true', () => { assert.throws(() => { fill('0a', '0z', { strictRanges: true }); }, /Invalid range arguments: \[ '0a', '0z' \]/); assert.throws(() => { fill('', '*', 2, { strictRanges: true }); }, /Invalid range arguments: \[ '', '\*' \]/); }); it('should throw when args are incompatible', () => { assert.throws(() => { fill('a8', 10, { strictRanges: true }); }, /Invalid range arguments: \[ 'a8', 10 \]/); assert.throws(() => { fill(1, 'zz', { strictRanges: true }); }, /Invalid range arguments: \[ 1, 'zz' \]/); }); it('should throw when the step is bad.', () => { let opts = { strictRanges: true }; assert.throws(() => fill('1', '10', 'z', opts), /Expected step "z" to be a number/); assert.throws(() => fill('a', 'z', 'a', opts), /Expected step "a" to be a number/); assert.throws(() => fill('a', 'z', '0a', opts), /Expected step "0a" to be a number/); }); }); fill-range-master/test/steps.js0000644000175000017500000000725413472205230016426 0ustar xavierxavier'use strict'; require('mocha'); const assert = require('assert'); const exact = require('./support/exact'); const fill = require('..'); describe('steps', () => { describe('steps: numbers', () => { it('should increment ranges using the given step', () => { exact(fill('1', '10', '1'), ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']); exact(fill('1', '10', '2'), ['1', '3', '5', '7', '9']); exact(fill('0', '1000', '200'), ['0','200', '400', '600', '800', '1000']); exact(fill('1', '10', 2), ['1', '3', '5', '7', '9']); exact(fill('1', '20', '2'), ['1', '3', '5', '7', '9', '11', '13', '15', '17', '19']); exact(fill('1', '20', '20'), ['1']); exact(fill('10', '1', '2'), ['10', '8', '6', '4', '2']); exact(fill('10', '1', '-2'), ['10', '8', '6', '4', '2']); exact(fill('10', '1', '2'), ['10', '8', '6', '4', '2']); exact(fill(2, 10, '2'), [2, 4, 6, 8, 10]); exact(fill(2, 10, 1), [2, 3, 4, 5, 6, 7, 8, 9, 10]); exact(fill(2, 10, 2), [2, 4, 6, 8, 10]); exact(fill(2, 10, 3), [2, 5, 8]); exact(fill(0, 5, 2), [0, 2, 4]); exact(fill(5, 0, 2), [5, 3, 1]); exact(fill(1, 5, 2), [1, 3, 5]); exact(fill(2, '10', 2), ['2', '4', '6', '8', '10']); exact(fill(2, 10, '2'), [2, 4, 6, 8, 10]); exact(fill(2, '10', 1), ['2', '3', '4', '5', '6', '7', '8', '9', '10']); exact(fill(2, '10', '2'), ['2', '4', '6', '8', '10']); exact(fill('2', 10, '3'), ['2', '5', '8']); }); it('should fill in negative ranges using the given step (strings)', () => { exact(fill('0', '-10', '-2'), ['0', '-2', '-4', '-6', '-8', '-10']); exact(fill('-0', '-10', '-2'), ['0', '-2', '-4', '-6', '-8', '-10']); exact(fill('-1', '-10', '-2'), ['-1', '-3', '-5', '-7', '-9']); exact(fill('-1', '-10', '2'), ['-1', '-3', '-5', '-7', '-9']); exact(fill('1', '10', '2'), ['1', '3', '5', '7', '9']); exact(fill('1', '20', '2'), ['1', '3', '5', '7', '9', '11', '13', '15', '17', '19']); exact(fill('1', '20', '20'), ['1']); exact(fill('10', '1', '-2'), ['10', '8', '6', '4', '2']); exact(fill('-10', '0', '2'), ['-10', '-8', '-6', '-4', '-2', '0']); exact(fill('-10', '-0', '2'), ['-10', '-8', '-6', '-4', '-2', '0']); exact(fill('-0', '-10', '0'), ['0', '-1', '-2', '-3', '-4', '-5', '-6', '-7', '-8', '-9', '-10']); exact(fill('0', '-10', '-0'), ['0', '-1', '-2', '-3', '-4', '-5', '-6', '-7', '-8', '-9', '-10']); }); it('should fill in negative ranges using the given step (numbers)', () => { exact(fill(-10, 0, 2), [-10, -8, -6, -4, -2, 0]); exact(fill(-10, -2, 2), [-10, -8, -6, -4, -2]); exact(fill(-2, -10, 1), [-2, -3, -4, -5, -6, -7, -8, -9, -10]); exact(fill(0, -10, 2), [0, -2, -4, -6, -8, -10]); exact(fill(-2, -10, 2), [-2, -4, -6, -8, -10]); exact(fill(-2, -10, 3), [-2, -5, -8]); exact(fill(-9, 9, 3), [-9, -6, -3, 0, 3, 6, 9]); }); it('should fill in negative ranges when negative zero is passed', () => { exact(fill(-10, -0, 2), [-10, -8, -6, -4, -2, 0]); exact(fill(-0, -10, 2), [0, -2, -4, -6, -8, -10]); }); }); describe('steps: letters', () => { it('should use increments with alphabetical ranges', () => { exact(fill('z', 'a', -2), ['z', 'x', 'v', 't', 'r', 'p', 'n', 'l', 'j', 'h', 'f', 'd', 'b']); exact(fill('a', 'e', 2), ['a','c', 'e']); exact(fill('E', 'A', 2), ['E', 'C', 'A']); }); }); describe('options: step', () => { it('should use the step defined on the options:', () => { let options = { step: 2 }; exact(fill('a', 'e', options), ['a','c', 'e']); exact(fill('E', 'A', options), ['E', 'C', 'A']); }); }); }); fill-range-master/test/matching.js0000644000175000017500000000317113472205230017054 0ustar xavierxavier'use strict'; require('mocha'); const assert = require('assert'); const exact = require('./support/exact'); const fill = require('..'); const toRegex = (...args) => new RegExp(`^(${fill(...args)})$`); const isMatch = (...args) => { let input = args.pop(); let regex = toRegex(...args); return regex.test(input); }; describe('when options.toRegex is used', () => { it('should create regex ranges for numbers in ascending order', () => { assert(!isMatch(2, 8, { toRegex: true }, '10')); assert(isMatch(2, 8, { toRegex: true }, '3')); assert(isMatch(2, 10, { toRegex: true }, '10')); assert(isMatch(2, 100, { toRegex: true }, '10')); assert(!isMatch(2, 100, { toRegex: true }, '101')); }); it('should create regex ranges with positive and negative numbers', () => { assert(isMatch(-10, 10, { toRegex: true }, '10')); assert(isMatch(-10, 10, 2, { toRegex: true }, '10')); }); it('should create regex ranges for numbers in descending order', () => { assert(isMatch(8, 2, { toRegex: true }, '2')); assert(isMatch(8, 2, { toRegex: true }, '8')); assert(!isMatch(8, 2, { toRegex: true }, '10')); }); it('should create regex ranges when a step is given', () => { assert(!isMatch(8, 2, { toRegex: true, step: 2 }, '10')); assert(!isMatch(8, 2, { toRegex: true, step: 2 }, '3')); assert(!isMatch(8, 2, { toRegex: true, step: 2 }, '5')); assert(isMatch(8, 2, { toRegex: true, step: 2 }, '8')); assert(!isMatch(2, 8, { toRegex: true, step: 2 }, '10')); assert(!isMatch(2, 8, { toRegex: true, step: 2 }, '3')); assert(isMatch(2, 8, { toRegex: true, step: 2 }, '8')); }); }); fill-range-master/.npmrc0000644000175000017500000000002313472205230015056 0ustar xavierxavierpackage-lock=false fill-range-master/.editorconfig0000644000175000017500000000036313472205230016422 0ustar xavierxavier# http://editorconfig.org/ root = true [*] charset = utf-8 end_of_line = lf indent_size = 2 indent_style = space insert_final_newline = true trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false insert_final_newline = true fill-range-master/package.json0000644000175000017500000000266313472205230016240 0ustar xavierxavier{ "name": "fill-range", "description": "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`", "version": "7.0.1", "homepage": "https://github.com/jonschlinkert/fill-range", "author": "Jon Schlinkert (https://github.com/jonschlinkert)", "contributors": [ "Edo Rivai (edo.rivai.nl)", "Jon Schlinkert (http://twitter.com/jonschlinkert)", "Paul Miller (paulmillr.com)", "Rouven Weßling (www.rouvenwessling.de)", "(https://github.com/wtgtybhertgeghgtwtg)" ], "repository": "jonschlinkert/fill-range", "bugs": { "url": "https://github.com/jonschlinkert/fill-range/issues" }, "license": "MIT", "files": [ "index.js" ], "main": "index.js", "engines": { "node": ">=8" }, "scripts": { "test": "mocha" }, "dependencies": { "to-regex-range": "^5.0.1" }, "devDependencies": { "gulp-format-md": "^2.0.0", "mocha": "^6.1.1" }, "keywords": [ "alpha", "alphabetical", "array", "bash", "brace", "expand", "expansion", "fill", "glob", "match", "matches", "matching", "number", "numerical", "range", "ranges", "regex", "sh" ], "verb": { "toc": false, "layout": "default", "tasks": [ "readme" ], "plugins": [ "gulp-format-md" ], "lint": { "reflinks": true } } } fill-range-master/index.js0000644000175000017500000001425313472205230015415 0ustar xavierxavier/*! * fill-range * * Copyright (c) 2014-present, Jon Schlinkert. * Licensed under the MIT License. */ 'use strict'; const util = require('util'); const toRegexRange = require('to-regex-range'); const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val); const transform = toNumber => { return value => toNumber === true ? Number(value) : String(value); }; const isValidValue = value => { return typeof value === 'number' || (typeof value === 'string' && value !== ''); }; const isNumber = num => Number.isInteger(+num); const zeros = input => { let value = `${input}`; let index = -1; if (value[0] === '-') value = value.slice(1); if (value === '0') return false; while (value[++index] === '0'); return index > 0; }; const stringify = (start, end, options) => { if (typeof start === 'string' || typeof end === 'string') { return true; } return options.stringify === true; }; const pad = (input, maxLength, toNumber) => { if (maxLength > 0) { let dash = input[0] === '-' ? '-' : ''; if (dash) input = input.slice(1); input = (dash + input.padStart(dash ? maxLength - 1 : maxLength, '0')); } if (toNumber === false) { return String(input); } return input; }; const toMaxLen = (input, maxLength) => { let negative = input[0] === '-' ? '-' : ''; if (negative) { input = input.slice(1); maxLength--; } while (input.length < maxLength) input = '0' + input; return negative ? ('-' + input) : input; }; const toSequence = (parts, options) => { parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0); parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0); let prefix = options.capture ? '' : '?:'; let positives = ''; let negatives = ''; let result; if (parts.positives.length) { positives = parts.positives.join('|'); } if (parts.negatives.length) { negatives = `-(${prefix}${parts.negatives.join('|')})`; } if (positives && negatives) { result = `${positives}|${negatives}`; } else { result = positives || negatives; } if (options.wrap) { return `(${prefix}${result})`; } return result; }; const toRange = (a, b, isNumbers, options) => { if (isNumbers) { return toRegexRange(a, b, { wrap: false, ...options }); } let start = String.fromCharCode(a); if (a === b) return start; let stop = String.fromCharCode(b); return `[${start}-${stop}]`; }; const toRegex = (start, end, options) => { if (Array.isArray(start)) { let wrap = options.wrap === true; let prefix = options.capture ? '' : '?:'; return wrap ? `(${prefix}${start.join('|')})` : start.join('|'); } return toRegexRange(start, end, options); }; const rangeError = (...args) => { return new RangeError('Invalid range arguments: ' + util.inspect(...args)); }; const invalidRange = (start, end, options) => { if (options.strictRanges === true) throw rangeError([start, end]); return []; }; const invalidStep = (step, options) => { if (options.strictRanges === true) { throw new TypeError(`Expected step "${step}" to be a number`); } return []; }; const fillNumbers = (start, end, step = 1, options = {}) => { let a = Number(start); let b = Number(end); if (!Number.isInteger(a) || !Number.isInteger(b)) { if (options.strictRanges === true) throw rangeError([start, end]); return []; } // fix negative zero if (a === 0) a = 0; if (b === 0) b = 0; let descending = a > b; let startString = String(start); let endString = String(end); let stepString = String(step); step = Math.max(Math.abs(step), 1); let padded = zeros(startString) || zeros(endString) || zeros(stepString); let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0; let toNumber = padded === false && stringify(start, end, options) === false; let format = options.transform || transform(toNumber); if (options.toRegex && step === 1) { return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options); } let parts = { negatives: [], positives: [] }; let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num)); let range = []; let index = 0; while (descending ? a >= b : a <= b) { if (options.toRegex === true && step > 1) { push(a); } else { range.push(pad(format(a, index), maxLen, toNumber)); } a = descending ? a - step : a + step; index++; } if (options.toRegex === true) { return step > 1 ? toSequence(parts, options) : toRegex(range, null, { wrap: false, ...options }); } return range; }; const fillLetters = (start, end, step = 1, options = {}) => { if ((!isNumber(start) && start.length > 1) || (!isNumber(end) && end.length > 1)) { return invalidRange(start, end, options); } let format = options.transform || (val => String.fromCharCode(val)); let a = `${start}`.charCodeAt(0); let b = `${end}`.charCodeAt(0); let descending = a > b; let min = Math.min(a, b); let max = Math.max(a, b); if (options.toRegex && step === 1) { return toRange(min, max, false, options); } let range = []; let index = 0; while (descending ? a >= b : a <= b) { range.push(format(a, index)); a = descending ? a - step : a + step; index++; } if (options.toRegex === true) { return toRegex(range, null, { wrap: false, options }); } return range; }; const fill = (start, end, step, options = {}) => { if (end == null && isValidValue(start)) { return [start]; } if (!isValidValue(start) || !isValidValue(end)) { return invalidRange(start, end, options); } if (typeof step === 'function') { return fill(start, end, 1, { transform: step }); } if (isObject(step)) { return fill(start, end, 0, step); } let opts = { ...options }; if (opts.capture === true) opts.wrap = true; step = step || opts.step || 1; if (!isNumber(step)) { if (step != null && !isObject(step)) return invalidStep(step, opts); return fill(start, end, 1, step); } if (isNumber(start) && isNumber(end)) { return fillNumbers(start, end, step, opts); } return fillLetters(start, end, Math.max(Math.abs(step), 1), opts); }; module.exports = fill; fill-range-master/.gitignore0000644000175000017500000000045613472205230015740 0ustar xavierxavier# always ignore files *.DS_Store .idea .vscode *.sublime-* # test related, or directories generated by tests test/actual actual coverage .nyc* # npm node_modules npm-debug.log # yarn yarn.lock yarn-error.log # misc _gh_pages _draft _drafts bower_components vendor temp tmp TODO.md package-lock.jsonfill-range-master/bench/0000755000175000017500000000000013472205230015022 5ustar xavierxavierfill-range-master/bench/package.json0000644000175000017500000000055013472205230017310 0ustar xavierxavier{ "name": "picomatch-benchmarks", "version": "0.0.0", "private": true, "main": "index.js", "dependencies": { "ansi-colors": "^3.0.3", "benchmark": "^2.1.4", "fill-range": "^6.0.0", "minimist": "^1.2.0" }, "lintDeps": { "devDependencies": { "files": { "patterns": [ "*.js" ] } } } } fill-range-master/bench/index.js0000644000175000017500000000370213472205230016471 0ustar xavierxavier'use strict'; const { Suite } = require('benchmark'); const colors = require('ansi-colors'); const argv = require('minimist')(process.argv.slice(2)); const fill60 = require('fill-range'); const fill70 = require('..'); /** * Setup */ const cycle = (e, newline) => { process.stdout.write(`\u001b[G ${e.target}${newline ? `\n` : ''}`); }; const bench = (name, options) => { const config = { name, ...options }; const suite = new Suite(config); const add = suite.add.bind(suite); suite.on('error', console.error); if (argv.run && !new RegExp(argv.run).test(name)) { suite.add = () => suite; return suite; } console.log(colors.green(`● ${config.name}`)); suite.add = (key, fn, opts) => { if (typeof fn !== 'function') opts = fn; add(key, { onCycle: e => cycle(e), onComplete: e => cycle(e, true), fn, ...opts }); return suite; }; return suite; }; const skip = () => {}; skip.add = () => skip; skip.run = () => skip; bench.skip = name => { console.log(colors.cyan('● ' + colors.unstyle(name) + ' (skipped)')); return skip; }; bench('alpha') .add('fill 6.0', () => fill60('a', 'z')) .add('fill 7.0', () => fill70('a', 'z')) .run(); bench('alpha with step') .add('fill 6.0', () => fill60('a', 'z', 5)) .add('fill 7.0', () => fill70('a', 'z', 5)) .run(); bench('numbers') .add('fill 6.0', () => fill60(1, 50)) .add('fill 7.0', () => fill70(1, 50)) .run(); bench('numbers with step') .add('fill 6.0', () => fill60(1, 50, 5)) .add('fill 7.0', () => fill70(1, 50, 5)) .run(); bench('padded') .add('fill 6.0', () => fill60('0', '010')) .add('fill 7.0', () => fill70('0', '010')) .run(); bench('padded with step') .add('fill 6.0', () => fill60('0', '010', 2)) .add('fill 7.0', () => fill70('0', '010', 2)) .run(); bench('negative, padded with step') .add('fill 6.0', () => fill60('-0020', '0020', 2)) .add('fill 7.0', () => fill70('-0020', '0020', 2)) .run(); fill-range-master/README.md0000644000175000017500000001647613472205230015240 0ustar xavierxavier# fill-range [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/fill-range.svg?style=flat)](https://www.npmjs.com/package/fill-range) [![NPM monthly downloads](https://img.shields.io/npm/dm/fill-range.svg?style=flat)](https://npmjs.org/package/fill-range) [![NPM total downloads](https://img.shields.io/npm/dt/fill-range.svg?style=flat)](https://npmjs.org/package/fill-range) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/fill-range.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/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` Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. ## Install Install with [npm](https://www.npmjs.com/): ```sh $ 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)_. ```js 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 ``` **Params** * `from`: **{String|Number}** the number or letter to start with * `to`: **{String|Number}** the number or letter to end with * `step`: **{String|Number|Object|Function}** Optionally pass a [step](#optionsstep) to use. * `options`: **{Object|Function}**: See all available [options](#options) ## Examples By default, an array of values is returned. **Alphabetical ranges** ```js console.log(fill('a', 'e')); //=> ['a', 'b', 'c', 'd', 'e'] console.log(fill('A', 'E')); //=> [ 'A', 'B', 'C', 'D', 'E' ] ``` **Numerical ranges** Numbers can be defined as actual numbers or strings. ```js console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ] console.log(fill('1', '5')); //=> [ 1, 2, 3, 4, 5 ] ``` **Negative ranges** Numbers can be defined as actual numbers or strings. ```js 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' ] ``` **Steps (increments)** ```js // 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' ] ``` ## 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)** ```js // 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' ] ``` ### 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: ```js fill('1.1', '2'); // decimals not supported in ranges fill('a', '2'); // incompatible range values fill(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)** ```js console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ] console.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)** ```js // 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' ``` ### options.transform **Type**: `function` **Default**: `undefined` **Description**: Customize each value in the returned array (or [string](#optionstoRegex)). _(you can also pass this function as the last argument to `fill()`)_. **Example(s)** ```js // add zero padding console.log(fill(1, 5, value => String(value).padStart(4, '0'))); //=> ['0001', '0002', '0003', '0004', '0005'] ``` ## About
Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
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: ```sh $ npm install && npm test ```
Building docs _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ To generate the readme, run the following command: ```sh $ npm install -g verbose/verb#dev verb-generate-readme && verb ```
### Contributors | **Commits** | **Contributor** | | --- | --- | | 116 | [jonschlinkert](https://github.com/jonschlinkert) | | 4 | [paulmillr](https://github.com/paulmillr) | | 2 | [realityking](https://github.com/realityking) | | 2 | [bluelovers](https://github.com/bluelovers) | | 1 | [edorivai](https://github.com/edorivai) | | 1 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) | ### Author **Jon Schlinkert** * [GitHub Profile](https://github.com/jonschlinkert) * [Twitter Profile](https://twitter.com/jonschlinkert) * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) Please consider supporting me on Patreon, or [start your own Patreon page](https://patreon.com/invite/bxpbvm)! ### License Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert). Released under the [MIT License](LICENSE). *** _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 08, 2019._fill-range-master/.gitattributes0000644000175000017500000000017713472205230016643 0ustar xavierxavier# Enforce Unix newlines * text eol=lf # binaries *.ai binary *.psd binary *.jpg binary *.gif binary *.png binary *.jpeg binaryfill-range-master/.github/0000755000175000017500000000000013476020375015314 5ustar xavierxavierfill-range-master/.travis.yml0000644000175000017500000000015313472205230016053 0ustar xavierxaviersudo: false os: - linux - osx - windows language: node_js node_js: - node - '10' - '9' - '8'