-
Notifications
You must be signed in to change notification settings - Fork 0
/
strwrap.js
76 lines (71 loc) · 1.66 KB
/
strwrap.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
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
/**
* github.com/torvalamo/strwrap
* MIT License
*/
'use strict';
/**
* Wrap it in a conditional in case it's require()'d multiple times.
*/
if (!String.prototype.wrap) {
Object.defineProperties(String.prototype, {
wrap: {
value: function(before, after) {
if (!after) {
if (after === null || before.length % 2) {
after = before;
} else {
const length = before.length / 2;
after = before.substr(length);
before = before.substr(0, length);
}
}
return before + this.toString() + after;
}
},
quote: {
get: function() {return this.wrap('\'')}
},
quoted: {
get: function() {return this.wrap('"')}
},
aquote: {
get: function() {return this.wrap('‹›')}
},
aquoted: {
get: function() {return this.wrap('«»')}
},
raquote: {
get: function() {return this.wrap('›‹')}
},
raquoted: {
get: function() {return this.wrap('»«')}
},
cquote: {
get: function() {return this.wrap('‘’')}
},
cquoted: {
get: function() {return this.wrap('“”')}
},
lquote: {
get: function() {return this.wrap('‚‛')}
},
lquoted: {
get: function() {return this.wrap('„‟')}
},
parentheses: {
get: function() {return this.wrap('()')}
},
braces: {
get: function() {return this.wrap('{}')}
},
chevrons: {
get: function() {return this.wrap('<>')}
},
crotchets: {
get: function() {return this.wrap('[]')}
},
dbrackets: {
get: function() {return this.wrap('⟦⟧')}
}
});
}