Skip to content

Commit c87d9ec

Browse files
committed
Removed trim shim, and replaced it with regex trim
1 parent d2e8fbb commit c87d9ec

File tree

1 file changed

+7
-37
lines changed

1 file changed

+7
-37
lines changed

index.js

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,6 @@ module.exports = function(css, options){
99
var lineno = 1;
1010
var column = 1;
1111

12-
/**
13-
* Shim-wrapper for trim. Will use native trim if supported, otherwise the trim
14-
* found at https://github.com/kriskowal/es5-shim/blob/master/es5-shim.js
15-
* at commit 32ff9747d5baaa446d5a49d0078ed38fcff93ab0
16-
*
17-
* Modified a bit to not pollute String prototype.
18-
*/
19-
20-
function trim(str) {
21-
if (str === void 0 || str === null) {
22-
throw new TypeError('trim called on null or undefined');
23-
}
24-
25-
var ws = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003' +
26-
'\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028' +
27-
'\u2029\uFEFF';
28-
29-
if (!String.prototype.trim || ws.trim()) {
30-
// http://blog.stevenlevithan.com/archives/faster-trim-javascript
31-
// http://perfectionkills.com/whitespace-deviations/
32-
ws = "[" + ws + "]";
33-
var trimBeginRegexp = new RegExp("^" + ws + ws + "*");
34-
var trimEndRegexp = new RegExp(ws + ws + "*$");
35-
36-
return String(str).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
37-
}
38-
39-
return String(str).trim();
40-
}
41-
4212
/**
4313
* Update lineno and column based on `str`.
4414
*/
@@ -198,7 +168,7 @@ module.exports = function(css, options){
198168
function selector() {
199169
var m = match(/^([^{]+)/);
200170
if (!m) return;
201-
return trim(m[0]).split(/\s*,\s*/);
171+
return m[0].replace(/^\s+|\s+$/g, '').split(/\s*,\s*/);
202172
}
203173

204174
/**
@@ -223,7 +193,7 @@ module.exports = function(css, options){
223193
var ret = pos({
224194
type: 'declaration',
225195
property: prop,
226-
value: trim(val[0])
196+
value: val[0].replace(/^\s+|\s+$/g, '')
227197
});
228198

229199
// ;
@@ -320,7 +290,7 @@ module.exports = function(css, options){
320290
var m = match(/^@supports *([^{]+)/);
321291

322292
if (!m) return;
323-
var supports = trim(m[1]);
293+
var supports = m[1].replace(/^\s+|\s+$/g, '');
324294

325295
if (!open()) return error("@supports missing '{'");
326296

@@ -344,7 +314,7 @@ module.exports = function(css, options){
344314
var m = match(/^@media *([^{]+)/);
345315

346316
if (!m) return;
347-
var media = trim(m[1]);
317+
var media = m[1].replace(/^\s+|\s+$/g, '');
348318

349319
if (!open()) return error("@media missing '{'");
350320

@@ -398,8 +368,8 @@ module.exports = function(css, options){
398368
var m = match(/^@([-\w]+)?document *([^{]+)/);
399369
if (!m) return;
400370

401-
var vendor = trim(m[1] || '');
402-
var doc = trim(m[2]);
371+
var vendor = (m[1] || '').replace(/^\s+|\s+$/g, '');
372+
var doc = m[2].replace(/^\s+|\s+$/g, '');
403373

404374
if (!open()) return error("@document missing '{'");
405375

@@ -448,7 +418,7 @@ module.exports = function(css, options){
448418
var m = match(new RegExp('^@' + name + ' *([^;\\n]+);'));
449419
if (!m) return;
450420
var ret = { type: name };
451-
ret[name] = trim(m[1]);
421+
ret[name] = m[1].replace(/^\s+|\s+$/g, '');
452422
return pos(ret);
453423
}
454424

0 commit comments

Comments
 (0)