123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- 'use strict';
- const stringify = require('./lib/stringify');
- const compile = require('./lib/compile');
- const expand = require('./lib/expand');
- const parse = require('./lib/parse');
- const braces = (input, options = {}) => {
- let output = [];
- if (Array.isArray(input)) {
- for (let pattern of input) {
- let result = braces.create(pattern, options);
- if (Array.isArray(result)) {
- output.push(...result);
- } else {
- output.push(result);
- }
- }
- } else {
- output = [].concat(braces.create(input, options));
- }
- if (options && options.expand === true && options.nodupes === true) {
- output = [...new Set(output)];
- }
- return output;
- };
- braces.parse = (input, options = {}) => parse(input, options);
- braces.stringify = (input, options = {}) => {
- if (typeof input === 'string') {
- return stringify(braces.parse(input, options), options);
- }
- return stringify(input, options);
- };
- braces.compile = (input, options = {}) => {
- if (typeof input === 'string') {
- input = braces.parse(input, options);
- }
- return compile(input, options);
- };
- braces.expand = (input, options = {}) => {
- if (typeof input === 'string') {
- input = braces.parse(input, options);
- }
- let result = expand(input, options);
-
- if (options.noempty === true) {
- result = result.filter(Boolean);
- }
-
- if (options.nodupes === true) {
- result = [...new Set(result)];
- }
- return result;
- };
- braces.create = (input, options = {}) => {
- if (input === '' || input.length < 3) {
- return [input];
- }
- return options.expand !== true
- ? braces.compile(input, options)
- : braces.expand(input, options);
- };
- module.exports = braces;
|