-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (35 loc) · 801 Bytes
/
index.js
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
function emptyQuotes(options) {
return options.quotes + options.quotes;
}
function quoteString(options, str) {
if (str === '') {
return emptyQuotes(options);
}
if (str[0] !== options.quotes) {
str = options.quotes + str;
}
if (str[str.length - 1] !== options.quotes) {
str += options.quotes;
}
return str;
}
function quoteOptions(options, str) {
if (arguments.length === 1) {
str = options;
options = { quotes: '"' };
}
if (typeof str === 'string') {
return quoteString(options, str);
}
if (typeof str === 'undefined' || str === null) {
return emptyQuotes(options);
}
return str;
}
function quote(str) {
if (typeof str === 'object') {
return quoteOptions.bind(null, str);
}
return quoteOptions(str);
}
module.exports = quote;