|
1
|
|
|
/* |
|
2
|
|
|
* Underscore.string |
|
3
|
|
|
* (c) 2010 Esa-Matti Suuronen <esa-matti aet suuronen dot org> |
|
4
|
|
|
* Underscore.string is freely distributable under the terms of the MIT license. |
|
5
|
|
|
* Documentation: https://github.com/epeli/underscore.string |
|
6
|
|
|
* Some code is borrowed from MooTools and Alexandru Marasteanu. |
|
7
|
|
|
* Version '3.3.4' |
|
8
|
|
|
* @preserve |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.s = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
|
|
|
|
|
|
12
|
|
|
var trim = require('./trim'); |
|
13
|
|
|
var decap = require('./decapitalize'); |
|
14
|
|
|
|
|
15
|
|
|
module.exports = function camelize(str, decapitalize) { |
|
16
|
|
|
str = trim(str).replace(/[-_\s]+(.)?/g, function(match, c) { |
|
17
|
|
|
return c ? c.toUpperCase() : ''; |
|
18
|
|
|
}); |
|
19
|
|
|
|
|
20
|
|
|
if (decapitalize === true) { |
|
21
|
|
|
return decap(str); |
|
22
|
|
|
} else { |
|
23
|
|
|
return str; |
|
24
|
|
|
} |
|
25
|
|
|
}; |
|
26
|
|
|
|
|
27
|
|
|
},{"./decapitalize":10,"./trim":65}],2:[function(require,module,exports){ |
|
28
|
|
|
var makeString = require('./helper/makeString'); |
|
29
|
|
|
|
|
30
|
|
|
module.exports = function capitalize(str, lowercaseRest) { |
|
31
|
|
|
str = makeString(str); |
|
32
|
|
|
var remainingChars = !lowercaseRest ? str.slice(1) : str.slice(1).toLowerCase(); |
|
33
|
|
|
|
|
34
|
|
|
return str.charAt(0).toUpperCase() + remainingChars; |
|
35
|
|
|
}; |
|
36
|
|
|
|
|
37
|
|
|
},{"./helper/makeString":20}],3:[function(require,module,exports){ |
|
38
|
|
|
var makeString = require('./helper/makeString'); |
|
39
|
|
|
|
|
40
|
|
|
module.exports = function chars(str) { |
|
41
|
|
|
return makeString(str).split(''); |
|
42
|
|
|
}; |
|
43
|
|
|
|
|
44
|
|
|
},{"./helper/makeString":20}],4:[function(require,module,exports){ |
|
45
|
|
|
module.exports = function chop(str, step) { |
|
46
|
|
|
if (str == null) return []; |
|
47
|
|
|
str = String(str); |
|
48
|
|
|
step = ~~step; |
|
49
|
|
|
return step > 0 ? str.match(new RegExp('.{1,' + step + '}', 'g')) : [str]; |
|
50
|
|
|
}; |
|
51
|
|
|
|
|
52
|
|
|
},{}],5:[function(require,module,exports){ |
|
53
|
|
|
var capitalize = require('./capitalize'); |
|
54
|
|
|
var camelize = require('./camelize'); |
|
55
|
|
|
var makeString = require('./helper/makeString'); |
|
56
|
|
|
|
|
57
|
|
|
module.exports = function classify(str) { |
|
58
|
|
|
str = makeString(str); |
|
59
|
|
|
return capitalize(camelize(str.replace(/[\W_]/g, ' ')).replace(/\s/g, '')); |
|
60
|
|
|
}; |
|
61
|
|
|
|
|
62
|
|
|
},{"./camelize":1,"./capitalize":2,"./helper/makeString":20}],6:[function(require,module,exports){ |
|
63
|
|
|
var trim = require('./trim'); |
|
64
|
|
|
|
|
65
|
|
|
module.exports = function clean(str) { |
|
66
|
|
|
return trim(str).replace(/\s\s+/g, ' '); |
|
67
|
|
|
}; |
|
68
|
|
|
|
|
69
|
|
|
},{"./trim":65}],7:[function(require,module,exports){ |
|
70
|
|
|
|
|
71
|
|
|
var makeString = require('./helper/makeString'); |
|
72
|
|
|
|
|
73
|
|
|
var from = 'ąàáäâãåæăćčĉęèéëêĝĥìíïîĵłľńňòóöőôõðøśșşšŝťțţŭùúüűûñÿýçżźž', |
|
74
|
|
|
to = 'aaaaaaaaaccceeeeeghiiiijllnnoooooooossssstttuuuuuunyyczzz'; |
|
75
|
|
|
|
|
76
|
|
|
from += from.toUpperCase(); |
|
77
|
|
|
to += to.toUpperCase(); |
|
78
|
|
|
|
|
79
|
|
|
to = to.split(''); |
|
80
|
|
|
|
|
81
|
|
|
// for tokens requireing multitoken output |
|
82
|
|
|
from += 'ß'; |
|
83
|
|
|
to.push('ss'); |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
module.exports = function cleanDiacritics(str) { |
|
87
|
|
|
return makeString(str).replace(/.{1}/g, function(c){ |
|
88
|
|
|
var index = from.indexOf(c); |
|
89
|
|
|
return index === -1 ? c : to[index]; |
|
90
|
|
|
}); |
|
91
|
|
|
}; |
|
92
|
|
|
|
|
93
|
|
|
},{"./helper/makeString":20}],8:[function(require,module,exports){ |
|
94
|
|
|
var makeString = require('./helper/makeString'); |
|
95
|
|
|
|
|
96
|
|
|
module.exports = function(str, substr) { |
|
97
|
|
|
str = makeString(str); |
|
98
|
|
|
substr = makeString(substr); |
|
99
|
|
|
|
|
100
|
|
|
if (str.length === 0 || substr.length === 0) return 0; |
|
101
|
|
|
|
|
102
|
|
|
return str.split(substr).length - 1; |
|
103
|
|
|
}; |
|
104
|
|
|
|
|
105
|
|
|
},{"./helper/makeString":20}],9:[function(require,module,exports){ |
|
106
|
|
|
var trim = require('./trim'); |
|
107
|
|
|
|
|
108
|
|
|
module.exports = function dasherize(str) { |
|
109
|
|
|
return trim(str).replace(/([A-Z])/g, '-$1').replace(/[-_\s]+/g, '-').toLowerCase(); |
|
110
|
|
|
}; |
|
111
|
|
|
|
|
112
|
|
|
},{"./trim":65}],10:[function(require,module,exports){ |
|
113
|
|
|
var makeString = require('./helper/makeString'); |
|
114
|
|
|
|
|
115
|
|
|
module.exports = function decapitalize(str) { |
|
116
|
|
|
str = makeString(str); |
|
117
|
|
|
return str.charAt(0).toLowerCase() + str.slice(1); |
|
118
|
|
|
}; |
|
119
|
|
|
|
|
120
|
|
|
},{"./helper/makeString":20}],11:[function(require,module,exports){ |
|
121
|
|
|
var makeString = require('./helper/makeString'); |
|
122
|
|
|
|
|
123
|
|
|
function getIndent(str) { |
|
124
|
|
|
var matches = str.match(/^[\s\\t]*/gm); |
|
125
|
|
|
var indent = matches[0].length; |
|
126
|
|
|
|
|
127
|
|
|
for (var i = 1; i < matches.length; i++) { |
|
128
|
|
|
indent = Math.min(matches[i].length, indent); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
return indent; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
module.exports = function dedent(str, pattern) { |
|
135
|
|
|
str = makeString(str); |
|
136
|
|
|
var indent = getIndent(str); |
|
137
|
|
|
var reg; |
|
138
|
|
|
|
|
139
|
|
|
if (indent === 0) return str; |
|
140
|
|
|
|
|
141
|
|
|
if (typeof pattern === 'string') { |
|
142
|
|
|
reg = new RegExp('^' + pattern, 'gm'); |
|
143
|
|
|
} else { |
|
144
|
|
|
reg = new RegExp('^[ \\t]{' + indent + '}', 'gm'); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
return str.replace(reg, ''); |
|
148
|
|
|
}; |
|
149
|
|
|
|
|
150
|
|
|
},{"./helper/makeString":20}],12:[function(require,module,exports){ |
|
151
|
|
|
var makeString = require('./helper/makeString'); |
|
152
|
|
|
var toPositive = require('./helper/toPositive'); |
|
153
|
|
|
|
|
154
|
|
|
module.exports = function endsWith(str, ends, position) { |
|
155
|
|
|
str = makeString(str); |
|
156
|
|
|
ends = '' + ends; |
|
157
|
|
|
if (typeof position == 'undefined') { |
|
158
|
|
|
position = str.length - ends.length; |
|
159
|
|
|
} else { |
|
160
|
|
|
position = Math.min(toPositive(position), str.length) - ends.length; |
|
161
|
|
|
} |
|
162
|
|
|
return position >= 0 && str.indexOf(ends, position) === position; |
|
163
|
|
|
}; |
|
164
|
|
|
|
|
165
|
|
|
},{"./helper/makeString":20,"./helper/toPositive":22}],13:[function(require,module,exports){ |
|
166
|
|
|
var makeString = require('./helper/makeString'); |
|
167
|
|
|
var escapeChars = require('./helper/escapeChars'); |
|
168
|
|
|
|
|
169
|
|
|
var regexString = '['; |
|
170
|
|
|
for(var key in escapeChars) { |
|
|
|
|
|
|
171
|
|
|
regexString += key; |
|
172
|
|
|
} |
|
173
|
|
|
regexString += ']'; |
|
174
|
|
|
|
|
175
|
|
|
var regex = new RegExp( regexString, 'g'); |
|
176
|
|
|
|
|
177
|
|
|
module.exports = function escapeHTML(str) { |
|
178
|
|
|
|
|
179
|
|
|
return makeString(str).replace(regex, function(m) { |
|
180
|
|
|
return '&' + escapeChars[m] + ';'; |
|
181
|
|
|
}); |
|
182
|
|
|
}; |
|
183
|
|
|
|
|
184
|
|
|
},{"./helper/escapeChars":17,"./helper/makeString":20}],14:[function(require,module,exports){ |
|
185
|
|
|
module.exports = function() { |
|
186
|
|
|
var result = {}; |
|
187
|
|
|
|
|
188
|
|
|
for (var prop in this) { |
|
189
|
|
|
if (!this.hasOwnProperty(prop) || prop.match(/^(?:include|contains|reverse|join|map|wrap)$/)) continue; |
|
190
|
|
|
result[prop] = this[prop]; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
return result; |
|
194
|
|
|
}; |
|
195
|
|
|
|
|
196
|
|
|
},{}],15:[function(require,module,exports){ |
|
197
|
|
|
var makeString = require('./makeString'); |
|
198
|
|
|
|
|
199
|
|
|
module.exports = function adjacent(str, direction) { |
|
200
|
|
|
str = makeString(str); |
|
201
|
|
|
if (str.length === 0) { |
|
202
|
|
|
return ''; |
|
203
|
|
|
} |
|
204
|
|
|
return str.slice(0, -1) + String.fromCharCode(str.charCodeAt(str.length - 1) + direction); |
|
205
|
|
|
}; |
|
206
|
|
|
|
|
207
|
|
|
},{"./makeString":20}],16:[function(require,module,exports){ |
|
208
|
|
|
var escapeRegExp = require('./escapeRegExp'); |
|
209
|
|
|
|
|
210
|
|
|
module.exports = function defaultToWhiteSpace(characters) { |
|
211
|
|
|
if (characters == null) |
|
212
|
|
|
return '\\s'; |
|
213
|
|
|
else if (characters.source) |
|
214
|
|
|
return characters.source; |
|
215
|
|
|
else |
|
216
|
|
|
return '[' + escapeRegExp(characters) + ']'; |
|
217
|
|
|
}; |
|
218
|
|
|
|
|
219
|
|
|
},{"./escapeRegExp":18}],17:[function(require,module,exports){ |
|
220
|
|
|
/* We're explicitly defining the list of entities we want to escape. |
|
221
|
|
|
nbsp is an HTML entity, but we don't want to escape all space characters in a string, hence its omission in this map. |
|
222
|
|
|
|
|
223
|
|
|
*/ |
|
224
|
|
|
var escapeChars = { |
|
225
|
|
|
'¢' : 'cent', |
|
226
|
|
|
'£' : 'pound', |
|
227
|
|
|
'¥' : 'yen', |
|
228
|
|
|
'€': 'euro', |
|
229
|
|
|
'©' :'copy', |
|
230
|
|
|
'®' : 'reg', |
|
231
|
|
|
'<' : 'lt', |
|
232
|
|
|
'>' : 'gt', |
|
233
|
|
|
'"' : 'quot', |
|
234
|
|
|
'&' : 'amp', |
|
235
|
|
|
'\'' : '#39' |
|
236
|
|
|
}; |
|
237
|
|
|
|
|
238
|
|
|
module.exports = escapeChars; |
|
239
|
|
|
|
|
240
|
|
|
},{}],18:[function(require,module,exports){ |
|
241
|
|
|
var makeString = require('./makeString'); |
|
242
|
|
|
|
|
243
|
|
|
module.exports = function escapeRegExp(str) { |
|
244
|
|
|
return makeString(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1'); |
|
245
|
|
|
}; |
|
246
|
|
|
|
|
247
|
|
|
},{"./makeString":20}],19:[function(require,module,exports){ |
|
248
|
|
|
/* |
|
249
|
|
|
We're explicitly defining the list of entities that might see in escape HTML strings |
|
250
|
|
|
*/ |
|
251
|
|
|
var htmlEntities = { |
|
252
|
|
|
nbsp: ' ', |
|
253
|
|
|
cent: '¢', |
|
254
|
|
|
pound: '£', |
|
255
|
|
|
yen: '¥', |
|
256
|
|
|
euro: '€', |
|
257
|
|
|
copy: '©', |
|
258
|
|
|
reg: '®', |
|
259
|
|
|
lt: '<', |
|
260
|
|
|
gt: '>', |
|
261
|
|
|
quot: '"', |
|
262
|
|
|
amp: '&', |
|
263
|
|
|
apos: '\'' |
|
264
|
|
|
}; |
|
265
|
|
|
|
|
266
|
|
|
module.exports = htmlEntities; |
|
267
|
|
|
|
|
268
|
|
|
},{}],20:[function(require,module,exports){ |
|
269
|
|
|
/** |
|
270
|
|
|
* Ensure some object is a coerced to a string |
|
271
|
|
|
**/ |
|
272
|
|
|
module.exports = function makeString(object) { |
|
273
|
|
|
if (object == null) return ''; |
|
274
|
|
|
return '' + object; |
|
275
|
|
|
}; |
|
276
|
|
|
|
|
277
|
|
|
},{}],21:[function(require,module,exports){ |
|
278
|
|
|
module.exports = function strRepeat(str, qty){ |
|
279
|
|
|
if (qty < 1) return ''; |
|
280
|
|
|
var result = ''; |
|
281
|
|
|
while (qty > 0) { |
|
282
|
|
|
if (qty & 1) result += str; |
|
|
|
|
|
|
283
|
|
|
qty >>= 1, str += str; |
|
|
|
|
|
|
284
|
|
|
} |
|
285
|
|
|
return result; |
|
286
|
|
|
}; |
|
287
|
|
|
|
|
288
|
|
|
},{}],22:[function(require,module,exports){ |
|
289
|
|
|
module.exports = function toPositive(number) { |
|
290
|
|
|
return number < 0 ? 0 : (+number || 0); |
|
291
|
|
|
}; |
|
292
|
|
|
|
|
293
|
|
|
},{}],23:[function(require,module,exports){ |
|
294
|
|
|
var capitalize = require('./capitalize'); |
|
295
|
|
|
var underscored = require('./underscored'); |
|
296
|
|
|
var trim = require('./trim'); |
|
297
|
|
|
|
|
298
|
|
|
module.exports = function humanize(str) { |
|
299
|
|
|
return capitalize(trim(underscored(str).replace(/_id$/, '').replace(/_/g, ' '))); |
|
300
|
|
|
}; |
|
301
|
|
|
|
|
302
|
|
|
},{"./capitalize":2,"./trim":65,"./underscored":67}],24:[function(require,module,exports){ |
|
303
|
|
|
var makeString = require('./helper/makeString'); |
|
304
|
|
|
|
|
305
|
|
|
module.exports = function include(str, needle) { |
|
306
|
|
|
if (needle === '') return true; |
|
307
|
|
|
return makeString(str).indexOf(needle) !== -1; |
|
308
|
|
|
}; |
|
309
|
|
|
|
|
310
|
|
|
},{"./helper/makeString":20}],25:[function(require,module,exports){ |
|
311
|
|
|
/* |
|
312
|
|
|
* Underscore.string |
|
313
|
|
|
* (c) 2010 Esa-Matti Suuronen <esa-matti aet suuronen dot org> |
|
314
|
|
|
* Underscore.string is freely distributable under the terms of the MIT license. |
|
315
|
|
|
* Documentation: https://github.com/epeli/underscore.string |
|
316
|
|
|
* Some code is borrowed from MooTools and Alexandru Marasteanu. |
|
317
|
|
|
* Version '3.3.4' |
|
318
|
|
|
* @preserve |
|
319
|
|
|
*/ |
|
320
|
|
|
|
|
321
|
|
|
'use strict'; |
|
322
|
|
|
|
|
323
|
|
|
function s(value) { |
|
324
|
|
|
/* jshint validthis: true */ |
|
325
|
|
|
if (!(this instanceof s)) return new s(value); |
|
|
|
|
|
|
326
|
|
|
this._wrapped = value; |
|
|
|
|
|
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
s.VERSION = '3.3.4'; |
|
330
|
|
|
|
|
331
|
|
|
s.isBlank = require('./isBlank'); |
|
332
|
|
|
s.stripTags = require('./stripTags'); |
|
333
|
|
|
s.capitalize = require('./capitalize'); |
|
334
|
|
|
s.decapitalize = require('./decapitalize'); |
|
335
|
|
|
s.chop = require('./chop'); |
|
336
|
|
|
s.trim = require('./trim'); |
|
337
|
|
|
s.clean = require('./clean'); |
|
338
|
|
|
s.cleanDiacritics = require('./cleanDiacritics'); |
|
339
|
|
|
s.count = require('./count'); |
|
340
|
|
|
s.chars = require('./chars'); |
|
341
|
|
|
s.swapCase = require('./swapCase'); |
|
342
|
|
|
s.escapeHTML = require('./escapeHTML'); |
|
343
|
|
|
s.unescapeHTML = require('./unescapeHTML'); |
|
344
|
|
|
s.splice = require('./splice'); |
|
345
|
|
|
s.insert = require('./insert'); |
|
346
|
|
|
s.replaceAll = require('./replaceAll'); |
|
347
|
|
|
s.include = require('./include'); |
|
348
|
|
|
s.join = require('./join'); |
|
349
|
|
|
s.lines = require('./lines'); |
|
350
|
|
|
s.dedent = require('./dedent'); |
|
351
|
|
|
s.reverse = require('./reverse'); |
|
352
|
|
|
s.startsWith = require('./startsWith'); |
|
353
|
|
|
s.endsWith = require('./endsWith'); |
|
354
|
|
|
s.pred = require('./pred'); |
|
355
|
|
|
s.succ = require('./succ'); |
|
356
|
|
|
s.titleize = require('./titleize'); |
|
357
|
|
|
s.camelize = require('./camelize'); |
|
358
|
|
|
s.underscored = require('./underscored'); |
|
359
|
|
|
s.dasherize = require('./dasherize'); |
|
360
|
|
|
s.classify = require('./classify'); |
|
361
|
|
|
s.humanize = require('./humanize'); |
|
362
|
|
|
s.ltrim = require('./ltrim'); |
|
363
|
|
|
s.rtrim = require('./rtrim'); |
|
364
|
|
|
s.truncate = require('./truncate'); |
|
365
|
|
|
s.prune = require('./prune'); |
|
366
|
|
|
s.words = require('./words'); |
|
367
|
|
|
s.pad = require('./pad'); |
|
368
|
|
|
s.lpad = require('./lpad'); |
|
369
|
|
|
s.rpad = require('./rpad'); |
|
370
|
|
|
s.lrpad = require('./lrpad'); |
|
371
|
|
|
s.sprintf = require('./sprintf'); |
|
372
|
|
|
s.vsprintf = require('./vsprintf'); |
|
373
|
|
|
s.toNumber = require('./toNumber'); |
|
374
|
|
|
s.numberFormat = require('./numberFormat'); |
|
375
|
|
|
s.strRight = require('./strRight'); |
|
376
|
|
|
s.strRightBack = require('./strRightBack'); |
|
377
|
|
|
s.strLeft = require('./strLeft'); |
|
378
|
|
|
s.strLeftBack = require('./strLeftBack'); |
|
379
|
|
|
s.toSentence = require('./toSentence'); |
|
380
|
|
|
s.toSentenceSerial = require('./toSentenceSerial'); |
|
381
|
|
|
s.slugify = require('./slugify'); |
|
382
|
|
|
s.surround = require('./surround'); |
|
383
|
|
|
s.quote = require('./quote'); |
|
384
|
|
|
s.unquote = require('./unquote'); |
|
385
|
|
|
s.repeat = require('./repeat'); |
|
386
|
|
|
s.naturalCmp = require('./naturalCmp'); |
|
387
|
|
|
s.levenshtein = require('./levenshtein'); |
|
388
|
|
|
s.toBoolean = require('./toBoolean'); |
|
389
|
|
|
s.exports = require('./exports'); |
|
390
|
|
|
s.escapeRegExp = require('./helper/escapeRegExp'); |
|
391
|
|
|
s.wrap = require('./wrap'); |
|
392
|
|
|
s.map = require('./map'); |
|
393
|
|
|
|
|
394
|
|
|
// Aliases |
|
395
|
|
|
s.strip = s.trim; |
|
396
|
|
|
s.lstrip = s.ltrim; |
|
397
|
|
|
s.rstrip = s.rtrim; |
|
398
|
|
|
s.center = s.lrpad; |
|
399
|
|
|
s.rjust = s.lpad; |
|
400
|
|
|
s.ljust = s.rpad; |
|
401
|
|
|
s.contains = s.include; |
|
402
|
|
|
s.q = s.quote; |
|
403
|
|
|
s.toBool = s.toBoolean; |
|
404
|
|
|
s.camelcase = s.camelize; |
|
405
|
|
|
s.mapChars = s.map; |
|
406
|
|
|
|
|
407
|
|
|
|
|
408
|
|
|
// Implement chaining |
|
409
|
|
|
s.prototype = { |
|
410
|
|
|
value: function value() { |
|
411
|
|
|
return this._wrapped; |
|
412
|
|
|
} |
|
413
|
|
|
}; |
|
414
|
|
|
|
|
415
|
|
|
function fn2method(key, fn) { |
|
416
|
|
|
if (typeof fn !== 'function') return; |
|
417
|
|
|
s.prototype[key] = function() { |
|
418
|
|
|
var args = [this._wrapped].concat(Array.prototype.slice.call(arguments)); |
|
419
|
|
|
var res = fn.apply(null, args); |
|
420
|
|
|
// if the result is non-string stop the chain and return the value |
|
421
|
|
|
return typeof res === 'string' ? new s(res) : res; |
|
|
|
|
|
|
422
|
|
|
}; |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
// Copy functions to instance methods for chaining |
|
426
|
|
|
for (var key in s) fn2method(key, s[key]); |
|
|
|
|
|
|
427
|
|
|
|
|
428
|
|
|
fn2method('tap', function tap(string, fn) { |
|
429
|
|
|
return fn(string); |
|
430
|
|
|
}); |
|
431
|
|
|
|
|
432
|
|
|
function prototype2method(methodName) { |
|
433
|
|
|
fn2method(methodName, function(context) { |
|
434
|
|
|
var args = Array.prototype.slice.call(arguments, 1); |
|
435
|
|
|
return String.prototype[methodName].apply(context, args); |
|
436
|
|
|
}); |
|
437
|
|
|
} |
|
438
|
|
|
|
|
439
|
|
|
var prototypeMethods = [ |
|
440
|
|
|
'toUpperCase', |
|
441
|
|
|
'toLowerCase', |
|
442
|
|
|
'split', |
|
443
|
|
|
'replace', |
|
444
|
|
|
'slice', |
|
445
|
|
|
'substring', |
|
446
|
|
|
'substr', |
|
447
|
|
|
'concat' |
|
448
|
|
|
]; |
|
449
|
|
|
|
|
450
|
|
|
for (var method in prototypeMethods) prototype2method(prototypeMethods[method]); |
|
|
|
|
|
|
451
|
|
|
|
|
452
|
|
|
|
|
453
|
|
|
module.exports = s; |
|
454
|
|
|
|
|
455
|
|
|
},{"./camelize":1,"./capitalize":2,"./chars":3,"./chop":4,"./classify":5,"./clean":6,"./cleanDiacritics":7,"./count":8,"./dasherize":9,"./decapitalize":10,"./dedent":11,"./endsWith":12,"./escapeHTML":13,"./exports":14,"./helper/escapeRegExp":18,"./humanize":23,"./include":24,"./insert":26,"./isBlank":27,"./join":28,"./levenshtein":29,"./lines":30,"./lpad":31,"./lrpad":32,"./ltrim":33,"./map":34,"./naturalCmp":35,"./numberFormat":38,"./pad":39,"./pred":40,"./prune":41,"./quote":42,"./repeat":43,"./replaceAll":44,"./reverse":45,"./rpad":46,"./rtrim":47,"./slugify":48,"./splice":49,"./sprintf":50,"./startsWith":51,"./strLeft":52,"./strLeftBack":53,"./strRight":54,"./strRightBack":55,"./stripTags":56,"./succ":57,"./surround":58,"./swapCase":59,"./titleize":60,"./toBoolean":61,"./toNumber":62,"./toSentence":63,"./toSentenceSerial":64,"./trim":65,"./truncate":66,"./underscored":67,"./unescapeHTML":68,"./unquote":69,"./vsprintf":70,"./words":71,"./wrap":72}],26:[function(require,module,exports){ |
|
456
|
|
|
var splice = require('./splice'); |
|
457
|
|
|
|
|
458
|
|
|
module.exports = function insert(str, i, substr) { |
|
459
|
|
|
return splice(str, i, 0, substr); |
|
460
|
|
|
}; |
|
461
|
|
|
|
|
462
|
|
|
},{"./splice":49}],27:[function(require,module,exports){ |
|
463
|
|
|
var makeString = require('./helper/makeString'); |
|
464
|
|
|
|
|
465
|
|
|
module.exports = function isBlank(str) { |
|
466
|
|
|
return (/^\s*$/).test(makeString(str)); |
|
467
|
|
|
}; |
|
468
|
|
|
|
|
469
|
|
|
},{"./helper/makeString":20}],28:[function(require,module,exports){ |
|
470
|
|
|
var makeString = require('./helper/makeString'); |
|
471
|
|
|
var slice = [].slice; |
|
472
|
|
|
|
|
473
|
|
|
module.exports = function join() { |
|
474
|
|
|
var args = slice.call(arguments), |
|
475
|
|
|
separator = args.shift(); |
|
476
|
|
|
|
|
477
|
|
|
return args.join(makeString(separator)); |
|
478
|
|
|
}; |
|
479
|
|
|
|
|
480
|
|
|
},{"./helper/makeString":20}],29:[function(require,module,exports){ |
|
481
|
|
|
var makeString = require('./helper/makeString'); |
|
482
|
|
|
|
|
483
|
|
|
/** |
|
484
|
|
|
* Based on the implementation here: https://github.com/hiddentao/fast-levenshtein |
|
485
|
|
|
*/ |
|
486
|
|
|
module.exports = function levenshtein(str1, str2) { |
|
487
|
|
|
'use strict'; |
|
488
|
|
|
str1 = makeString(str1); |
|
489
|
|
|
str2 = makeString(str2); |
|
490
|
|
|
|
|
491
|
|
|
// Short cut cases |
|
492
|
|
|
if (str1 === str2) return 0; |
|
493
|
|
|
if (!str1 || !str2) return Math.max(str1.length, str2.length); |
|
494
|
|
|
|
|
495
|
|
|
// two rows |
|
496
|
|
|
var prevRow = new Array(str2.length + 1); |
|
497
|
|
|
|
|
498
|
|
|
// initialise previous row |
|
499
|
|
|
for (var i = 0; i < prevRow.length; ++i) { |
|
500
|
|
|
prevRow[i] = i; |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
// calculate current row distance from previous row |
|
504
|
|
|
for (i = 0; i < str1.length; ++i) { |
|
505
|
|
|
var nextCol = i + 1; |
|
506
|
|
|
|
|
507
|
|
|
for (var j = 0; j < str2.length; ++j) { |
|
508
|
|
|
var curCol = nextCol; |
|
509
|
|
|
|
|
510
|
|
|
// substution |
|
511
|
|
|
nextCol = prevRow[j] + ( (str1.charAt(i) === str2.charAt(j)) ? 0 : 1 ); |
|
512
|
|
|
// insertion |
|
513
|
|
|
var tmp = curCol + 1; |
|
514
|
|
|
if (nextCol > tmp) { |
|
515
|
|
|
nextCol = tmp; |
|
516
|
|
|
} |
|
517
|
|
|
// deletion |
|
518
|
|
|
tmp = prevRow[j + 1] + 1; |
|
519
|
|
|
if (nextCol > tmp) { |
|
520
|
|
|
nextCol = tmp; |
|
521
|
|
|
} |
|
522
|
|
|
|
|
523
|
|
|
// copy current col value into previous (in preparation for next iteration) |
|
524
|
|
|
prevRow[j] = curCol; |
|
525
|
|
|
} |
|
526
|
|
|
|
|
527
|
|
|
// copy last col value into previous (in preparation for next iteration) |
|
528
|
|
|
prevRow[j] = nextCol; |
|
529
|
|
|
} |
|
530
|
|
|
|
|
531
|
|
|
return nextCol; |
|
|
|
|
|
|
532
|
|
|
}; |
|
533
|
|
|
|
|
534
|
|
|
},{"./helper/makeString":20}],30:[function(require,module,exports){ |
|
535
|
|
|
module.exports = function lines(str) { |
|
536
|
|
|
if (str == null) return []; |
|
537
|
|
|
return String(str).split(/\r\n?|\n/); |
|
538
|
|
|
}; |
|
539
|
|
|
|
|
540
|
|
|
},{}],31:[function(require,module,exports){ |
|
541
|
|
|
var pad = require('./pad'); |
|
542
|
|
|
|
|
543
|
|
|
module.exports = function lpad(str, length, padStr) { |
|
544
|
|
|
return pad(str, length, padStr); |
|
545
|
|
|
}; |
|
546
|
|
|
|
|
547
|
|
|
},{"./pad":39}],32:[function(require,module,exports){ |
|
548
|
|
|
var pad = require('./pad'); |
|
549
|
|
|
|
|
550
|
|
|
module.exports = function lrpad(str, length, padStr) { |
|
551
|
|
|
return pad(str, length, padStr, 'both'); |
|
552
|
|
|
}; |
|
553
|
|
|
|
|
554
|
|
|
},{"./pad":39}],33:[function(require,module,exports){ |
|
555
|
|
|
var makeString = require('./helper/makeString'); |
|
556
|
|
|
var defaultToWhiteSpace = require('./helper/defaultToWhiteSpace'); |
|
557
|
|
|
var nativeTrimLeft = String.prototype.trimLeft; |
|
558
|
|
|
|
|
559
|
|
|
module.exports = function ltrim(str, characters) { |
|
560
|
|
|
str = makeString(str); |
|
561
|
|
|
if (!characters && nativeTrimLeft) return nativeTrimLeft.call(str); |
|
562
|
|
|
characters = defaultToWhiteSpace(characters); |
|
563
|
|
|
return str.replace(new RegExp('^' + characters + '+'), ''); |
|
564
|
|
|
}; |
|
565
|
|
|
|
|
566
|
|
|
},{"./helper/defaultToWhiteSpace":16,"./helper/makeString":20}],34:[function(require,module,exports){ |
|
567
|
|
|
var makeString = require('./helper/makeString'); |
|
568
|
|
|
|
|
569
|
|
|
module.exports = function(str, callback) { |
|
570
|
|
|
str = makeString(str); |
|
571
|
|
|
|
|
572
|
|
|
if (str.length === 0 || typeof callback !== 'function') return str; |
|
573
|
|
|
|
|
574
|
|
|
return str.replace(/./g, callback); |
|
575
|
|
|
}; |
|
576
|
|
|
|
|
577
|
|
|
},{"./helper/makeString":20}],35:[function(require,module,exports){ |
|
578
|
|
|
module.exports = function naturalCmp(str1, str2) { |
|
579
|
|
|
if (str1 == str2) return 0; |
|
580
|
|
|
if (!str1) return -1; |
|
581
|
|
|
if (!str2) return 1; |
|
582
|
|
|
|
|
583
|
|
|
var cmpRegex = /(\.\d+|\d+|\D+)/g, |
|
584
|
|
|
tokens1 = String(str1).match(cmpRegex), |
|
585
|
|
|
tokens2 = String(str2).match(cmpRegex), |
|
586
|
|
|
count = Math.min(tokens1.length, tokens2.length); |
|
587
|
|
|
|
|
588
|
|
|
for (var i = 0; i < count; i++) { |
|
589
|
|
|
var a = tokens1[i], |
|
590
|
|
|
b = tokens2[i]; |
|
591
|
|
|
|
|
592
|
|
|
if (a !== b) { |
|
593
|
|
|
var num1 = +a; |
|
594
|
|
|
var num2 = +b; |
|
595
|
|
|
if (num1 === num1 && num2 === num2) { |
|
596
|
|
|
return num1 > num2 ? 1 : -1; |
|
597
|
|
|
} |
|
598
|
|
|
return a < b ? -1 : 1; |
|
599
|
|
|
} |
|
600
|
|
|
} |
|
601
|
|
|
|
|
602
|
|
|
if (tokens1.length != tokens2.length) |
|
603
|
|
|
return tokens1.length - tokens2.length; |
|
604
|
|
|
|
|
605
|
|
|
return str1 < str2 ? -1 : 1; |
|
606
|
|
|
}; |
|
607
|
|
|
|
|
608
|
|
|
},{}],36:[function(require,module,exports){ |
|
609
|
|
|
(function(window) { |
|
610
|
|
|
var re = { |
|
611
|
|
|
not_string: /[^s]/, |
|
612
|
|
|
number: /[diefg]/, |
|
613
|
|
|
json: /[j]/, |
|
614
|
|
|
not_json: /[^j]/, |
|
615
|
|
|
text: /^[^\x25]+/, |
|
616
|
|
|
modulo: /^\x25{2}/, |
|
617
|
|
|
placeholder: /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijosuxX])/, |
|
618
|
|
|
key: /^([a-z_][a-z_\d]*)/i, |
|
619
|
|
|
key_access: /^\.([a-z_][a-z_\d]*)/i, |
|
620
|
|
|
index_access: /^\[(\d+)\]/, |
|
621
|
|
|
sign: /^[\+\-]/ |
|
622
|
|
|
} |
|
623
|
|
|
|
|
624
|
|
|
function sprintf() { |
|
625
|
|
|
var key = arguments[0], cache = sprintf.cache |
|
626
|
|
|
if (!(cache[key] && cache.hasOwnProperty(key))) { |
|
627
|
|
|
cache[key] = sprintf.parse(key) |
|
628
|
|
|
} |
|
629
|
|
|
return sprintf.format.call(null, cache[key], arguments) |
|
630
|
|
|
} |
|
631
|
|
|
|
|
632
|
|
|
sprintf.format = function(parse_tree, argv) { |
|
633
|
|
|
var cursor = 1, tree_length = parse_tree.length, node_type = "", arg, output = [], i, k, match, pad, pad_character, pad_length, is_positive = true, sign = "" |
|
634
|
|
|
for (i = 0; i < tree_length; i++) { |
|
635
|
|
|
node_type = get_type(parse_tree[i]) |
|
636
|
|
|
if (node_type === "string") { |
|
637
|
|
|
output[output.length] = parse_tree[i] |
|
638
|
|
|
} |
|
639
|
|
|
else if (node_type === "array") { |
|
640
|
|
|
match = parse_tree[i] // convenience purposes only |
|
641
|
|
|
if (match[2]) { // keyword argument |
|
642
|
|
|
arg = argv[cursor] |
|
643
|
|
|
for (k = 0; k < match[2].length; k++) { |
|
644
|
|
|
if (!arg.hasOwnProperty(match[2][k])) { |
|
645
|
|
|
throw new Error(sprintf("[sprintf] property '%s' does not exist", match[2][k])) |
|
646
|
|
|
} |
|
647
|
|
|
arg = arg[match[2][k]] |
|
648
|
|
|
} |
|
649
|
|
|
} |
|
650
|
|
|
else if (match[1]) { // positional argument (explicit) |
|
651
|
|
|
arg = argv[match[1]] |
|
652
|
|
|
} |
|
653
|
|
|
else { // positional argument (implicit) |
|
654
|
|
|
arg = argv[cursor++] |
|
655
|
|
|
} |
|
656
|
|
|
|
|
657
|
|
|
if (get_type(arg) == "function") { |
|
658
|
|
|
arg = arg() |
|
659
|
|
|
} |
|
660
|
|
|
|
|
661
|
|
|
if (re.not_string.test(match[8]) && re.not_json.test(match[8]) && (get_type(arg) != "number" && isNaN(arg))) { |
|
662
|
|
|
throw new TypeError(sprintf("[sprintf] expecting number but found %s", get_type(arg))) |
|
663
|
|
|
} |
|
664
|
|
|
|
|
665
|
|
|
if (re.number.test(match[8])) { |
|
666
|
|
|
is_positive = arg >= 0 |
|
667
|
|
|
} |
|
668
|
|
|
|
|
669
|
|
|
switch (match[8]) { |
|
|
|
|
|
|
670
|
|
|
case "b": |
|
671
|
|
|
arg = arg.toString(2) |
|
672
|
|
|
break |
|
673
|
|
|
case "c": |
|
674
|
|
|
arg = String.fromCharCode(arg) |
|
675
|
|
|
break |
|
676
|
|
|
case "d": |
|
677
|
|
|
case "i": |
|
678
|
|
|
arg = parseInt(arg, 10) |
|
679
|
|
|
break |
|
680
|
|
|
case "j": |
|
681
|
|
|
arg = JSON.stringify(arg, null, match[6] ? parseInt(match[6]) : 0) |
|
682
|
|
|
break |
|
683
|
|
|
case "e": |
|
684
|
|
|
arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential() |
|
685
|
|
|
break |
|
686
|
|
|
case "f": |
|
687
|
|
|
arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg) |
|
688
|
|
|
break |
|
689
|
|
|
case "g": |
|
690
|
|
|
arg = match[7] ? parseFloat(arg).toPrecision(match[7]) : parseFloat(arg) |
|
691
|
|
|
break |
|
692
|
|
|
case "o": |
|
693
|
|
|
arg = arg.toString(8) |
|
694
|
|
|
break |
|
695
|
|
|
case "s": |
|
696
|
|
|
arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg) |
|
697
|
|
|
break |
|
698
|
|
|
case "u": |
|
699
|
|
|
arg = arg >>> 0 |
|
700
|
|
|
break |
|
701
|
|
|
case "x": |
|
702
|
|
|
arg = arg.toString(16) |
|
703
|
|
|
break |
|
704
|
|
|
case "X": |
|
705
|
|
|
arg = arg.toString(16).toUpperCase() |
|
706
|
|
|
break |
|
707
|
|
|
} |
|
708
|
|
|
if (re.json.test(match[8])) { |
|
709
|
|
|
output[output.length] = arg |
|
710
|
|
|
} |
|
711
|
|
|
else { |
|
712
|
|
|
if (re.number.test(match[8]) && (!is_positive || match[3])) { |
|
713
|
|
|
sign = is_positive ? "+" : "-" |
|
714
|
|
|
arg = arg.toString().replace(re.sign, "") |
|
715
|
|
|
} |
|
716
|
|
|
else { |
|
717
|
|
|
sign = "" |
|
718
|
|
|
} |
|
719
|
|
|
pad_character = match[4] ? match[4] === "0" ? "0" : match[4].charAt(1) : " " |
|
720
|
|
|
pad_length = match[6] - (sign + arg).length |
|
721
|
|
|
pad = match[6] ? (pad_length > 0 ? str_repeat(pad_character, pad_length) : "") : "" |
|
722
|
|
|
output[output.length] = match[5] ? sign + arg + pad : (pad_character === "0" ? sign + pad + arg : pad + sign + arg) |
|
723
|
|
|
} |
|
724
|
|
|
} |
|
725
|
|
|
} |
|
726
|
|
|
return output.join("") |
|
727
|
|
|
} |
|
728
|
|
|
|
|
729
|
|
|
sprintf.cache = {} |
|
730
|
|
|
|
|
731
|
|
|
sprintf.parse = function(fmt) { |
|
732
|
|
|
var _fmt = fmt, match = [], parse_tree = [], arg_names = 0 |
|
|
|
|
|
|
733
|
|
|
while (_fmt) { |
|
734
|
|
|
if ((match = re.text.exec(_fmt)) !== null) { |
|
735
|
|
|
parse_tree[parse_tree.length] = match[0] |
|
736
|
|
|
} |
|
737
|
|
|
else if ((match = re.modulo.exec(_fmt)) !== null) { |
|
738
|
|
|
parse_tree[parse_tree.length] = "%" |
|
739
|
|
|
} |
|
740
|
|
|
else if ((match = re.placeholder.exec(_fmt)) !== null) { |
|
741
|
|
|
if (match[2]) { |
|
742
|
|
|
arg_names |= 1 |
|
743
|
|
|
var field_list = [], replacement_field = match[2], field_match = [] |
|
|
|
|
|
|
744
|
|
|
if ((field_match = re.key.exec(replacement_field)) !== null) { |
|
745
|
|
|
field_list[field_list.length] = field_match[1] |
|
746
|
|
|
while ((replacement_field = replacement_field.substring(field_match[0].length)) !== "") { |
|
747
|
|
|
if ((field_match = re.key_access.exec(replacement_field)) !== null) { |
|
748
|
|
|
field_list[field_list.length] = field_match[1] |
|
749
|
|
|
} |
|
750
|
|
|
else if ((field_match = re.index_access.exec(replacement_field)) !== null) { |
|
751
|
|
|
field_list[field_list.length] = field_match[1] |
|
752
|
|
|
} |
|
753
|
|
|
else { |
|
754
|
|
|
throw new SyntaxError("[sprintf] failed to parse named argument key") |
|
755
|
|
|
} |
|
756
|
|
|
} |
|
757
|
|
|
} |
|
758
|
|
|
else { |
|
759
|
|
|
throw new SyntaxError("[sprintf] failed to parse named argument key") |
|
760
|
|
|
} |
|
761
|
|
|
match[2] = field_list |
|
762
|
|
|
} |
|
763
|
|
|
else { |
|
764
|
|
|
arg_names |= 2 |
|
765
|
|
|
} |
|
766
|
|
|
if (arg_names === 3) { |
|
767
|
|
|
throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported") |
|
768
|
|
|
} |
|
769
|
|
|
parse_tree[parse_tree.length] = match |
|
770
|
|
|
} |
|
771
|
|
|
else { |
|
772
|
|
|
throw new SyntaxError("[sprintf] unexpected placeholder") |
|
773
|
|
|
} |
|
774
|
|
|
_fmt = _fmt.substring(match[0].length) |
|
775
|
|
|
} |
|
776
|
|
|
return parse_tree |
|
777
|
|
|
} |
|
778
|
|
|
|
|
779
|
|
|
var vsprintf = function(fmt, argv, _argv) { |
|
780
|
|
|
_argv = (argv || []).slice(0) |
|
781
|
|
|
_argv.splice(0, 0, fmt) |
|
782
|
|
|
return sprintf.apply(null, _argv) |
|
783
|
|
|
} |
|
784
|
|
|
|
|
785
|
|
|
/** |
|
786
|
|
|
* helpers |
|
787
|
|
|
*/ |
|
788
|
|
|
function get_type(variable) { |
|
789
|
|
|
return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase() |
|
790
|
|
|
} |
|
791
|
|
|
|
|
792
|
|
|
function str_repeat(input, multiplier) { |
|
793
|
|
|
return Array(multiplier + 1).join(input) |
|
794
|
|
|
} |
|
795
|
|
|
|
|
796
|
|
|
/** |
|
797
|
|
|
* export to either browser or node.js |
|
798
|
|
|
*/ |
|
799
|
|
|
if (typeof exports !== "undefined") { |
|
800
|
|
|
exports.sprintf = sprintf |
|
801
|
|
|
exports.vsprintf = vsprintf |
|
802
|
|
|
} |
|
803
|
|
|
else { |
|
804
|
|
|
window.sprintf = sprintf |
|
805
|
|
|
window.vsprintf = vsprintf |
|
806
|
|
|
|
|
807
|
|
|
if (typeof define === "function" && define.amd) { |
|
|
|
|
|
|
808
|
|
|
define(function() { |
|
809
|
|
|
return { |
|
810
|
|
|
sprintf: sprintf, |
|
811
|
|
|
vsprintf: vsprintf |
|
812
|
|
|
} |
|
813
|
|
|
}) |
|
814
|
|
|
} |
|
815
|
|
|
} |
|
816
|
|
|
})(typeof window === "undefined" ? this : window); |
|
817
|
|
|
|
|
818
|
|
|
},{}],37:[function(require,module,exports){ |
|
819
|
|
|
(function (global){ |
|
820
|
|
|
|
|
821
|
|
|
/** |
|
822
|
|
|
* Module exports. |
|
823
|
|
|
*/ |
|
824
|
|
|
|
|
825
|
|
|
module.exports = deprecate; |
|
826
|
|
|
|
|
827
|
|
|
/** |
|
828
|
|
|
* Mark that a method should not be used. |
|
829
|
|
|
* Returns a modified function which warns once by default. |
|
830
|
|
|
* |
|
831
|
|
|
* If `localStorage.noDeprecation = true` is set, then it is a no-op. |
|
832
|
|
|
* |
|
833
|
|
|
* If `localStorage.throwDeprecation = true` is set, then deprecated functions |
|
834
|
|
|
* will throw an Error when invoked. |
|
835
|
|
|
* |
|
836
|
|
|
* If `localStorage.traceDeprecation = true` is set, then deprecated functions |
|
837
|
|
|
* will invoke `console.trace()` instead of `console.error()`. |
|
838
|
|
|
* |
|
839
|
|
|
* @param {Function} fn - the function to deprecate |
|
840
|
|
|
* @param {String} msg - the string to print to the console when `fn` is invoked |
|
841
|
|
|
* @returns {Function} a new "deprecated" version of `fn` |
|
842
|
|
|
* @api public |
|
843
|
|
|
*/ |
|
844
|
|
|
|
|
845
|
|
|
function deprecate (fn, msg) { |
|
846
|
|
|
if (config('noDeprecation')) { |
|
847
|
|
|
return fn; |
|
848
|
|
|
} |
|
849
|
|
|
|
|
850
|
|
|
var warned = false; |
|
851
|
|
|
function deprecated() { |
|
852
|
|
|
if (!warned) { |
|
853
|
|
|
if (config('throwDeprecation')) { |
|
854
|
|
|
throw new Error(msg); |
|
855
|
|
|
} else if (config('traceDeprecation')) { |
|
856
|
|
|
console.trace(msg); |
|
857
|
|
|
} else { |
|
858
|
|
|
console.warn(msg); |
|
859
|
|
|
} |
|
860
|
|
|
warned = true; |
|
861
|
|
|
} |
|
862
|
|
|
return fn.apply(this, arguments); |
|
863
|
|
|
} |
|
864
|
|
|
|
|
865
|
|
|
return deprecated; |
|
866
|
|
|
} |
|
867
|
|
|
|
|
868
|
|
|
/** |
|
869
|
|
|
* Checks `localStorage` for boolean values for the given `name`. |
|
870
|
|
|
* |
|
871
|
|
|
* @param {String} name |
|
872
|
|
|
* @returns {Boolean} |
|
873
|
|
|
* @api private |
|
874
|
|
|
*/ |
|
875
|
|
|
|
|
876
|
|
|
function config (name) { |
|
877
|
|
|
// accessing global.localStorage can trigger a DOMException in sandboxed iframes |
|
878
|
|
|
try { |
|
879
|
|
|
if (!global.localStorage) return false; |
|
880
|
|
|
} catch (_) { |
|
881
|
|
|
return false; |
|
882
|
|
|
} |
|
883
|
|
|
var val = global.localStorage[name]; |
|
884
|
|
|
if (null == val) return false; |
|
885
|
|
|
return String(val).toLowerCase() === 'true'; |
|
886
|
|
|
} |
|
887
|
|
|
|
|
888
|
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) |
|
|
|
|
|
|
889
|
|
|
},{}],38:[function(require,module,exports){ |
|
890
|
|
|
module.exports = function numberFormat(number, dec, dsep, tsep) { |
|
891
|
|
|
if (isNaN(number) || number == null) return ''; |
|
892
|
|
|
|
|
893
|
|
|
number = number.toFixed(~~dec); |
|
894
|
|
|
tsep = typeof tsep == 'string' ? tsep : ','; |
|
895
|
|
|
|
|
896
|
|
|
var parts = number.split('.'), |
|
897
|
|
|
fnums = parts[0], |
|
898
|
|
|
decimals = parts[1] ? (dsep || '.') + parts[1] : ''; |
|
899
|
|
|
|
|
900
|
|
|
return fnums.replace(/(\d)(?=(?:\d{3})+$)/g, '$1' + tsep) + decimals; |
|
901
|
|
|
}; |
|
902
|
|
|
|
|
903
|
|
|
},{}],39:[function(require,module,exports){ |
|
904
|
|
|
var makeString = require('./helper/makeString'); |
|
905
|
|
|
var strRepeat = require('./helper/strRepeat'); |
|
906
|
|
|
|
|
907
|
|
|
module.exports = function pad(str, length, padStr, type) { |
|
908
|
|
|
str = makeString(str); |
|
909
|
|
|
length = ~~length; |
|
910
|
|
|
|
|
911
|
|
|
var padlen = 0; |
|
912
|
|
|
|
|
913
|
|
|
if (!padStr) |
|
914
|
|
|
padStr = ' '; |
|
915
|
|
|
else if (padStr.length > 1) |
|
916
|
|
|
padStr = padStr.charAt(0); |
|
917
|
|
|
|
|
918
|
|
|
switch (type) { |
|
919
|
|
|
case 'right': |
|
920
|
|
|
padlen = length - str.length; |
|
921
|
|
|
return str + strRepeat(padStr, padlen); |
|
922
|
|
|
case 'both': |
|
923
|
|
|
padlen = length - str.length; |
|
924
|
|
|
return strRepeat(padStr, Math.ceil(padlen / 2)) + str + strRepeat(padStr, Math.floor(padlen / 2)); |
|
925
|
|
|
default: // 'left' |
|
926
|
|
|
padlen = length - str.length; |
|
927
|
|
|
return strRepeat(padStr, padlen) + str; |
|
928
|
|
|
} |
|
929
|
|
|
}; |
|
930
|
|
|
|
|
931
|
|
|
},{"./helper/makeString":20,"./helper/strRepeat":21}],40:[function(require,module,exports){ |
|
932
|
|
|
var adjacent = require('./helper/adjacent'); |
|
933
|
|
|
|
|
934
|
|
|
module.exports = function succ(str) { |
|
935
|
|
|
return adjacent(str, -1); |
|
936
|
|
|
}; |
|
937
|
|
|
|
|
938
|
|
|
},{"./helper/adjacent":15}],41:[function(require,module,exports){ |
|
939
|
|
|
/** |
|
940
|
|
|
* _s.prune: a more elegant version of truncate |
|
941
|
|
|
* prune extra chars, never leaving a half-chopped word. |
|
942
|
|
|
* @author github.com/rwz |
|
943
|
|
|
*/ |
|
944
|
|
|
var makeString = require('./helper/makeString'); |
|
945
|
|
|
var rtrim = require('./rtrim'); |
|
946
|
|
|
|
|
947
|
|
|
module.exports = function prune(str, length, pruneStr) { |
|
948
|
|
|
str = makeString(str); |
|
949
|
|
|
length = ~~length; |
|
950
|
|
|
pruneStr = pruneStr != null ? String(pruneStr) : '...'; |
|
951
|
|
|
|
|
952
|
|
|
if (str.length <= length) return str; |
|
953
|
|
|
|
|
954
|
|
|
var tmpl = function(c) { |
|
955
|
|
|
return c.toUpperCase() !== c.toLowerCase() ? 'A' : ' '; |
|
956
|
|
|
}, |
|
957
|
|
|
template = str.slice(0, length + 1).replace(/.(?=\W*\w*$)/g, tmpl); // 'Hello, world' -> 'HellAA AAAAA' |
|
958
|
|
|
|
|
959
|
|
|
if (template.slice(template.length - 2).match(/\w\w/)) |
|
960
|
|
|
template = template.replace(/\s*\S+$/, ''); |
|
961
|
|
|
else |
|
962
|
|
|
template = rtrim(template.slice(0, template.length - 1)); |
|
963
|
|
|
|
|
964
|
|
|
return (template + pruneStr).length > str.length ? str : str.slice(0, template.length) + pruneStr; |
|
965
|
|
|
}; |
|
966
|
|
|
|
|
967
|
|
|
},{"./helper/makeString":20,"./rtrim":47}],42:[function(require,module,exports){ |
|
968
|
|
|
var surround = require('./surround'); |
|
969
|
|
|
|
|
970
|
|
|
module.exports = function quote(str, quoteChar) { |
|
971
|
|
|
return surround(str, quoteChar || '"'); |
|
972
|
|
|
}; |
|
973
|
|
|
|
|
974
|
|
|
},{"./surround":58}],43:[function(require,module,exports){ |
|
975
|
|
|
var makeString = require('./helper/makeString'); |
|
976
|
|
|
var strRepeat = require('./helper/strRepeat'); |
|
977
|
|
|
|
|
978
|
|
|
module.exports = function repeat(str, qty, separator) { |
|
979
|
|
|
str = makeString(str); |
|
980
|
|
|
|
|
981
|
|
|
qty = ~~qty; |
|
982
|
|
|
|
|
983
|
|
|
// using faster implementation if separator is not needed; |
|
984
|
|
|
if (separator == null) return strRepeat(str, qty); |
|
985
|
|
|
|
|
986
|
|
|
// this one is about 300x slower in Google Chrome |
|
987
|
|
|
/*eslint no-empty: 0*/ |
|
988
|
|
|
for (var repeat = []; qty > 0; repeat[--qty] = str) {} |
|
|
|
|
|
|
989
|
|
|
return repeat.join(separator); |
|
990
|
|
|
}; |
|
991
|
|
|
|
|
992
|
|
|
},{"./helper/makeString":20,"./helper/strRepeat":21}],44:[function(require,module,exports){ |
|
993
|
|
|
var makeString = require('./helper/makeString'); |
|
994
|
|
|
|
|
995
|
|
|
module.exports = function replaceAll(str, find, replace, ignorecase) { |
|
996
|
|
|
var flags = (ignorecase === true)?'gi':'g'; |
|
997
|
|
|
var reg = new RegExp(find, flags); |
|
998
|
|
|
|
|
999
|
|
|
return makeString(str).replace(reg, replace); |
|
1000
|
|
|
}; |
|
1001
|
|
|
|
|
1002
|
|
|
},{"./helper/makeString":20}],45:[function(require,module,exports){ |
|
1003
|
|
|
var chars = require('./chars'); |
|
1004
|
|
|
|
|
1005
|
|
|
module.exports = function reverse(str) { |
|
1006
|
|
|
return chars(str).reverse().join(''); |
|
1007
|
|
|
}; |
|
1008
|
|
|
|
|
1009
|
|
|
},{"./chars":3}],46:[function(require,module,exports){ |
|
1010
|
|
|
var pad = require('./pad'); |
|
1011
|
|
|
|
|
1012
|
|
|
module.exports = function rpad(str, length, padStr) { |
|
1013
|
|
|
return pad(str, length, padStr, 'right'); |
|
1014
|
|
|
}; |
|
1015
|
|
|
|
|
1016
|
|
|
},{"./pad":39}],47:[function(require,module,exports){ |
|
1017
|
|
|
var makeString = require('./helper/makeString'); |
|
1018
|
|
|
var defaultToWhiteSpace = require('./helper/defaultToWhiteSpace'); |
|
1019
|
|
|
var nativeTrimRight = String.prototype.trimRight; |
|
1020
|
|
|
|
|
1021
|
|
|
module.exports = function rtrim(str, characters) { |
|
1022
|
|
|
str = makeString(str); |
|
1023
|
|
|
if (!characters && nativeTrimRight) return nativeTrimRight.call(str); |
|
1024
|
|
|
characters = defaultToWhiteSpace(characters); |
|
1025
|
|
|
return str.replace(new RegExp(characters + '+$'), ''); |
|
1026
|
|
|
}; |
|
1027
|
|
|
|
|
1028
|
|
|
},{"./helper/defaultToWhiteSpace":16,"./helper/makeString":20}],48:[function(require,module,exports){ |
|
1029
|
|
|
var trim = require('./trim'); |
|
1030
|
|
|
var dasherize = require('./dasherize'); |
|
1031
|
|
|
var cleanDiacritics = require('./cleanDiacritics'); |
|
1032
|
|
|
|
|
1033
|
|
|
module.exports = function slugify(str) { |
|
1034
|
|
|
return trim(dasherize(cleanDiacritics(str).replace(/[^\w\s-]/g, '-').toLowerCase()), '-'); |
|
1035
|
|
|
}; |
|
1036
|
|
|
|
|
1037
|
|
|
},{"./cleanDiacritics":7,"./dasherize":9,"./trim":65}],49:[function(require,module,exports){ |
|
1038
|
|
|
var chars = require('./chars'); |
|
1039
|
|
|
|
|
1040
|
|
|
module.exports = function splice(str, i, howmany, substr) { |
|
1041
|
|
|
var arr = chars(str); |
|
1042
|
|
|
arr.splice(~~i, ~~howmany, substr); |
|
1043
|
|
|
return arr.join(''); |
|
1044
|
|
|
}; |
|
1045
|
|
|
|
|
1046
|
|
|
},{"./chars":3}],50:[function(require,module,exports){ |
|
1047
|
|
|
var deprecate = require('util-deprecate'); |
|
1048
|
|
|
|
|
1049
|
|
|
module.exports = deprecate(require('sprintf-js').sprintf, |
|
1050
|
|
|
'sprintf() will be removed in the next major release, use the sprintf-js package instead.'); |
|
1051
|
|
|
|
|
1052
|
|
|
},{"sprintf-js":36,"util-deprecate":37}],51:[function(require,module,exports){ |
|
1053
|
|
|
var makeString = require('./helper/makeString'); |
|
1054
|
|
|
var toPositive = require('./helper/toPositive'); |
|
1055
|
|
|
|
|
1056
|
|
|
module.exports = function startsWith(str, starts, position) { |
|
1057
|
|
|
str = makeString(str); |
|
1058
|
|
|
starts = '' + starts; |
|
1059
|
|
|
position = position == null ? 0 : Math.min(toPositive(position), str.length); |
|
1060
|
|
|
return str.lastIndexOf(starts, position) === position; |
|
1061
|
|
|
}; |
|
1062
|
|
|
|
|
1063
|
|
|
},{"./helper/makeString":20,"./helper/toPositive":22}],52:[function(require,module,exports){ |
|
1064
|
|
|
var makeString = require('./helper/makeString'); |
|
1065
|
|
|
|
|
1066
|
|
|
module.exports = function strLeft(str, sep) { |
|
1067
|
|
|
str = makeString(str); |
|
1068
|
|
|
sep = makeString(sep); |
|
1069
|
|
|
var pos = !sep ? -1 : str.indexOf(sep); |
|
1070
|
|
|
return~ pos ? str.slice(0, pos) : str; |
|
1071
|
|
|
}; |
|
1072
|
|
|
|
|
1073
|
|
|
},{"./helper/makeString":20}],53:[function(require,module,exports){ |
|
1074
|
|
|
var makeString = require('./helper/makeString'); |
|
1075
|
|
|
|
|
1076
|
|
|
module.exports = function strLeftBack(str, sep) { |
|
1077
|
|
|
str = makeString(str); |
|
1078
|
|
|
sep = makeString(sep); |
|
1079
|
|
|
var pos = str.lastIndexOf(sep); |
|
1080
|
|
|
return~ pos ? str.slice(0, pos) : str; |
|
1081
|
|
|
}; |
|
1082
|
|
|
|
|
1083
|
|
|
},{"./helper/makeString":20}],54:[function(require,module,exports){ |
|
1084
|
|
|
var makeString = require('./helper/makeString'); |
|
1085
|
|
|
|
|
1086
|
|
|
module.exports = function strRight(str, sep) { |
|
1087
|
|
|
str = makeString(str); |
|
1088
|
|
|
sep = makeString(sep); |
|
1089
|
|
|
var pos = !sep ? -1 : str.indexOf(sep); |
|
1090
|
|
|
return~ pos ? str.slice(pos + sep.length, str.length) : str; |
|
1091
|
|
|
}; |
|
1092
|
|
|
|
|
1093
|
|
|
},{"./helper/makeString":20}],55:[function(require,module,exports){ |
|
1094
|
|
|
var makeString = require('./helper/makeString'); |
|
1095
|
|
|
|
|
1096
|
|
|
module.exports = function strRightBack(str, sep) { |
|
1097
|
|
|
str = makeString(str); |
|
1098
|
|
|
sep = makeString(sep); |
|
1099
|
|
|
var pos = !sep ? -1 : str.lastIndexOf(sep); |
|
1100
|
|
|
return~ pos ? str.slice(pos + sep.length, str.length) : str; |
|
1101
|
|
|
}; |
|
1102
|
|
|
|
|
1103
|
|
|
},{"./helper/makeString":20}],56:[function(require,module,exports){ |
|
1104
|
|
|
var makeString = require('./helper/makeString'); |
|
1105
|
|
|
|
|
1106
|
|
|
module.exports = function stripTags(str) { |
|
1107
|
|
|
return makeString(str).replace(/<\/?[^>]+>/g, ''); |
|
1108
|
|
|
}; |
|
1109
|
|
|
|
|
1110
|
|
|
},{"./helper/makeString":20}],57:[function(require,module,exports){ |
|
1111
|
|
|
var adjacent = require('./helper/adjacent'); |
|
1112
|
|
|
|
|
1113
|
|
|
module.exports = function succ(str) { |
|
1114
|
|
|
return adjacent(str, 1); |
|
1115
|
|
|
}; |
|
1116
|
|
|
|
|
1117
|
|
|
},{"./helper/adjacent":15}],58:[function(require,module,exports){ |
|
1118
|
|
|
module.exports = function surround(str, wrapper) { |
|
1119
|
|
|
return [wrapper, str, wrapper].join(''); |
|
1120
|
|
|
}; |
|
1121
|
|
|
|
|
1122
|
|
|
},{}],59:[function(require,module,exports){ |
|
1123
|
|
|
var makeString = require('./helper/makeString'); |
|
1124
|
|
|
|
|
1125
|
|
|
module.exports = function swapCase(str) { |
|
1126
|
|
|
return makeString(str).replace(/\S/g, function(c) { |
|
1127
|
|
|
return c === c.toUpperCase() ? c.toLowerCase() : c.toUpperCase(); |
|
1128
|
|
|
}); |
|
1129
|
|
|
}; |
|
1130
|
|
|
|
|
1131
|
|
|
},{"./helper/makeString":20}],60:[function(require,module,exports){ |
|
1132
|
|
|
var makeString = require('./helper/makeString'); |
|
1133
|
|
|
|
|
1134
|
|
|
module.exports = function titleize(str) { |
|
1135
|
|
|
return makeString(str).toLowerCase().replace(/(?:^|\s|-)\S/g, function(c) { |
|
1136
|
|
|
return c.toUpperCase(); |
|
1137
|
|
|
}); |
|
1138
|
|
|
}; |
|
1139
|
|
|
|
|
1140
|
|
|
},{"./helper/makeString":20}],61:[function(require,module,exports){ |
|
1141
|
|
|
var trim = require('./trim'); |
|
1142
|
|
|
|
|
1143
|
|
|
function boolMatch(s, matchers) { |
|
1144
|
|
|
var i, matcher, down = s.toLowerCase(); |
|
1145
|
|
|
matchers = [].concat(matchers); |
|
1146
|
|
|
for (i = 0; i < matchers.length; i += 1) { |
|
1147
|
|
|
matcher = matchers[i]; |
|
1148
|
|
|
if (!matcher) continue; |
|
1149
|
|
|
if (matcher.test && matcher.test(s)) return true; |
|
1150
|
|
|
if (matcher.toLowerCase() === down) return true; |
|
1151
|
|
|
} |
|
|
|
|
|
|
1152
|
|
|
} |
|
1153
|
|
|
|
|
1154
|
|
|
module.exports = function toBoolean(str, trueValues, falseValues) { |
|
1155
|
|
|
if (typeof str === 'number') str = '' + str; |
|
1156
|
|
|
if (typeof str !== 'string') return !!str; |
|
1157
|
|
|
str = trim(str); |
|
1158
|
|
|
if (boolMatch(str, trueValues || ['true', '1'])) return true; |
|
1159
|
|
|
if (boolMatch(str, falseValues || ['false', '0'])) return false; |
|
|
|
|
|
|
1160
|
|
|
}; |
|
1161
|
|
|
|
|
1162
|
|
|
},{"./trim":65}],62:[function(require,module,exports){ |
|
1163
|
|
|
module.exports = function toNumber(num, precision) { |
|
1164
|
|
|
if (num == null) return 0; |
|
1165
|
|
|
var factor = Math.pow(10, isFinite(precision) ? precision : 0); |
|
1166
|
|
|
return Math.round(num * factor) / factor; |
|
1167
|
|
|
}; |
|
1168
|
|
|
|
|
1169
|
|
|
},{}],63:[function(require,module,exports){ |
|
1170
|
|
|
var rtrim = require('./rtrim'); |
|
1171
|
|
|
|
|
1172
|
|
|
module.exports = function toSentence(array, separator, lastSeparator, serial) { |
|
1173
|
|
|
separator = separator || ', '; |
|
1174
|
|
|
lastSeparator = lastSeparator || ' and '; |
|
1175
|
|
|
var a = array.slice(), |
|
1176
|
|
|
lastMember = a.pop(); |
|
1177
|
|
|
|
|
1178
|
|
|
if (array.length > 2 && serial) lastSeparator = rtrim(separator) + lastSeparator; |
|
1179
|
|
|
|
|
1180
|
|
|
return a.length ? a.join(separator) + lastSeparator + lastMember : lastMember; |
|
1181
|
|
|
}; |
|
1182
|
|
|
|
|
1183
|
|
|
},{"./rtrim":47}],64:[function(require,module,exports){ |
|
1184
|
|
|
var toSentence = require('./toSentence'); |
|
1185
|
|
|
|
|
1186
|
|
|
module.exports = function toSentenceSerial(array, sep, lastSep) { |
|
1187
|
|
|
return toSentence(array, sep, lastSep, true); |
|
1188
|
|
|
}; |
|
1189
|
|
|
|
|
1190
|
|
|
},{"./toSentence":63}],65:[function(require,module,exports){ |
|
1191
|
|
|
var makeString = require('./helper/makeString'); |
|
1192
|
|
|
var defaultToWhiteSpace = require('./helper/defaultToWhiteSpace'); |
|
1193
|
|
|
var nativeTrim = String.prototype.trim; |
|
1194
|
|
|
|
|
1195
|
|
|
module.exports = function trim(str, characters) { |
|
1196
|
|
|
str = makeString(str); |
|
1197
|
|
|
if (!characters && nativeTrim) return nativeTrim.call(str); |
|
1198
|
|
|
characters = defaultToWhiteSpace(characters); |
|
1199
|
|
|
return str.replace(new RegExp('^' + characters + '+|' + characters + '+$', 'g'), ''); |
|
1200
|
|
|
}; |
|
1201
|
|
|
|
|
1202
|
|
|
},{"./helper/defaultToWhiteSpace":16,"./helper/makeString":20}],66:[function(require,module,exports){ |
|
1203
|
|
|
var makeString = require('./helper/makeString'); |
|
1204
|
|
|
|
|
1205
|
|
|
module.exports = function truncate(str, length, truncateStr) { |
|
1206
|
|
|
str = makeString(str); |
|
1207
|
|
|
truncateStr = truncateStr || '...'; |
|
1208
|
|
|
length = ~~length; |
|
1209
|
|
|
return str.length > length ? str.slice(0, length) + truncateStr : str; |
|
1210
|
|
|
}; |
|
1211
|
|
|
|
|
1212
|
|
|
},{"./helper/makeString":20}],67:[function(require,module,exports){ |
|
1213
|
|
|
var trim = require('./trim'); |
|
1214
|
|
|
|
|
1215
|
|
|
module.exports = function underscored(str) { |
|
1216
|
|
|
return trim(str).replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase(); |
|
1217
|
|
|
}; |
|
1218
|
|
|
|
|
1219
|
|
|
},{"./trim":65}],68:[function(require,module,exports){ |
|
1220
|
|
|
var makeString = require('./helper/makeString'); |
|
1221
|
|
|
var htmlEntities = require('./helper/htmlEntities'); |
|
1222
|
|
|
|
|
1223
|
|
|
module.exports = function unescapeHTML(str) { |
|
1224
|
|
|
return makeString(str).replace(/\&([^;]+);/g, function(entity, entityCode) { |
|
1225
|
|
|
var match; |
|
1226
|
|
|
|
|
1227
|
|
|
if (entityCode in htmlEntities) { |
|
1228
|
|
|
return htmlEntities[entityCode]; |
|
1229
|
|
|
/*eslint no-cond-assign: 0*/ |
|
1230
|
|
|
} else if (match = entityCode.match(/^#x([\da-fA-F]+)$/)) { |
|
1231
|
|
|
return String.fromCharCode(parseInt(match[1], 16)); |
|
1232
|
|
|
/*eslint no-cond-assign: 0*/ |
|
1233
|
|
|
} else if (match = entityCode.match(/^#(\d+)$/)) { |
|
1234
|
|
|
return String.fromCharCode(~~match[1]); |
|
1235
|
|
|
} else { |
|
1236
|
|
|
return entity; |
|
1237
|
|
|
} |
|
1238
|
|
|
}); |
|
1239
|
|
|
}; |
|
1240
|
|
|
|
|
1241
|
|
|
},{"./helper/htmlEntities":19,"./helper/makeString":20}],69:[function(require,module,exports){ |
|
1242
|
|
|
module.exports = function unquote(str, quoteChar) { |
|
1243
|
|
|
quoteChar = quoteChar || '"'; |
|
1244
|
|
|
if (str[0] === quoteChar && str[str.length - 1] === quoteChar) |
|
1245
|
|
|
return str.slice(1, str.length - 1); |
|
1246
|
|
|
else return str; |
|
1247
|
|
|
}; |
|
1248
|
|
|
|
|
1249
|
|
|
},{}],70:[function(require,module,exports){ |
|
1250
|
|
|
var deprecate = require('util-deprecate'); |
|
1251
|
|
|
|
|
1252
|
|
|
module.exports = deprecate(require('sprintf-js').vsprintf, |
|
1253
|
|
|
'vsprintf() will be removed in the next major release, use the sprintf-js package instead.'); |
|
1254
|
|
|
|
|
1255
|
|
|
},{"sprintf-js":36,"util-deprecate":37}],71:[function(require,module,exports){ |
|
1256
|
|
|
var isBlank = require('./isBlank'); |
|
1257
|
|
|
var trim = require('./trim'); |
|
1258
|
|
|
|
|
1259
|
|
|
module.exports = function words(str, delimiter) { |
|
1260
|
|
|
if (isBlank(str)) return []; |
|
1261
|
|
|
return trim(str, delimiter).split(delimiter || /\s+/); |
|
1262
|
|
|
}; |
|
1263
|
|
|
|
|
1264
|
|
|
},{"./isBlank":27,"./trim":65}],72:[function(require,module,exports){ |
|
1265
|
|
|
// Wrap |
|
1266
|
|
|
// wraps a string by a certain width |
|
1267
|
|
|
|
|
1268
|
|
|
var makeString = require('./helper/makeString'); |
|
1269
|
|
|
|
|
1270
|
|
|
module.exports = function wrap(str, options){ |
|
1271
|
|
|
str = makeString(str); |
|
1272
|
|
|
|
|
1273
|
|
|
options = options || {}; |
|
1274
|
|
|
|
|
1275
|
|
|
var width = options.width || 75; |
|
1276
|
|
|
var seperator = options.seperator || '\n'; |
|
1277
|
|
|
var cut = options.cut || false; |
|
1278
|
|
|
var preserveSpaces = options.preserveSpaces || false; |
|
1279
|
|
|
var trailingSpaces = options.trailingSpaces || false; |
|
1280
|
|
|
|
|
1281
|
|
|
var result; |
|
1282
|
|
|
|
|
1283
|
|
|
if(width <= 0){ |
|
1284
|
|
|
return str; |
|
1285
|
|
|
} |
|
1286
|
|
|
|
|
1287
|
|
|
else if(!cut){ |
|
1288
|
|
|
|
|
1289
|
|
|
var words = str.split(' '); |
|
1290
|
|
|
var current_column = 0; |
|
1291
|
|
|
result = ''; |
|
1292
|
|
|
|
|
1293
|
|
|
while(words.length > 0){ |
|
1294
|
|
|
|
|
1295
|
|
|
// if adding a space and the next word would cause this line to be longer than width... |
|
1296
|
|
|
if(1 + words[0].length + current_column > width){ |
|
1297
|
|
|
//start a new line if this line is not already empty |
|
1298
|
|
|
if(current_column > 0){ |
|
1299
|
|
|
// add a space at the end of the line is preserveSpaces is true |
|
1300
|
|
|
if (preserveSpaces){ |
|
1301
|
|
|
result += ' '; |
|
1302
|
|
|
current_column++; |
|
|
|
|
|
|
1303
|
|
|
} |
|
1304
|
|
|
// fill the rest of the line with spaces if trailingSpaces option is true |
|
1305
|
|
|
else if(trailingSpaces){ |
|
1306
|
|
|
while(current_column < width){ |
|
1307
|
|
|
result += ' '; |
|
1308
|
|
|
current_column++; |
|
1309
|
|
|
} |
|
1310
|
|
|
} |
|
1311
|
|
|
//start new line |
|
1312
|
|
|
result += seperator; |
|
1313
|
|
|
current_column = 0; |
|
1314
|
|
|
} |
|
1315
|
|
|
} |
|
1316
|
|
|
|
|
1317
|
|
|
// if not at the begining of the line, add a space in front of the word |
|
1318
|
|
|
if(current_column > 0){ |
|
1319
|
|
|
result += ' '; |
|
1320
|
|
|
current_column++; |
|
1321
|
|
|
} |
|
1322
|
|
|
|
|
1323
|
|
|
// tack on the next word, update current column, a pop words array |
|
1324
|
|
|
result += words[0]; |
|
1325
|
|
|
current_column += words[0].length; |
|
1326
|
|
|
words.shift(); |
|
1327
|
|
|
|
|
1328
|
|
|
} |
|
1329
|
|
|
|
|
1330
|
|
|
// fill the rest of the line with spaces if trailingSpaces option is true |
|
1331
|
|
|
if(trailingSpaces){ |
|
1332
|
|
|
while(current_column < width){ |
|
1333
|
|
|
result += ' '; |
|
1334
|
|
|
current_column++; |
|
1335
|
|
|
} |
|
1336
|
|
|
} |
|
1337
|
|
|
|
|
1338
|
|
|
return result; |
|
1339
|
|
|
|
|
1340
|
|
|
} |
|
1341
|
|
|
|
|
1342
|
|
|
else { |
|
1343
|
|
|
|
|
1344
|
|
|
var index = 0; |
|
1345
|
|
|
result = ''; |
|
1346
|
|
|
|
|
1347
|
|
|
// walk through each character and add seperators where appropriate |
|
1348
|
|
|
while(index < str.length){ |
|
1349
|
|
|
if(index % width == 0 && index > 0){ |
|
1350
|
|
|
result += seperator; |
|
1351
|
|
|
} |
|
1352
|
|
|
result += str.charAt(index); |
|
1353
|
|
|
index++; |
|
1354
|
|
|
} |
|
1355
|
|
|
|
|
1356
|
|
|
// fill the rest of the line with spaces if trailingSpaces option is true |
|
1357
|
|
|
if(trailingSpaces){ |
|
1358
|
|
|
while(index % width > 0){ |
|
1359
|
|
|
result += ' '; |
|
1360
|
|
|
index++; |
|
1361
|
|
|
} |
|
1362
|
|
|
} |
|
1363
|
|
|
|
|
1364
|
|
|
return result; |
|
1365
|
|
|
} |
|
1366
|
|
|
}; |
|
1367
|
|
|
|
|
1368
|
|
|
},{"./helper/makeString":20}]},{},[25])(25) |
|
1369
|
|
|
}); |
The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.
This operator is most often used in
forstatements.Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.
This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.
could just as well be written as:
To learn more about the sequence operator, please refer to the MDN.