
MIT 라이선스 braces 3.0.3, 검토된 CVE-2026-93687 depth 백포트 포함, 고정된 소비만 허용
JavaScript로 구현된 Bash 스타일의 중괄호 확장입니다. 다른 중괄호 확장 라이브러리보다 안전하며, 속도를 희생하지 않고 Bash 4.3 중괄호 명세를 완벽하게 지원합니다.
이 프로젝트의 작성자인 Jon Schlinkert를 팔로우하고, 프로젝트에 별을 눌러 ❤️ 를 표시하고 지원해 주시기 바랍니다.
npm으로 설치하세요:
$ npm install --save braces
자세한 내용은 변경 로그를 참조하세요.
Brace 패턴은 특정 범위와 문자 시퀀스를 매칭할 수 있는 기능을 추가하여 glob을 더욱 강력하게 만듭니다.
a/{b,c}/d => ['a/b/d', 'a/c/d']{01..03} => ['01', '02', '03']{2..10..2} => ['2', '4', '6', '8', '10']주요 내보내기는 하나 이상의 brace patterns와 options를 받는 함수입니다.
const braces = require('braces');
// braces(patterns[, options]);
console.log(braces(['{01..05}', '{a..e}']));
//=> ['(0[1-5])', '([a-e])']
console.log(braces(['{01..05}', '{a..e}'], { expand: true }));
//=> ['01', '02', '03', '04', '05', 'a', 'b', 'c', 'd', 'e']
기본적으로 중괄호 패턴은 정규식을 생성하고 매칭하는 데 최적화된 문자열로 컴파일됩니다.
컴파일됨
console.log(braces('a/{x,y,z}/b'));
//=> ['a/(x|y|z)/b']
console.log(braces(['a/{01..20}/b', 'a/{1..5}/b']));
//=> [ 'a/(0[1-9]|1[0-9]|20)/b', 'a/([1-5])/b' ]
확장
expand 옵션을 true로 설정하거나 braces.expand()를 사용하여 중괄호 확장을 활성화합니다(Bash에서 기대할 수 있는 것과 유사한 배열, 또는 echo {1..5}, 또는 minimatch를 반환합니다):
console.log(braces('a/{x,y,z}/b', { expand: true }));
//=> ['a/x/b', 'a/y/b', 'a/z/b']
console.log(braces.expand('{01..10}'));
//=> ['01','02','03','04','05','06','07','08','09','10']
목록을 확장합니다(Bash "sets"와 유사):
console.log(braces('a/{foo,bar,baz}/*.js'));
//=> ['a/(foo|bar|baz)/*.js']
console.log(braces.expand('a/{foo,bar,baz}/*.js'));
//=> ['a/foo/*.js', 'a/bar/*.js', 'a/baz/*.js']
문자 범위를 확장합니다(Bash "시퀀스"와 유사):
console.log(braces.expand('{1..3}')); // ['1', '2', '3']
console.log(braces.expand('a/{1..3}/b')); // ['a/1/b', 'a/2/b', 'a/3/b']
console.log(braces('{a..c}', { expand: true })); // ['a', 'b', 'c']
console.log(braces('foo/{a..c}', { expand: true })); // ['foo/a', 'foo/b', 'foo/c']
// supports zero-padded ranges
console.log(braces('a/{01..03}/b')); //=> ['a/(0[1-3])/b']
console.log(braces('a/{001..300}/b')); //=> ['a/(0{2}[1-9]|0[1-9][0-9]|[12][0-9]{2}|300)/b']
범위 확장에 사용 가능한 모든 옵션은 fill-range를 참고하세요.
범위에는 단계(step) 또는 증분(increment)을 사용할 수 있습니다:
console.log(braces.expand('{2..10..2}'));
//=> ['2', '4', '6', '8', '10']
console.log(braces('{2..10..2}'));
//=> ['(2|4|6|8|10)']
.optimize 메서드가 사용되거나 options.optimize가 true로 설정되면, 시퀀스는 확장을 위해 to-regex-range로 전달됩니다.
중괄호 패턴은 중첩될 수 있습니다. 각 확장된 문자열의 결과는 정렬되지 않으며, 왼쪽에서 오른쪽 순서가 유지됩니다.
"확장된" 중괄호
console.log(braces.expand('a{b,c,/{x,y}}/e'));
//=> ['ab/e', 'ac/e', 'a/x/e', 'a/y/e']
console.log(braces.expand('a/{x,{1..5},y}/c'));
//=> ['a/x/c', 'a/1/c', 'a/2/c', 'a/3/c', 'a/4/c', 'a/5/c', 'a/y/c']
"최적화된" 중괄호
console.log(braces('a{b,c,/{x,y}}/e'));
//=> ['a(b|c|/(x|y))/e']
console.log(braces('a/{x,{1..5},y}/c'));
//=> ['a/(x|([1-5])|y)/c']
중괄호 이스케이프
여는 중괄호 또는 닫는 중괄호 중 하나라도 이스케이프된 경우 중괄호 패턴은 확장되거나 평가되지 않습니다:
console.log(braces.expand('a\\{d,c,b}e'));
//=> ['a{d,c,b}e']
console.log(braces.expand('a{d,c,b\\}e'));
//=> ['a{d,c,b}e']
쉼표 이스케이프
중괄호 안의 쉼표도 이스케이프할 수 있습니다:
console.log(braces.expand('a{b\\,c}d'));
//=> ['a{b,c}d']
console.log(braces.expand('a{d\\,c,b}e'));
//=> ['ad,ce', 'abe']
단일 항목
bash 규칙에 따라, 중괄호 패턴이 단일 문자를 포함하는 경우에도 확장되지 않습니다:
console.log(braces.expand('a{b}c'));
//=> ['a{b}c']
유형: Number
기본값: 10,000
설명: 입력 문자열의 길이를 제한합니다. 입력 문자열이 생성되거나 애플리케이션에서 사용자가 문자열을 전달할 수 있도록 허용하는 등의 경우에 유용합니다.
console.log(braces('a/{b,c}/d', { maxLength: 3 })); //=> throws an error
유형: Boolean
기본값: undefined
설명: "확장된" 중괄호 패턴을 생성합니다 (또는 동일한 작업을 수행하는 braces.expand() 메서드를 사용할 수도 있습니다).
console.log(braces('a/{b,c}/d', { expand: true }));
//=> [ 'a/b/d', 'a/c/d' ]
유형: Boolean
기본값: undefined
설명: 반환된 배열에서 중복을 제거합니다.
유형: Number
기본값: 1000
설명: 사용자가 악의적인 패턴을 전달하는 것을 방지하기 위해, braces.expand()가 사용되거나 options.expand가 true이고 생성된 범위가 rangeLimit를 초과할 경우 오류가 발생합니다.
options.rangeLimit를 사용자 정의하거나 Inifinity로 설정하여 이 기능을 완전히 비활성화할 수 있습니다.
예시
// pattern exceeds the "rangeLimit", so it's optimized automatically
console.log(braces.expand('{1..1000}'));
//=> ['([1-9]|[1-9][0-9]{1,2}|1000)']
// pattern does not exceed "rangeLimit", so it's NOT optimized
console.log(braces.expand('{1..100}'));
//=> ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '100']
유형: Function
기본값: undefined
설명: 범위 확장을 사용자 정의합니다.
예시: 숫자가 아닌 값 변환
const alpha = braces.expand('x/{a..e}/y', {
transform(value, index) {
// When non-numeric values are passed, "value" is a character code.
return 'foo/' + String.fromCharCode(value) + '-' + index;
},
});
console.log(alpha);
//=> [ 'x/foo/a-0/y', 'x/foo/b-1/y', 'x/foo/c-2/y', 'x/foo/d-3/y', 'x/foo/e-4/y' ]
예시: 숫자 값 변환
const numeric = braces.expand('{1..5}', {
transform(value) {
// when numeric values are passed, "value" is a number
return 'foo/' + value * 2;
},
});
console.log(numeric);
//=> [ 'foo/2', 'foo/4', 'foo/6', 'foo/8', 'foo/10' ]
유형: Boolean
기본값: undefined
설명: 정규 표현식에서 수량자는 토큰이 반복될 수 있는 횟수를 지정하는 데 사용할 수 있습니다. 예를 들어 a{1,3}은 문자 a가 1회에서 3회까지 일치함을 의미합니다.
안타깝게도 정규식 수량자는 Bash 목록과 동일한 구문을 공유합니다.