Skip to content
This repository was archived by the owner on Mar 22, 2019. It is now read-only.

Commit a83b4f5

Browse files
committed
Use template literals
1 parent e153894 commit a83b4f5

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

index.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function unquoteFontFamily(family) {
6767
quote = setQuote(RegExp.$1);
6868

6969
if (!list.space(family).every(canUnquote)) {
70-
family = quote + family + quote;
70+
family = `${quote}${family}${quote}`;
7171
}
7272

7373
return family;
@@ -84,25 +84,25 @@ function toRGBColor(m, leading, c) {
8484
}
8585

8686
if (c.alpha() < 1) {
87-
return leading + c.cssa();
87+
return `${leading}${c.cssa()}`;
8888
}
8989

90-
return leading + c.hex() + " ";
90+
return `${leading}${c.hex()} `;
9191
}
9292

9393
// Convert to shortest color
9494
function toShortestColor(m, leading, r1, r2, g1, g2, b1, b2) {
95-
let c = "#" + r1 + r2 + g1 + g2 + b1 + b2;
95+
let c = `#${r1}${r2}${g1}${g2}${b1}${b2}`;
9696

9797
if (r1 === r2 && g1 === g2 && b1 === b2) {
98-
c = "#" + r1 + g1 + b1;
98+
c = `#${r1}${g1}${b1}`;
9999
}
100100

101101
if (color.shortest.hasOwnProperty(c)) {
102102
c = color.shortest[c];
103103
}
104104

105-
return leading + c.toLowerCase();
105+
return `${leading}${c.toLowerCase()}`;
106106
}
107107

108108
// Remove unit from 0 length and 0 percentage if possible
@@ -119,26 +119,26 @@ function removeUnitOfZero(prop, m, leading, num, u, position, value) {
119119
}
120120

121121
if (unit.forZero.hasOwnProperty(u)) {
122-
num += unit.forZero[u];
122+
num = `${num}${unit.forZero[u]}`;
123123
}
124124

125-
return leading + num;
125+
return `${leading}${num}`;
126126
}
127127

128128
// Convert to shortest time
129129
function toShortestTime(m, leading, n) {
130-
return leading + (parseInt(n, 10) / 100).toString().replace(/^0+/, "") + "s";
130+
return `${leading}${(parseInt(n, 10) / 100).toString().replace(/^0+/, "")}s`;
131131
}
132132

133133
// Convert to shortest angle
134134
function toShortestAngle(m, leading, n, u) {
135135
n = parseInt(n, 10);
136136

137137
if (Number.isInteger(n / 10)) {
138-
return leading + (n * (360 / 400)) + "deg";
138+
return `${leading}${(n * (360 / 400))}deg`;
139139
}
140140

141-
return leading + n + u;
141+
return `${leading}${n}${u}`;
142142
}
143143

144144
// Unquote inside `url()` notation if possible
@@ -150,16 +150,18 @@ function unquoteURL(m, leading, url) {
150150
url = url.replace(re.escapedBraces, "$1");
151151

152152
if (re.urlNeedQuote.test(url)) {
153-
url = quote + url + quote;
153+
url = `${quote}${url}${quote}`;
154154
}
155155

156-
return leading + "url(" + url + ")";
156+
return `${leading}url(${url})`;
157157
}
158158

159159
// Remove white spaces inside `calc()` notation
160160
function removeCalcWhiteSpaces(m, leading, calc) {
161-
return leading + "calc(" +
162-
calc.replace(re.whiteSpacesBothEndsOfSymbol, "$1") + ")";
161+
return `${leading}calc(${calc.replace(
162+
re.whiteSpacesBothEndsOfSymbol,
163+
"$1"
164+
)})`;
163165
}
164166

165167
// Wring value of declaration
@@ -214,17 +216,17 @@ function unquoteAttributeSelector(m, att, con, val) {
214216
let quote;
215217

216218
if (!con || !val) {
217-
return "[" + att + "]";
219+
return `[${att}]`;
218220
}
219221

220222
val = val.trim().replace(re.quotedString, "$2");
221223
quote = setQuote(RegExp.$1);
222224

223225
if (!canUnquote(val)) {
224-
val = quote + val + quote;
226+
val = `${quote}${val}${quote}`;
225227
}
226228

227-
return "[" + att + con + val + "]";
229+
return `[${att}${con}${val}]`;
228230
}
229231

230232
// Remove white spaces from string
@@ -234,13 +236,13 @@ function removeWhiteSpaces(string) {
234236

235237
// Remove white spaces from both ends of `:not()`
236238
function trimNegationFunction(m, not) {
237-
return ":not(" + not.trim() + ")";
239+
return `:not(${ not.trim() })`;
238240
}
239241

240242
// Remove white spaces around `>`, `+`, and `~`, but not `\>`, `\+`, and `\~`
241243
function trimSelectorCombinator(m, combinator, backslash) {
242244
if (backslash) {
243-
return " " + combinator + " ";
245+
return ` ${ combinator } `;
244246
}
245247

246248
return combinator;
@@ -307,7 +309,7 @@ function uniqueArray(array) {
307309

308310
// Remove duplicate declaration
309311
function removeDuplicateDeclaration(decls, decl) {
310-
const d = decl.raws.before + decl.prop + decl.raws.between + decl.value;
312+
const d = `${decl.raws.before}${decl.prop}${decl.raws.between}${decl.value}`;
311313

312314
if (decls.hasOwnProperty(d)) {
313315
decls[d].remove();
@@ -331,7 +333,7 @@ function removeDefaultFontFaceDescriptor(decl) {
331333
if (
332334
(re.descriptorFontFace.test(prop) && value === "normal") ||
333335
(prop === "unicode-range" && re.unicodeRangeDefault.test(value)) ||
334-
prop + value === "font-weight400"
336+
`${prop}${value}` === "font-weight400"
335337
) {
336338
decl.remove();
337339
}
@@ -341,7 +343,7 @@ function removeDefaultFontFaceDescriptor(decl) {
341343
function quoteImportURL(m, quote, url) {
342344
quote = setQuote(quote);
343345

344-
return quote + url + quote;
346+
return `${quote}${url}${quote}`;
345347
}
346348

347349
// Quote `@namespace` URL
@@ -351,7 +353,7 @@ function quoteNamespaceURL(param, index, p) {
351353
if (param === p[p.length - 1]) {
352354
param = param.replace(re.quotedString, "$2");
353355
quote = setQuote(RegExp.$1);
354-
param = quote + param + quote;
356+
param = `${quote}${param}${quote}`;
355357
}
356358

357359
return param;
@@ -479,7 +481,7 @@ function wringDeclLike(m, prop, value) {
479481

480482
wringDecl.call(null, false, decl);
481483

482-
return "(" + decl.toString() + ")";
484+
return `(${ decl.toString() })`;
483485
}
484486

485487
// Wring ruleset

0 commit comments

Comments
 (0)