3.0.2 • Published 2 years ago

str-expand v3.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

str-expand

Expand a string pattern into a list of strings using sequence or enum tokens.

Install

npm i str-expand

Usage

const strExpand = require('str-expand')


// single-item list for strings with no tokens

strExpand('http://example.com')
//=> [ 'http://example.com' ]


// empty list for empty string

strExpand('')
//=> []


// expand numeric ranges

strExpand('http://example.com/[1..3].jpg')
//=> [
//        'http://example.com/1.jpg',
//        'http://example.com/2.jpg',
//        'http://example.com/3.jpg',
// ]

strExpand('http://example.com/[1..2]/[3..4].jpg')
// => [
//        'http://example.com/1/3.jpg',
//        'http://example.com/1/4.jpg',
//        'http://example.com/2/3.jpg',
//        'http://example.com/2/4.jpg',
// ]

strExpand('[090..100].png')
// => [ '090.png', '091.png', ... '099.png', '100.png' ]

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




// expand string enums

strExpand('banana {bread,muffin,cake}')
//=> [
//        'banana bread',
//        'banana muffin',
//        'banana cake',
// ]

strExpand('{cold,warm} banana {bread,muffin,cake}')
//=> [
//        'cold banana bread',
//        'cold banana muffin',
//        'cold banana cake',
//        'warm banana bread',
//        'warm banana muffin',
//        'warm banana cake',
// ]


// mix and match

strExpand('It was called {red,blue,yellow} [3..5]')
// => [
//        'It was called red 3',
//        'It was called red 4',
//        'It was called red 5',
//        'It was called blue 3',
//        'It was called blue 4',
//        'It was called blue 5',
//        'It was called yellow 3',
//        'It was called yellow 4',
//        'It was called yellow 5',
// ]
3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.0

4 years ago

1.2.1

6 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago