Skip to content

Latest commit

 

History

History
77 lines (53 loc) · 1.73 KB

.verb.md

File metadata and controls

77 lines (53 loc) · 1.73 KB

Example usage

var expand = require('{%= name %}');
expand('start..end..step', options);

// examples
console.log(expand('1..3')) //=> ['1', '2', '3']
console.log(expand('1..10..3')) //=> [ '1', '4', '7', '10' ]

Params

  • start: the number or letter to start with
  • end: the number or letter to end with
  • step: (optional) the step/increment to use. works with letters and numbers.
  • options: Options object to pass to [fill-range][], or a transform function (see [fill-range][] readme for details and documentation)

This library wraps [fill-range][] to support range expansion using .. separated strings. See [fill-range][] for the full list of options and features.

Examples

expand('a..e')
//=> ['a', 'b', 'c', 'd', 'e']

expand('a..e..2')
//=> ['a', 'c', 'e']

expand('A..E..2')
//=> ['A', 'C', 'E']

expand('1..3')
//=> ['1', '2', '3']

expand('0..-5')
//=> [ '0', '-1', '-2', '-3', '-4', '-5' ]

expand('-9..9..3')
//=> [ '-9', '-6', '-3', '0', '3', '6', '9' ])

expand('-1..-10..-2')
//=> [ '-1', '-3', '-5', '-7', '-9' ]

expand('1..10..2')
//=> [ '1', '3', '5', '7', '9' ]

Custom function

Optionally pass a custom function as the second argument:

expand('a..e', function (val, isNumber, pad, i) {
  if (!isNumber) {
    return String.fromCharCode(val) + i;
  }
  return val;
});
//=> ['a0', 'b1', 'c2', 'd3', 'e4']

Benchmarks

{%= docs("benchmark/last.md") %}

History

v2.0.0

Changes

  • Special step characters are no longer supported, as the same thing can be accomplished with a custom transform function.
  • The signature in the transform function has changed. See [fill-range][] for more details.