underscore.string.js 43 KB

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