Skip to content

Commit 354cfbf

Browse files
committedApr 30, 2018
Use let, const
1 parent 13e0d90 commit 354cfbf

File tree

4 files changed

+68
-70
lines changed

4 files changed

+68
-70
lines changed
 

‎index.js

+26-28
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
* Local dependencies
55
*/
66

7-
var compilers = require('./lib/compilers');
8-
var parsers = require('./lib/parsers');
7+
const compilers = require('./lib/compilers');
8+
const parsers = require('./lib/parsers');
99

1010
/**
1111
* Module dependencies
1212
*/
1313

14-
var Snapdragon = require('snapdragon');
15-
var toRegex = require('to-regex');
14+
const Snapdragon = require('snapdragon');
15+
const toRegex = require('to-regex');
1616

1717
/**
1818
* Parses the given POSIX character class `pattern` and returns a
@@ -25,7 +25,7 @@ var toRegex = require('to-regex');
2525
*/
2626

2727
function brackets(pattern, options) {
28-
var res = brackets.create(pattern, options);
28+
const res = brackets.create(pattern, options);
2929
return res.output;
3030
}
3131

@@ -34,7 +34,7 @@ function brackets(pattern, options) {
3434
* array with only the strings that matched the pattern.
3535
*
3636
* ```js
37-
* var brackets = require('expand-brackets');
37+
* const brackets = require('expand-brackets');
3838
* console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]'));
3939
* //=> ['a']
4040
*
@@ -50,22 +50,22 @@ function brackets(pattern, options) {
5050

5151
brackets.match = function(arr, pattern, options) {
5252
arr = [].concat(arr);
53-
var opts = Object.assign({}, options);
54-
var isMatch = brackets.matcher(pattern, opts);
55-
var len = arr.length;
56-
var idx = -1;
57-
var res = [];
53+
const opts = Object.assign({}, options);
54+
const isMatch = brackets.matcher(pattern, opts);
55+
const len = arr.length;
56+
const res = [];
57+
let idx = -1;
5858

5959
while (++idx < len) {
60-
var ele = arr[idx];
60+
const ele = arr[idx];
6161
if (isMatch(ele)) {
6262
res.push(ele);
6363
}
6464
}
6565

6666
if (res.length === 0) {
6767
if (opts.failglob === true) {
68-
throw new Error('no matches found for "' + pattern + '"');
68+
throw new Error(`no matches found for "${pattern}"`);
6969
}
7070

7171
if (opts.nonull === true || opts.nullglob === true) {
@@ -80,7 +80,7 @@ brackets.match = function(arr, pattern, options) {
8080
* brackets `pattern`.
8181
*
8282
* ```js
83-
* var brackets = require('expand-brackets');
83+
* const brackets = require('expand-brackets');
8484
*
8585
* console.log(brackets.isMatch('a.a', '[[:alpha:]].[[:alpha:]]'));
8686
* //=> true
@@ -103,8 +103,8 @@ brackets.isMatch = function(str, pattern, options) {
103103
* function takes the string to match as its only argument.
104104
*
105105
* ```js
106-
* var brackets = require('expand-brackets');
107-
* var isMatch = brackets.matcher('[[:lower:]].[[:upper:]]');
106+
* const brackets = require('expand-brackets');
107+
* const isMatch = brackets.matcher('[[:lower:]].[[:upper:]]');
108108
*
109109
* console.log(isMatch('a.a'));
110110
* //=> false
@@ -118,18 +118,16 @@ brackets.isMatch = function(str, pattern, options) {
118118
*/
119119

120120
brackets.matcher = function(pattern, options) {
121-
var re = brackets.makeRe(pattern, options);
122-
return function(str) {
123-
return re.test(str);
124-
};
121+
const re = brackets.makeRe(pattern, options);
122+
return (str) => re.test(str);
125123
};
126124

127125
/**
128126
* Create a regular expression from the given `pattern`.
129127
*
130128
* ```js
131-
* var brackets = require('expand-brackets');
132-
* var re = brackets.makeRe('[[:alpha:]]');
129+
* const brackets = require('expand-brackets');
130+
* const re = brackets.makeRe('[[:alpha:]]');
133131
* console.log(re);
134132
* //=> /^(?:[a-zA-Z])$/
135133
* ```
@@ -140,8 +138,8 @@ brackets.matcher = function(pattern, options) {
140138
*/
141139

142140
brackets.makeRe = function(pattern, options) {
143-
var res = brackets.create(pattern, options);
144-
var opts = Object.assign({strictErrors: false}, options);
141+
const res = brackets.create(pattern, options);
142+
const opts = Object.assign({strictErrors: false}, options);
145143
return toRegex(res.output, opts);
146144
};
147145

@@ -150,7 +148,7 @@ brackets.makeRe = function(pattern, options) {
150148
* with the compiled `output` and optional source `map`.
151149
*
152150
* ```js
153-
* var brackets = require('expand-brackets');
151+
* const brackets = require('expand-brackets');
154152
* console.log(brackets('[[:alpha:]]'));
155153
* // { options: { source: 'string' },
156154
* // input: '[[:alpha:]]',
@@ -182,13 +180,13 @@ brackets.makeRe = function(pattern, options) {
182180
*/
183181

184182
brackets.create = function(pattern, options) {
185-
var snapdragon = (options && options.snapdragon) || new Snapdragon(options);
183+
const snapdragon = (options && options.snapdragon) || new Snapdragon(options);
186184
compilers(snapdragon);
187185
parsers(snapdragon);
188186

189-
var ast = snapdragon.parse(pattern, options);
187+
const ast = snapdragon.parse(pattern, options);
190188
ast.input = pattern;
191-
var res = snapdragon.compile(ast, options);
189+
const res = snapdragon.compile(ast, options);
192190
res.input = pattern;
193191
return res;
194192
};

‎lib/compilers.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var posix = require('posix-character-classes');
3+
const posix = require('posix-character-classes');
44

55
module.exports = function(brackets) {
66
brackets.compiler
@@ -30,7 +30,7 @@ module.exports = function(brackets) {
3030
return this.emit('\\[::\\]', node);
3131
}
3232

33-
var val = posix[node.inner];
33+
let val = posix[node.inner];
3434
if (typeof val === 'undefined') {
3535
val = '[' + node.inner + ']';
3636
}
@@ -48,7 +48,7 @@ module.exports = function(brackets) {
4848
return this.emit(node.val, node);
4949
})
5050
.set('bracket.inner', function(node) {
51-
var inner = node.val;
51+
let inner = node.val;
5252

5353
if (inner === '[' || inner === ']') {
5454
return this.emit('\\' + node.val, node);
@@ -64,7 +64,7 @@ module.exports = function(brackets) {
6464
inner = inner.split('-').join('\\-');
6565
}
6666

67-
var isNegated = inner.charAt(0) === '^';
67+
const isNegated = inner.charAt(0) === '^';
6868
// add slashes to negated brackets, per spec
6969
if (isNegated && inner.indexOf('/') === -1) {
7070
inner += '/';
@@ -78,7 +78,7 @@ module.exports = function(brackets) {
7878
return this.emit(inner, node);
7979
})
8080
.set('bracket.close', function(node) {
81-
var val = node.val.replace(/^\\/, '');
81+
const val = node.val.replace(/^\\/, '');
8282
if (node.parent.escaped === true) {
8383
return this.emit('\\' + val, node);
8484
}

‎lib/parsers.js

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'use strict';
22

3-
var utils = require('./utils');
3+
const utils = require('./utils');
44

55
/**
66
* Text regex
77
*/
88

9-
var TEXT_REGEX = '(\\[(?=.*\\])|\\])+';
10-
var not = utils.createRegex(TEXT_REGEX);
9+
const TEXT_REGEX = '(\\[(?=.*\\])|\\])+';
10+
const not = utils.createRegex(TEXT_REGEX);
1111

1212
/**
1313
* Brackets parsers
@@ -20,8 +20,8 @@ function parsers(brackets) {
2020

2121
.set('escape', function() {
2222
if (this.isInside('bracket')) return;
23-
var pos = this.position();
24-
var m = this.match(/^\\(.)/);
23+
const pos = this.position();
24+
const m = this.match(/^\\(.)/);
2525
if (!m) return;
2626

2727
return pos({
@@ -36,8 +36,8 @@ function parsers(brackets) {
3636

3737
.set('text', function() {
3838
if (this.isInside('bracket')) return;
39-
var pos = this.position();
40-
var m = this.match(not);
39+
const pos = this.position();
40+
const m = this.match(not);
4141
if (!m || !m[0]) return;
4242

4343
return pos({
@@ -51,8 +51,8 @@ function parsers(brackets) {
5151
*/
5252

5353
.set('posix', function() {
54-
var pos = this.position();
55-
var m = this.match(/^\[:(.*?):\](?=.*\])/);
54+
const pos = this.position();
55+
const m = this.match(/^\[:(.*?):\](?=.*\])/);
5656
if (!m) return;
5757

5858
var inside = this.isInside('bracket');
@@ -79,13 +79,13 @@ function parsers(brackets) {
7979
*/
8080

8181
.set('bracket.open', function() {
82-
var parsed = this.parsed;
83-
var pos = this.position();
84-
var m = this.match(/^\[(?=.*\])/);
82+
const parsed = this.parsed;
83+
const pos = this.position();
84+
const m = this.match(/^\[(?=.*\])/);
8585
if (!m) return;
8686

87-
var prev = this.prev();
88-
var last = utils.last(prev.nodes);
87+
const prev = this.prev();
88+
const last = utils.last(prev.nodes);
8989

9090
if (parsed.slice(-1) === '\\' && !this.isInside('bracket')) {
9191
last.val = last.val.slice(0, last.val.length - 1);
@@ -95,7 +95,7 @@ function parsers(brackets) {
9595
});
9696
}
9797

98-
var open = pos({
98+
const open = pos({
9999
type: 'bracket.open',
100100
val: m[0]
101101
});
@@ -107,7 +107,7 @@ function parsers(brackets) {
107107
return open;
108108
}
109109

110-
var node = pos({
110+
const node = pos({
111111
type: 'bracket',
112112
nodes: []
113113
});
@@ -123,24 +123,24 @@ function parsers(brackets) {
123123

124124
.set('bracket.inner', function() {
125125
if (!this.isInside('bracket')) return;
126-
var pos = this.position();
127-
var m = this.match(not);
126+
const pos = this.position();
127+
const m = this.match(not);
128128
if (!m || !m[0]) return;
129129

130-
var next = this.input.charAt(0);
131-
var val = m[0];
130+
const next = this.input.charAt(0);
131+
let val = m[0];
132132

133-
var node = pos({
133+
const node = pos({
134134
type: 'bracket.inner',
135-
val: val
135+
val
136136
});
137137

138138
if (val === '\\\\') {
139139
return node;
140140
}
141141

142-
var first = val.charAt(0);
143-
var last = val.slice(-1);
142+
const first = val.charAt(0);
143+
const last = val.slice(-1);
144144

145145
if (first === '!') {
146146
val = '^' + val.slice(1);
@@ -160,13 +160,13 @@ function parsers(brackets) {
160160
*/
161161

162162
.set('bracket.close', function() {
163-
var parsed = this.parsed;
164-
var pos = this.position();
165-
var m = this.match(/^\]/);
163+
const parsed = this.parsed;
164+
const pos = this.position();
165+
const m = this.match(/^\]/);
166166
if (!m) return;
167167

168-
var prev = this.prev();
169-
var last = utils.last(prev.nodes);
168+
const prev = this.prev();
169+
const last = utils.last(prev.nodes);
170170

171171
if (parsed.slice(-1) === '\\' && !this.isInside('bracket')) {
172172
last.val = last.val.slice(0, last.val.length - 1);
@@ -177,7 +177,7 @@ function parsers(brackets) {
177177
});
178178
}
179179

180-
var node = pos({
180+
const node = pos({
181181
type: 'bracket.close',
182182
rest: this.input,
183183
val: m[0]
@@ -189,7 +189,7 @@ function parsers(brackets) {
189189
return node;
190190
}
191191

192-
var bracket = this.pop('bracket');
192+
const bracket = this.pop('bracket');
193193
if (!this.isType(bracket, 'bracket')) {
194194
if (this.options.strict) {
195195
throw new Error('missing opening "["');

‎lib/utils.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
var toRegex = require('to-regex');
4-
var regexNot = require('regex-not');
5-
var cached;
3+
const toRegex = require('to-regex');
4+
const regexNot = require('regex-not');
5+
let cached;
66

77
/**
88
* Get the last element from `array`
@@ -20,9 +20,9 @@ exports.last = function(arr) {
2020

2121
exports.createRegex = function(pattern, include) {
2222
if (cached) return cached;
23-
var opts = {contains: true, strictClose: false};
24-
var not = regexNot.create(pattern, opts);
25-
var re;
23+
const opts = {contains: true, strictClose: false};
24+
const not = regexNot.create(pattern, opts);
25+
let re;
2626

2727
if (typeof include === 'string') {
2828
re = toRegex('^(?:' + include + '|' + not + ')', opts);

0 commit comments

Comments
 (0)
Please sign in to comment.