underscore.string.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392
  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.6'
  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(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({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.6'
  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.6';
  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. /* global window, exports, define */
  493. !function() {
  494. 'use strict'
  495. var re = {
  496. not_string: /[^s]/,
  497. not_bool: /[^t]/,
  498. not_type: /[^T]/,
  499. not_primitive: /[^v]/,
  500. number: /[diefg]/,
  501. numeric_arg: /[bcdiefguxX]/,
  502. json: /[j]/,
  503. not_json: /[^j]/,
  504. text: /^[^\x25]+/,
  505. modulo: /^\x25{2}/,
  506. placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
  507. key: /^([a-z_][a-z_\d]*)/i,
  508. key_access: /^\.([a-z_][a-z_\d]*)/i,
  509. index_access: /^\[(\d+)\]/,
  510. sign: /^[+-]/
  511. }
  512. function sprintf(key) {
  513. // `arguments` is not an array, but should be fine for this call
  514. return sprintf_format(sprintf_parse(key), arguments)
  515. }
  516. function vsprintf(fmt, argv) {
  517. return sprintf.apply(null, [fmt].concat(argv || []))
  518. }
  519. function sprintf_format(parse_tree, argv) {
  520. var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign
  521. for (i = 0; i < tree_length; i++) {
  522. if (typeof parse_tree[i] === 'string') {
  523. output += parse_tree[i]
  524. }
  525. else if (typeof parse_tree[i] === 'object') {
  526. ph = parse_tree[i] // convenience purposes only
  527. if (ph.keys) { // keyword argument
  528. arg = argv[cursor]
  529. for (k = 0; k < ph.keys.length; k++) {
  530. if (arg == undefined) {
  531. throw new Error(sprintf('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k-1]))
  532. }
  533. arg = arg[ph.keys[k]]
  534. }
  535. }
  536. else if (ph.param_no) { // positional argument (explicit)
  537. arg = argv[ph.param_no]
  538. }
  539. else { // positional argument (implicit)
  540. arg = argv[cursor++]
  541. }
  542. if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) {
  543. arg = arg()
  544. }
  545. if (re.numeric_arg.test(ph.type) && (typeof arg !== 'number' && isNaN(arg))) {
  546. throw new TypeError(sprintf('[sprintf] expecting number but found %T', arg))
  547. }
  548. if (re.number.test(ph.type)) {
  549. is_positive = arg >= 0
  550. }
  551. switch (ph.type) {
  552. case 'b':
  553. arg = parseInt(arg, 10).toString(2)
  554. break
  555. case 'c':
  556. arg = String.fromCharCode(parseInt(arg, 10))
  557. break
  558. case 'd':
  559. case 'i':
  560. arg = parseInt(arg, 10)
  561. break
  562. case 'j':
  563. arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0)
  564. break
  565. case 'e':
  566. arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential()
  567. break
  568. case 'f':
  569. arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg)
  570. break
  571. case 'g':
  572. arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg)
  573. break
  574. case 'o':
  575. arg = (parseInt(arg, 10) >>> 0).toString(8)
  576. break
  577. case 's':
  578. arg = String(arg)
  579. arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
  580. break
  581. case 't':
  582. arg = String(!!arg)
  583. arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
  584. break
  585. case 'T':
  586. arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase()
  587. arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
  588. break
  589. case 'u':
  590. arg = parseInt(arg, 10) >>> 0
  591. break
  592. case 'v':
  593. arg = arg.valueOf()
  594. arg = (ph.precision ? arg.substring(0, ph.precision) : arg)
  595. break
  596. case 'x':
  597. arg = (parseInt(arg, 10) >>> 0).toString(16)
  598. break
  599. case 'X':
  600. arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase()
  601. break
  602. }
  603. if (re.json.test(ph.type)) {
  604. output += arg
  605. }
  606. else {
  607. if (re.number.test(ph.type) && (!is_positive || ph.sign)) {
  608. sign = is_positive ? '+' : '-'
  609. arg = arg.toString().replace(re.sign, '')
  610. }
  611. else {
  612. sign = ''
  613. }
  614. pad_character = ph.pad_char ? ph.pad_char === '0' ? '0' : ph.pad_char.charAt(1) : ' '
  615. pad_length = ph.width - (sign + arg).length
  616. pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : ''
  617. output += ph.align ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg)
  618. }
  619. }
  620. }
  621. return output
  622. }
  623. var sprintf_cache = Object.create(null)
  624. function sprintf_parse(fmt) {
  625. if (sprintf_cache[fmt]) {
  626. return sprintf_cache[fmt]
  627. }
  628. var _fmt = fmt, match, parse_tree = [], arg_names = 0
  629. while (_fmt) {
  630. if ((match = re.text.exec(_fmt)) !== null) {
  631. parse_tree.push(match[0])
  632. }
  633. else if ((match = re.modulo.exec(_fmt)) !== null) {
  634. parse_tree.push('%')
  635. }
  636. else if ((match = re.placeholder.exec(_fmt)) !== null) {
  637. if (match[2]) {
  638. arg_names |= 1
  639. var field_list = [], replacement_field = match[2], field_match = []
  640. if ((field_match = re.key.exec(replacement_field)) !== null) {
  641. field_list.push(field_match[1])
  642. while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {
  643. if ((field_match = re.key_access.exec(replacement_field)) !== null) {
  644. field_list.push(field_match[1])
  645. }
  646. else if ((field_match = re.index_access.exec(replacement_field)) !== null) {
  647. field_list.push(field_match[1])
  648. }
  649. else {
  650. throw new SyntaxError('[sprintf] failed to parse named argument key')
  651. }
  652. }
  653. }
  654. else {
  655. throw new SyntaxError('[sprintf] failed to parse named argument key')
  656. }
  657. match[2] = field_list
  658. }
  659. else {
  660. arg_names |= 2
  661. }
  662. if (arg_names === 3) {
  663. throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported')
  664. }
  665. parse_tree.push(
  666. {
  667. placeholder: match[0],
  668. param_no: match[1],
  669. keys: match[2],
  670. sign: match[3],
  671. pad_char: match[4],
  672. align: match[5],
  673. width: match[6],
  674. precision: match[7],
  675. type: match[8]
  676. }
  677. )
  678. }
  679. else {
  680. throw new SyntaxError('[sprintf] unexpected placeholder')
  681. }
  682. _fmt = _fmt.substring(match[0].length)
  683. }
  684. return sprintf_cache[fmt] = parse_tree
  685. }
  686. /**
  687. * export to either browser or node.js
  688. */
  689. /* eslint-disable quote-props */
  690. if (typeof exports !== 'undefined') {
  691. exports['sprintf'] = sprintf
  692. exports['vsprintf'] = vsprintf
  693. }
  694. if (typeof window !== 'undefined') {
  695. window['sprintf'] = sprintf
  696. window['vsprintf'] = vsprintf
  697. if (typeof define === 'function' && define['amd']) {
  698. define(function() {
  699. return {
  700. 'sprintf': sprintf,
  701. 'vsprintf': vsprintf
  702. }
  703. })
  704. }
  705. }
  706. /* eslint-enable quote-props */
  707. }(); // eslint-disable-line
  708. },{}],37:[function(require,module,exports){
  709. (function (global){(function (){
  710. /**
  711. * Module exports.
  712. */
  713. module.exports = deprecate;
  714. /**
  715. * Mark that a method should not be used.
  716. * Returns a modified function which warns once by default.
  717. *
  718. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  719. *
  720. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  721. * will throw an Error when invoked.
  722. *
  723. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  724. * will invoke `console.trace()` instead of `console.error()`.
  725. *
  726. * @param {Function} fn - the function to deprecate
  727. * @param {String} msg - the string to print to the console when `fn` is invoked
  728. * @returns {Function} a new "deprecated" version of `fn`
  729. * @api public
  730. */
  731. function deprecate (fn, msg) {
  732. if (config('noDeprecation')) {
  733. return fn;
  734. }
  735. var warned = false;
  736. function deprecated() {
  737. if (!warned) {
  738. if (config('throwDeprecation')) {
  739. throw new Error(msg);
  740. } else if (config('traceDeprecation')) {
  741. console.trace(msg);
  742. } else {
  743. console.warn(msg);
  744. }
  745. warned = true;
  746. }
  747. return fn.apply(this, arguments);
  748. }
  749. return deprecated;
  750. }
  751. /**
  752. * Checks `localStorage` for boolean values for the given `name`.
  753. *
  754. * @param {String} name
  755. * @returns {Boolean}
  756. * @api private
  757. */
  758. function config (name) {
  759. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  760. try {
  761. if (!global.localStorage) return false;
  762. } catch (_) {
  763. return false;
  764. }
  765. var val = global.localStorage[name];
  766. if (null == val) return false;
  767. return String(val).toLowerCase() === 'true';
  768. }
  769. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  770. },{}],38:[function(require,module,exports){
  771. module.exports = function numberFormat(number, dec, dsep, tsep) {
  772. if (isNaN(number) || number == null) return '';
  773. number = number.toFixed(~~dec);
  774. tsep = typeof tsep == 'string' ? tsep : ',';
  775. var parts = number.split('.'),
  776. fnums = parts[0],
  777. decimals = parts[1] ? (dsep || '.') + parts[1] : '';
  778. return fnums.replace(/(\d)(?=(?:\d{3})+$)/g, '$1' + tsep) + decimals;
  779. };
  780. },{}],39:[function(require,module,exports){
  781. var makeString = require('./helper/makeString');
  782. var strRepeat = require('./helper/strRepeat');
  783. module.exports = function pad(str, length, padStr, type) {
  784. str = makeString(str);
  785. length = ~~length;
  786. var padlen = 0;
  787. if (!padStr)
  788. padStr = ' ';
  789. else if (padStr.length > 1)
  790. padStr = padStr.charAt(0);
  791. switch (type) {
  792. case 'right':
  793. padlen = length - str.length;
  794. return str + strRepeat(padStr, padlen);
  795. case 'both':
  796. padlen = length - str.length;
  797. return strRepeat(padStr, Math.ceil(padlen / 2)) + str + strRepeat(padStr, Math.floor(padlen / 2));
  798. default: // 'left'
  799. padlen = length - str.length;
  800. return strRepeat(padStr, padlen) + str;
  801. }
  802. };
  803. },{"./helper/makeString":20,"./helper/strRepeat":21}],40:[function(require,module,exports){
  804. var adjacent = require('./helper/adjacent');
  805. module.exports = function succ(str) {
  806. return adjacent(str, -1);
  807. };
  808. },{"./helper/adjacent":15}],41:[function(require,module,exports){
  809. /**
  810. * _s.prune: a more elegant version of truncate
  811. * prune extra chars, never leaving a half-chopped word.
  812. * @author github.com/rwz
  813. */
  814. var makeString = require('./helper/makeString');
  815. var rtrim = require('./rtrim');
  816. module.exports = function prune(str, length, pruneStr) {
  817. str = makeString(str);
  818. length = ~~length;
  819. pruneStr = pruneStr != null ? String(pruneStr) : '...';
  820. if (str.length <= length) return str;
  821. var tmpl = function(c) {
  822. return c.toUpperCase() !== c.toLowerCase() ? 'A' : ' ';
  823. },
  824. template = str.slice(0, length + 1).replace(/.(?=\W*\w*$)/g, tmpl); // 'Hello, world' -> 'HellAA AAAAA'
  825. if (template.slice(template.length - 2).match(/\w\w/))
  826. template = template.replace(/\s*\S+$/, '');
  827. else
  828. template = rtrim(template.slice(0, template.length - 1));
  829. return (template + pruneStr).length > str.length ? str : str.slice(0, template.length) + pruneStr;
  830. };
  831. },{"./helper/makeString":20,"./rtrim":47}],42:[function(require,module,exports){
  832. var surround = require('./surround');
  833. module.exports = function quote(str, quoteChar) {
  834. return surround(str, quoteChar || '"');
  835. };
  836. },{"./surround":58}],43:[function(require,module,exports){
  837. var makeString = require('./helper/makeString');
  838. var strRepeat = require('./helper/strRepeat');
  839. module.exports = function repeat(str, qty, separator) {
  840. str = makeString(str);
  841. qty = ~~qty;
  842. // using faster implementation if separator is not needed;
  843. if (separator == null) return strRepeat(str, qty);
  844. // this one is about 300x slower in Google Chrome
  845. /*eslint no-empty: 0*/
  846. for (var repeat = []; qty > 0; repeat[--qty] = str) {}
  847. return repeat.join(separator);
  848. };
  849. },{"./helper/makeString":20,"./helper/strRepeat":21}],44:[function(require,module,exports){
  850. var makeString = require('./helper/makeString');
  851. module.exports = function replaceAll(str, find, replace, ignorecase) {
  852. var flags = (ignorecase === true)?'gi':'g';
  853. var reg = new RegExp(find, flags);
  854. return makeString(str).replace(reg, replace);
  855. };
  856. },{"./helper/makeString":20}],45:[function(require,module,exports){
  857. var chars = require('./chars');
  858. module.exports = function reverse(str) {
  859. return chars(str).reverse().join('');
  860. };
  861. },{"./chars":3}],46:[function(require,module,exports){
  862. var pad = require('./pad');
  863. module.exports = function rpad(str, length, padStr) {
  864. return pad(str, length, padStr, 'right');
  865. };
  866. },{"./pad":39}],47:[function(require,module,exports){
  867. var makeString = require('./helper/makeString');
  868. var defaultToWhiteSpace = require('./helper/defaultToWhiteSpace');
  869. var nativeTrimRight = String.prototype.trimRight;
  870. module.exports = function rtrim(str, characters) {
  871. str = makeString(str);
  872. if (!characters && nativeTrimRight) return nativeTrimRight.call(str);
  873. characters = defaultToWhiteSpace(characters);
  874. return str.replace(new RegExp(characters + '+$'), '');
  875. };
  876. },{"./helper/defaultToWhiteSpace":16,"./helper/makeString":20}],48:[function(require,module,exports){
  877. var trim = require('./trim');
  878. var dasherize = require('./dasherize');
  879. var cleanDiacritics = require('./cleanDiacritics');
  880. module.exports = function slugify(str) {
  881. return trim(dasherize(cleanDiacritics(str).replace(/[^\w\s-]/g, '-').toLowerCase()), '-');
  882. };
  883. },{"./cleanDiacritics":7,"./dasherize":9,"./trim":65}],49:[function(require,module,exports){
  884. var chars = require('./chars');
  885. module.exports = function splice(str, i, howmany, substr) {
  886. var arr = chars(str);
  887. arr.splice(~~i, ~~howmany, substr);
  888. return arr.join('');
  889. };
  890. },{"./chars":3}],50:[function(require,module,exports){
  891. var deprecate = require('util-deprecate');
  892. module.exports = deprecate(require('sprintf-js').sprintf,
  893. 'sprintf() will be removed in the next major release, use the sprintf-js package instead.');
  894. },{"sprintf-js":36,"util-deprecate":37}],51:[function(require,module,exports){
  895. var makeString = require('./helper/makeString');
  896. var toPositive = require('./helper/toPositive');
  897. module.exports = function startsWith(str, starts, position) {
  898. str = makeString(str);
  899. starts = '' + starts;
  900. position = position == null ? 0 : Math.min(toPositive(position), str.length);
  901. return str.lastIndexOf(starts, position) === position;
  902. };
  903. },{"./helper/makeString":20,"./helper/toPositive":22}],52:[function(require,module,exports){
  904. var makeString = require('./helper/makeString');
  905. module.exports = function strLeft(str, sep) {
  906. str = makeString(str);
  907. sep = makeString(sep);
  908. var pos = !sep ? -1 : str.indexOf(sep);
  909. return~ pos ? str.slice(0, pos) : str;
  910. };
  911. },{"./helper/makeString":20}],53:[function(require,module,exports){
  912. var makeString = require('./helper/makeString');
  913. module.exports = function strLeftBack(str, sep) {
  914. str = makeString(str);
  915. sep = makeString(sep);
  916. var pos = str.lastIndexOf(sep);
  917. return~ pos ? str.slice(0, pos) : str;
  918. };
  919. },{"./helper/makeString":20}],54:[function(require,module,exports){
  920. var makeString = require('./helper/makeString');
  921. module.exports = function strRight(str, sep) {
  922. str = makeString(str);
  923. sep = makeString(sep);
  924. var pos = !sep ? -1 : str.indexOf(sep);
  925. return~ pos ? str.slice(pos + sep.length, str.length) : str;
  926. };
  927. },{"./helper/makeString":20}],55:[function(require,module,exports){
  928. var makeString = require('./helper/makeString');
  929. module.exports = function strRightBack(str, sep) {
  930. str = makeString(str);
  931. sep = makeString(sep);
  932. var pos = !sep ? -1 : str.lastIndexOf(sep);
  933. return~ pos ? str.slice(pos + sep.length, str.length) : str;
  934. };
  935. },{"./helper/makeString":20}],56:[function(require,module,exports){
  936. var makeString = require('./helper/makeString');
  937. module.exports = function stripTags(str) {
  938. return makeString(str).replace(/<\/?[^>]+>/g, '');
  939. };
  940. },{"./helper/makeString":20}],57:[function(require,module,exports){
  941. var adjacent = require('./helper/adjacent');
  942. module.exports = function succ(str) {
  943. return adjacent(str, 1);
  944. };
  945. },{"./helper/adjacent":15}],58:[function(require,module,exports){
  946. module.exports = function surround(str, wrapper) {
  947. return [wrapper, str, wrapper].join('');
  948. };
  949. },{}],59:[function(require,module,exports){
  950. var makeString = require('./helper/makeString');
  951. module.exports = function swapCase(str) {
  952. return makeString(str).replace(/\S/g, function(c) {
  953. return c === c.toUpperCase() ? c.toLowerCase() : c.toUpperCase();
  954. });
  955. };
  956. },{"./helper/makeString":20}],60:[function(require,module,exports){
  957. var makeString = require('./helper/makeString');
  958. module.exports = function titleize(str) {
  959. return makeString(str).toLowerCase().replace(/(?:^|\s|-)\S/g, function(c) {
  960. return c.toUpperCase();
  961. });
  962. };
  963. },{"./helper/makeString":20}],61:[function(require,module,exports){
  964. var trim = require('./trim');
  965. function boolMatch(s, matchers) {
  966. var i, matcher, down = s.toLowerCase();
  967. matchers = [].concat(matchers);
  968. for (i = 0; i < matchers.length; i += 1) {
  969. matcher = matchers[i];
  970. if (!matcher) continue;
  971. if (matcher.test && matcher.test(s)) return true;
  972. if (matcher.toLowerCase() === down) return true;
  973. }
  974. }
  975. module.exports = function toBoolean(str, trueValues, falseValues) {
  976. if (typeof str === 'number') str = '' + str;
  977. if (typeof str !== 'string') return !!str;
  978. str = trim(str);
  979. if (boolMatch(str, trueValues || ['true', '1'])) return true;
  980. if (boolMatch(str, falseValues || ['false', '0'])) return false;
  981. };
  982. },{"./trim":65}],62:[function(require,module,exports){
  983. module.exports = function toNumber(num, precision) {
  984. if (num == null) return 0;
  985. var factor = Math.pow(10, isFinite(precision) ? precision : 0);
  986. return Math.round(num * factor) / factor;
  987. };
  988. },{}],63:[function(require,module,exports){
  989. var rtrim = require('./rtrim');
  990. module.exports = function toSentence(array, separator, lastSeparator, serial) {
  991. separator = separator || ', ';
  992. lastSeparator = lastSeparator || ' and ';
  993. var a = array.slice(),
  994. lastMember = a.pop();
  995. if (array.length > 2 && serial) lastSeparator = rtrim(separator) + lastSeparator;
  996. return a.length ? a.join(separator) + lastSeparator + lastMember : lastMember;
  997. };
  998. },{"./rtrim":47}],64:[function(require,module,exports){
  999. var toSentence = require('./toSentence');
  1000. module.exports = function toSentenceSerial(array, sep, lastSep) {
  1001. return toSentence(array, sep, lastSep, true);
  1002. };
  1003. },{"./toSentence":63}],65:[function(require,module,exports){
  1004. var makeString = require('./helper/makeString');
  1005. var defaultToWhiteSpace = require('./helper/defaultToWhiteSpace');
  1006. var nativeTrim = String.prototype.trim;
  1007. module.exports = function trim(str, characters) {
  1008. str = makeString(str);
  1009. if (!characters && nativeTrim) return nativeTrim.call(str);
  1010. characters = defaultToWhiteSpace(characters);
  1011. return str.replace(new RegExp('^' + characters + '+|' + characters + '+$', 'g'), '');
  1012. };
  1013. },{"./helper/defaultToWhiteSpace":16,"./helper/makeString":20}],66:[function(require,module,exports){
  1014. var makeString = require('./helper/makeString');
  1015. module.exports = function truncate(str, length, truncateStr) {
  1016. str = makeString(str);
  1017. truncateStr = truncateStr || '...';
  1018. length = ~~length;
  1019. return str.length > length ? str.slice(0, length) + truncateStr : str;
  1020. };
  1021. },{"./helper/makeString":20}],67:[function(require,module,exports){
  1022. var trim = require('./trim');
  1023. module.exports = function underscored(str) {
  1024. return trim(str).replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
  1025. };
  1026. },{"./trim":65}],68:[function(require,module,exports){
  1027. var makeString = require('./helper/makeString');
  1028. var htmlEntities = require('./helper/htmlEntities');
  1029. module.exports = function unescapeHTML(str) {
  1030. return makeString(str).replace(/\&([^;]{1,10});/g, function(entity, entityCode) {
  1031. var match;
  1032. if (entityCode in htmlEntities) {
  1033. return htmlEntities[entityCode];
  1034. /*eslint no-cond-assign: 0*/
  1035. } else if (match = entityCode.match(/^#x([\da-fA-F]+)$/)) {
  1036. return String.fromCharCode(parseInt(match[1], 16));
  1037. /*eslint no-cond-assign: 0*/
  1038. } else if (match = entityCode.match(/^#(\d+)$/)) {
  1039. return String.fromCharCode(~~match[1]);
  1040. } else {
  1041. return entity;
  1042. }
  1043. });
  1044. };
  1045. },{"./helper/htmlEntities":19,"./helper/makeString":20}],69:[function(require,module,exports){
  1046. module.exports = function unquote(str, quoteChar) {
  1047. quoteChar = quoteChar || '"';
  1048. if (str[0] === quoteChar && str[str.length - 1] === quoteChar)
  1049. return str.slice(1, str.length - 1);
  1050. else return str;
  1051. };
  1052. },{}],70:[function(require,module,exports){
  1053. var deprecate = require('util-deprecate');
  1054. module.exports = deprecate(require('sprintf-js').vsprintf,
  1055. 'vsprintf() will be removed in the next major release, use the sprintf-js package instead.');
  1056. },{"sprintf-js":36,"util-deprecate":37}],71:[function(require,module,exports){
  1057. var isBlank = require('./isBlank');
  1058. var trim = require('./trim');
  1059. module.exports = function words(str, delimiter) {
  1060. if (isBlank(str)) return [];
  1061. return trim(str, delimiter).split(delimiter || /\s+/);
  1062. };
  1063. },{"./isBlank":27,"./trim":65}],72:[function(require,module,exports){
  1064. // Wrap
  1065. // wraps a string by a certain width
  1066. var makeString = require('./helper/makeString');
  1067. module.exports = function wrap(str, options){
  1068. str = makeString(str);
  1069. options = options || {};
  1070. var width = options.width || 75;
  1071. var seperator = options.seperator || '\n';
  1072. var cut = options.cut || false;
  1073. var preserveSpaces = options.preserveSpaces || false;
  1074. var trailingSpaces = options.trailingSpaces || false;
  1075. var result;
  1076. if(width <= 0){
  1077. return str;
  1078. }
  1079. else if(!cut){
  1080. var words = str.split(' ');
  1081. var current_column = 0;
  1082. result = '';
  1083. while(words.length > 0){
  1084. // if adding a space and the next word would cause this line to be longer than width...
  1085. if(1 + words[0].length + current_column > width){
  1086. //start a new line if this line is not already empty
  1087. if(current_column > 0){
  1088. // add a space at the end of the line is preserveSpaces is true
  1089. if (preserveSpaces){
  1090. result += ' ';
  1091. current_column++;
  1092. }
  1093. // fill the rest of the line with spaces if trailingSpaces option is true
  1094. else if(trailingSpaces){
  1095. while(current_column < width){
  1096. result += ' ';
  1097. current_column++;
  1098. }
  1099. }
  1100. //start new line
  1101. result += seperator;
  1102. current_column = 0;
  1103. }
  1104. }
  1105. // if not at the begining of the line, add a space in front of the word
  1106. if(current_column > 0){
  1107. result += ' ';
  1108. current_column++;
  1109. }
  1110. // tack on the next word, update current column, a pop words array
  1111. result += words[0];
  1112. current_column += words[0].length;
  1113. words.shift();
  1114. }
  1115. // fill the rest of the line with spaces if trailingSpaces option is true
  1116. if(trailingSpaces){
  1117. while(current_column < width){
  1118. result += ' ';
  1119. current_column++;
  1120. }
  1121. }
  1122. return result;
  1123. }
  1124. else {
  1125. var index = 0;
  1126. result = '';
  1127. // walk through each character and add seperators where appropriate
  1128. while(index < str.length){
  1129. if(index % width == 0 && index > 0){
  1130. result += seperator;
  1131. }
  1132. result += str.charAt(index);
  1133. index++;
  1134. }
  1135. // fill the rest of the line with spaces if trailingSpaces option is true
  1136. if(trailingSpaces){
  1137. while(index % width > 0){
  1138. result += ' ';
  1139. index++;
  1140. }
  1141. }
  1142. return result;
  1143. }
  1144. };
  1145. },{"./helper/makeString":20}]},{},[25])(25)
  1146. });