1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369 |
- /*
- * Underscore.string
- * (c) 2010 Esa-Matti Suuronen <esa-matti aet suuronen dot org>
- * Underscore.string is freely distributable under the terms of the MIT license.
- * Documentation: https://github.com/epeli/underscore.string
- * Some code is borrowed from MooTools and Alexandru Marasteanu.
- * Version '3.3.4'
- * @preserve
- */
- (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){
- var trim = require('./trim');
- var decap = require('./decapitalize');
- module.exports = function camelize(str, decapitalize) {
- str = trim(str).replace(/[-_\s]+(.)?/g, function(match, c) {
- return c ? c.toUpperCase() : '';
- });
- if (decapitalize === true) {
- return decap(str);
- } else {
- return str;
- }
- };
- },{"./decapitalize":10,"./trim":65}],2:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function capitalize(str, lowercaseRest) {
- str = makeString(str);
- var remainingChars = !lowercaseRest ? str.slice(1) : str.slice(1).toLowerCase();
- return str.charAt(0).toUpperCase() + remainingChars;
- };
- },{"./helper/makeString":20}],3:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function chars(str) {
- return makeString(str).split('');
- };
- },{"./helper/makeString":20}],4:[function(require,module,exports){
- module.exports = function chop(str, step) {
- if (str == null) return [];
- str = String(str);
- step = ~~step;
- return step > 0 ? str.match(new RegExp('.{1,' + step + '}', 'g')) : [str];
- };
- },{}],5:[function(require,module,exports){
- var capitalize = require('./capitalize');
- var camelize = require('./camelize');
- var makeString = require('./helper/makeString');
- module.exports = function classify(str) {
- str = makeString(str);
- return capitalize(camelize(str.replace(/[\W_]/g, ' ')).replace(/\s/g, ''));
- };
- },{"./camelize":1,"./capitalize":2,"./helper/makeString":20}],6:[function(require,module,exports){
- var trim = require('./trim');
- module.exports = function clean(str) {
- return trim(str).replace(/\s\s+/g, ' ');
- };
- },{"./trim":65}],7:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- var from = 'ąàáäâãåæăćčĉęèéëêĝĥìíïîĵłľńňòóöőôõðøśșşšŝťțţŭùúüűûñÿýçżźž',
- to = 'aaaaaaaaaccceeeeeghiiiijllnnoooooooossssstttuuuuuunyyczzz';
- from += from.toUpperCase();
- to += to.toUpperCase();
- to = to.split('');
- // for tokens requireing multitoken output
- from += 'ß';
- to.push('ss');
- module.exports = function cleanDiacritics(str) {
- return makeString(str).replace(/.{1}/g, function(c){
- var index = from.indexOf(c);
- return index === -1 ? c : to[index];
- });
- };
- },{"./helper/makeString":20}],8:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function(str, substr) {
- str = makeString(str);
- substr = makeString(substr);
- if (str.length === 0 || substr.length === 0) return 0;
-
- return str.split(substr).length - 1;
- };
- },{"./helper/makeString":20}],9:[function(require,module,exports){
- var trim = require('./trim');
- module.exports = function dasherize(str) {
- return trim(str).replace(/([A-Z])/g, '-$1').replace(/[-_\s]+/g, '-').toLowerCase();
- };
- },{"./trim":65}],10:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function decapitalize(str) {
- str = makeString(str);
- return str.charAt(0).toLowerCase() + str.slice(1);
- };
- },{"./helper/makeString":20}],11:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- function getIndent(str) {
- var matches = str.match(/^[\s\\t]*/gm);
- var indent = matches[0].length;
-
- for (var i = 1; i < matches.length; i++) {
- indent = Math.min(matches[i].length, indent);
- }
- return indent;
- }
- module.exports = function dedent(str, pattern) {
- str = makeString(str);
- var indent = getIndent(str);
- var reg;
- if (indent === 0) return str;
- if (typeof pattern === 'string') {
- reg = new RegExp('^' + pattern, 'gm');
- } else {
- reg = new RegExp('^[ \\t]{' + indent + '}', 'gm');
- }
- return str.replace(reg, '');
- };
- },{"./helper/makeString":20}],12:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- var toPositive = require('./helper/toPositive');
- module.exports = function endsWith(str, ends, position) {
- str = makeString(str);
- ends = '' + ends;
- if (typeof position == 'undefined') {
- position = str.length - ends.length;
- } else {
- position = Math.min(toPositive(position), str.length) - ends.length;
- }
- return position >= 0 && str.indexOf(ends, position) === position;
- };
- },{"./helper/makeString":20,"./helper/toPositive":22}],13:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- var escapeChars = require('./helper/escapeChars');
- var regexString = '[';
- for(var key in escapeChars) {
- regexString += key;
- }
- regexString += ']';
- var regex = new RegExp( regexString, 'g');
- module.exports = function escapeHTML(str) {
- return makeString(str).replace(regex, function(m) {
- return '&' + escapeChars[m] + ';';
- });
- };
- },{"./helper/escapeChars":17,"./helper/makeString":20}],14:[function(require,module,exports){
- module.exports = function() {
- var result = {};
- for (var prop in this) {
- if (!this.hasOwnProperty(prop) || prop.match(/^(?:include|contains|reverse|join|map|wrap)$/)) continue;
- result[prop] = this[prop];
- }
- return result;
- };
- },{}],15:[function(require,module,exports){
- var makeString = require('./makeString');
- module.exports = function adjacent(str, direction) {
- str = makeString(str);
- if (str.length === 0) {
- return '';
- }
- return str.slice(0, -1) + String.fromCharCode(str.charCodeAt(str.length - 1) + direction);
- };
- },{"./makeString":20}],16:[function(require,module,exports){
- var escapeRegExp = require('./escapeRegExp');
- module.exports = function defaultToWhiteSpace(characters) {
- if (characters == null)
- return '\\s';
- else if (characters.source)
- return characters.source;
- else
- return '[' + escapeRegExp(characters) + ']';
- };
- },{"./escapeRegExp":18}],17:[function(require,module,exports){
- /* We're explicitly defining the list of entities we want to escape.
- nbsp is an HTML entity, but we don't want to escape all space characters in a string, hence its omission in this map.
- */
- var escapeChars = {
- '¢' : 'cent',
- '£' : 'pound',
- '¥' : 'yen',
- '€': 'euro',
- '©' :'copy',
- '®' : 'reg',
- '<' : 'lt',
- '>' : 'gt',
- '"' : 'quot',
- '&' : 'amp',
- '\'' : '#39'
- };
- module.exports = escapeChars;
- },{}],18:[function(require,module,exports){
- var makeString = require('./makeString');
- module.exports = function escapeRegExp(str) {
- return makeString(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
- };
- },{"./makeString":20}],19:[function(require,module,exports){
- /*
- We're explicitly defining the list of entities that might see in escape HTML strings
- */
- var htmlEntities = {
- nbsp: ' ',
- cent: '¢',
- pound: '£',
- yen: '¥',
- euro: '€',
- copy: '©',
- reg: '®',
- lt: '<',
- gt: '>',
- quot: '"',
- amp: '&',
- apos: '\''
- };
- module.exports = htmlEntities;
- },{}],20:[function(require,module,exports){
- /**
- * Ensure some object is a coerced to a string
- **/
- module.exports = function makeString(object) {
- if (object == null) return '';
- return '' + object;
- };
- },{}],21:[function(require,module,exports){
- module.exports = function strRepeat(str, qty){
- if (qty < 1) return '';
- var result = '';
- while (qty > 0) {
- if (qty & 1) result += str;
- qty >>= 1, str += str;
- }
- return result;
- };
- },{}],22:[function(require,module,exports){
- module.exports = function toPositive(number) {
- return number < 0 ? 0 : (+number || 0);
- };
- },{}],23:[function(require,module,exports){
- var capitalize = require('./capitalize');
- var underscored = require('./underscored');
- var trim = require('./trim');
- module.exports = function humanize(str) {
- return capitalize(trim(underscored(str).replace(/_id$/, '').replace(/_/g, ' ')));
- };
- },{"./capitalize":2,"./trim":65,"./underscored":67}],24:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function include(str, needle) {
- if (needle === '') return true;
- return makeString(str).indexOf(needle) !== -1;
- };
- },{"./helper/makeString":20}],25:[function(require,module,exports){
- /*
- * Underscore.string
- * (c) 2010 Esa-Matti Suuronen <esa-matti aet suuronen dot org>
- * Underscore.string is freely distributable under the terms of the MIT license.
- * Documentation: https://github.com/epeli/underscore.string
- * Some code is borrowed from MooTools and Alexandru Marasteanu.
- * Version '3.3.4'
- * @preserve
- */
- 'use strict';
- function s(value) {
- /* jshint validthis: true */
- if (!(this instanceof s)) return new s(value);
- this._wrapped = value;
- }
- s.VERSION = '3.3.4';
- s.isBlank = require('./isBlank');
- s.stripTags = require('./stripTags');
- s.capitalize = require('./capitalize');
- s.decapitalize = require('./decapitalize');
- s.chop = require('./chop');
- s.trim = require('./trim');
- s.clean = require('./clean');
- s.cleanDiacritics = require('./cleanDiacritics');
- s.count = require('./count');
- s.chars = require('./chars');
- s.swapCase = require('./swapCase');
- s.escapeHTML = require('./escapeHTML');
- s.unescapeHTML = require('./unescapeHTML');
- s.splice = require('./splice');
- s.insert = require('./insert');
- s.replaceAll = require('./replaceAll');
- s.include = require('./include');
- s.join = require('./join');
- s.lines = require('./lines');
- s.dedent = require('./dedent');
- s.reverse = require('./reverse');
- s.startsWith = require('./startsWith');
- s.endsWith = require('./endsWith');
- s.pred = require('./pred');
- s.succ = require('./succ');
- s.titleize = require('./titleize');
- s.camelize = require('./camelize');
- s.underscored = require('./underscored');
- s.dasherize = require('./dasherize');
- s.classify = require('./classify');
- s.humanize = require('./humanize');
- s.ltrim = require('./ltrim');
- s.rtrim = require('./rtrim');
- s.truncate = require('./truncate');
- s.prune = require('./prune');
- s.words = require('./words');
- s.pad = require('./pad');
- s.lpad = require('./lpad');
- s.rpad = require('./rpad');
- s.lrpad = require('./lrpad');
- s.sprintf = require('./sprintf');
- s.vsprintf = require('./vsprintf');
- s.toNumber = require('./toNumber');
- s.numberFormat = require('./numberFormat');
- s.strRight = require('./strRight');
- s.strRightBack = require('./strRightBack');
- s.strLeft = require('./strLeft');
- s.strLeftBack = require('./strLeftBack');
- s.toSentence = require('./toSentence');
- s.toSentenceSerial = require('./toSentenceSerial');
- s.slugify = require('./slugify');
- s.surround = require('./surround');
- s.quote = require('./quote');
- s.unquote = require('./unquote');
- s.repeat = require('./repeat');
- s.naturalCmp = require('./naturalCmp');
- s.levenshtein = require('./levenshtein');
- s.toBoolean = require('./toBoolean');
- s.exports = require('./exports');
- s.escapeRegExp = require('./helper/escapeRegExp');
- s.wrap = require('./wrap');
- s.map = require('./map');
- // Aliases
- s.strip = s.trim;
- s.lstrip = s.ltrim;
- s.rstrip = s.rtrim;
- s.center = s.lrpad;
- s.rjust = s.lpad;
- s.ljust = s.rpad;
- s.contains = s.include;
- s.q = s.quote;
- s.toBool = s.toBoolean;
- s.camelcase = s.camelize;
- s.mapChars = s.map;
- // Implement chaining
- s.prototype = {
- value: function value() {
- return this._wrapped;
- }
- };
- function fn2method(key, fn) {
- if (typeof fn !== 'function') return;
- s.prototype[key] = function() {
- var args = [this._wrapped].concat(Array.prototype.slice.call(arguments));
- var res = fn.apply(null, args);
- // if the result is non-string stop the chain and return the value
- return typeof res === 'string' ? new s(res) : res;
- };
- }
- // Copy functions to instance methods for chaining
- for (var key in s) fn2method(key, s[key]);
- fn2method('tap', function tap(string, fn) {
- return fn(string);
- });
- function prototype2method(methodName) {
- fn2method(methodName, function(context) {
- var args = Array.prototype.slice.call(arguments, 1);
- return String.prototype[methodName].apply(context, args);
- });
- }
- var prototypeMethods = [
- 'toUpperCase',
- 'toLowerCase',
- 'split',
- 'replace',
- 'slice',
- 'substring',
- 'substr',
- 'concat'
- ];
- for (var method in prototypeMethods) prototype2method(prototypeMethods[method]);
- module.exports = s;
- },{"./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){
- var splice = require('./splice');
- module.exports = function insert(str, i, substr) {
- return splice(str, i, 0, substr);
- };
- },{"./splice":49}],27:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function isBlank(str) {
- return (/^\s*$/).test(makeString(str));
- };
- },{"./helper/makeString":20}],28:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- var slice = [].slice;
- module.exports = function join() {
- var args = slice.call(arguments),
- separator = args.shift();
- return args.join(makeString(separator));
- };
- },{"./helper/makeString":20}],29:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- /**
- * Based on the implementation here: https://github.com/hiddentao/fast-levenshtein
- */
- module.exports = function levenshtein(str1, str2) {
- 'use strict';
- str1 = makeString(str1);
- str2 = makeString(str2);
- // Short cut cases
- if (str1 === str2) return 0;
- if (!str1 || !str2) return Math.max(str1.length, str2.length);
- // two rows
- var prevRow = new Array(str2.length + 1);
- // initialise previous row
- for (var i = 0; i < prevRow.length; ++i) {
- prevRow[i] = i;
- }
- // calculate current row distance from previous row
- for (i = 0; i < str1.length; ++i) {
- var nextCol = i + 1;
- for (var j = 0; j < str2.length; ++j) {
- var curCol = nextCol;
- // substution
- nextCol = prevRow[j] + ( (str1.charAt(i) === str2.charAt(j)) ? 0 : 1 );
- // insertion
- var tmp = curCol + 1;
- if (nextCol > tmp) {
- nextCol = tmp;
- }
- // deletion
- tmp = prevRow[j + 1] + 1;
- if (nextCol > tmp) {
- nextCol = tmp;
- }
- // copy current col value into previous (in preparation for next iteration)
- prevRow[j] = curCol;
- }
- // copy last col value into previous (in preparation for next iteration)
- prevRow[j] = nextCol;
- }
- return nextCol;
- };
- },{"./helper/makeString":20}],30:[function(require,module,exports){
- module.exports = function lines(str) {
- if (str == null) return [];
- return String(str).split(/\r\n?|\n/);
- };
- },{}],31:[function(require,module,exports){
- var pad = require('./pad');
- module.exports = function lpad(str, length, padStr) {
- return pad(str, length, padStr);
- };
- },{"./pad":39}],32:[function(require,module,exports){
- var pad = require('./pad');
- module.exports = function lrpad(str, length, padStr) {
- return pad(str, length, padStr, 'both');
- };
- },{"./pad":39}],33:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- var defaultToWhiteSpace = require('./helper/defaultToWhiteSpace');
- var nativeTrimLeft = String.prototype.trimLeft;
- module.exports = function ltrim(str, characters) {
- str = makeString(str);
- if (!characters && nativeTrimLeft) return nativeTrimLeft.call(str);
- characters = defaultToWhiteSpace(characters);
- return str.replace(new RegExp('^' + characters + '+'), '');
- };
- },{"./helper/defaultToWhiteSpace":16,"./helper/makeString":20}],34:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function(str, callback) {
- str = makeString(str);
- if (str.length === 0 || typeof callback !== 'function') return str;
- return str.replace(/./g, callback);
- };
- },{"./helper/makeString":20}],35:[function(require,module,exports){
- module.exports = function naturalCmp(str1, str2) {
- if (str1 == str2) return 0;
- if (!str1) return -1;
- if (!str2) return 1;
- var cmpRegex = /(\.\d+|\d+|\D+)/g,
- tokens1 = String(str1).match(cmpRegex),
- tokens2 = String(str2).match(cmpRegex),
- count = Math.min(tokens1.length, tokens2.length);
- for (var i = 0; i < count; i++) {
- var a = tokens1[i],
- b = tokens2[i];
- if (a !== b) {
- var num1 = +a;
- var num2 = +b;
- if (num1 === num1 && num2 === num2) {
- return num1 > num2 ? 1 : -1;
- }
- return a < b ? -1 : 1;
- }
- }
- if (tokens1.length != tokens2.length)
- return tokens1.length - tokens2.length;
- return str1 < str2 ? -1 : 1;
- };
- },{}],36:[function(require,module,exports){
- (function(window) {
- var re = {
- not_string: /[^s]/,
- number: /[diefg]/,
- json: /[j]/,
- not_json: /[^j]/,
- text: /^[^\x25]+/,
- modulo: /^\x25{2}/,
- placeholder: /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijosuxX])/,
- key: /^([a-z_][a-z_\d]*)/i,
- key_access: /^\.([a-z_][a-z_\d]*)/i,
- index_access: /^\[(\d+)\]/,
- sign: /^[\+\-]/
- }
- function sprintf() {
- var key = arguments[0], cache = sprintf.cache
- if (!(cache[key] && cache.hasOwnProperty(key))) {
- cache[key] = sprintf.parse(key)
- }
- return sprintf.format.call(null, cache[key], arguments)
- }
- sprintf.format = function(parse_tree, argv) {
- var cursor = 1, tree_length = parse_tree.length, node_type = "", arg, output = [], i, k, match, pad, pad_character, pad_length, is_positive = true, sign = ""
- for (i = 0; i < tree_length; i++) {
- node_type = get_type(parse_tree[i])
- if (node_type === "string") {
- output[output.length] = parse_tree[i]
- }
- else if (node_type === "array") {
- match = parse_tree[i] // convenience purposes only
- if (match[2]) { // keyword argument
- arg = argv[cursor]
- for (k = 0; k < match[2].length; k++) {
- if (!arg.hasOwnProperty(match[2][k])) {
- throw new Error(sprintf("[sprintf] property '%s' does not exist", match[2][k]))
- }
- arg = arg[match[2][k]]
- }
- }
- else if (match[1]) { // positional argument (explicit)
- arg = argv[match[1]]
- }
- else { // positional argument (implicit)
- arg = argv[cursor++]
- }
- if (get_type(arg) == "function") {
- arg = arg()
- }
- if (re.not_string.test(match[8]) && re.not_json.test(match[8]) && (get_type(arg) != "number" && isNaN(arg))) {
- throw new TypeError(sprintf("[sprintf] expecting number but found %s", get_type(arg)))
- }
- if (re.number.test(match[8])) {
- is_positive = arg >= 0
- }
- switch (match[8]) {
- case "b":
- arg = arg.toString(2)
- break
- case "c":
- arg = String.fromCharCode(arg)
- break
- case "d":
- case "i":
- arg = parseInt(arg, 10)
- break
- case "j":
- arg = JSON.stringify(arg, null, match[6] ? parseInt(match[6]) : 0)
- break
- case "e":
- arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential()
- break
- case "f":
- arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg)
- break
- case "g":
- arg = match[7] ? parseFloat(arg).toPrecision(match[7]) : parseFloat(arg)
- break
- case "o":
- arg = arg.toString(8)
- break
- case "s":
- arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg)
- break
- case "u":
- arg = arg >>> 0
- break
- case "x":
- arg = arg.toString(16)
- break
- case "X":
- arg = arg.toString(16).toUpperCase()
- break
- }
- if (re.json.test(match[8])) {
- output[output.length] = arg
- }
- else {
- if (re.number.test(match[8]) && (!is_positive || match[3])) {
- sign = is_positive ? "+" : "-"
- arg = arg.toString().replace(re.sign, "")
- }
- else {
- sign = ""
- }
- pad_character = match[4] ? match[4] === "0" ? "0" : match[4].charAt(1) : " "
- pad_length = match[6] - (sign + arg).length
- pad = match[6] ? (pad_length > 0 ? str_repeat(pad_character, pad_length) : "") : ""
- output[output.length] = match[5] ? sign + arg + pad : (pad_character === "0" ? sign + pad + arg : pad + sign + arg)
- }
- }
- }
- return output.join("")
- }
- sprintf.cache = {}
- sprintf.parse = function(fmt) {
- var _fmt = fmt, match = [], parse_tree = [], arg_names = 0
- while (_fmt) {
- if ((match = re.text.exec(_fmt)) !== null) {
- parse_tree[parse_tree.length] = match[0]
- }
- else if ((match = re.modulo.exec(_fmt)) !== null) {
- parse_tree[parse_tree.length] = "%"
- }
- else if ((match = re.placeholder.exec(_fmt)) !== null) {
- if (match[2]) {
- arg_names |= 1
- var field_list = [], replacement_field = match[2], field_match = []
- if ((field_match = re.key.exec(replacement_field)) !== null) {
- field_list[field_list.length] = field_match[1]
- while ((replacement_field = replacement_field.substring(field_match[0].length)) !== "") {
- if ((field_match = re.key_access.exec(replacement_field)) !== null) {
- field_list[field_list.length] = field_match[1]
- }
- else if ((field_match = re.index_access.exec(replacement_field)) !== null) {
- field_list[field_list.length] = field_match[1]
- }
- else {
- throw new SyntaxError("[sprintf] failed to parse named argument key")
- }
- }
- }
- else {
- throw new SyntaxError("[sprintf] failed to parse named argument key")
- }
- match[2] = field_list
- }
- else {
- arg_names |= 2
- }
- if (arg_names === 3) {
- throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported")
- }
- parse_tree[parse_tree.length] = match
- }
- else {
- throw new SyntaxError("[sprintf] unexpected placeholder")
- }
- _fmt = _fmt.substring(match[0].length)
- }
- return parse_tree
- }
- var vsprintf = function(fmt, argv, _argv) {
- _argv = (argv || []).slice(0)
- _argv.splice(0, 0, fmt)
- return sprintf.apply(null, _argv)
- }
- /**
- * helpers
- */
- function get_type(variable) {
- return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase()
- }
- function str_repeat(input, multiplier) {
- return Array(multiplier + 1).join(input)
- }
- /**
- * export to either browser or node.js
- */
- if (typeof exports !== "undefined") {
- exports.sprintf = sprintf
- exports.vsprintf = vsprintf
- }
- else {
- window.sprintf = sprintf
- window.vsprintf = vsprintf
- if (typeof define === "function" && define.amd) {
- define(function() {
- return {
- sprintf: sprintf,
- vsprintf: vsprintf
- }
- })
- }
- }
- })(typeof window === "undefined" ? this : window);
- },{}],37:[function(require,module,exports){
- (function (global){
- /**
- * Module exports.
- */
- module.exports = deprecate;
- /**
- * Mark that a method should not be used.
- * Returns a modified function which warns once by default.
- *
- * If `localStorage.noDeprecation = true` is set, then it is a no-op.
- *
- * If `localStorage.throwDeprecation = true` is set, then deprecated functions
- * will throw an Error when invoked.
- *
- * If `localStorage.traceDeprecation = true` is set, then deprecated functions
- * will invoke `console.trace()` instead of `console.error()`.
- *
- * @param {Function} fn - the function to deprecate
- * @param {String} msg - the string to print to the console when `fn` is invoked
- * @returns {Function} a new "deprecated" version of `fn`
- * @api public
- */
- function deprecate (fn, msg) {
- if (config('noDeprecation')) {
- return fn;
- }
- var warned = false;
- function deprecated() {
- if (!warned) {
- if (config('throwDeprecation')) {
- throw new Error(msg);
- } else if (config('traceDeprecation')) {
- console.trace(msg);
- } else {
- console.warn(msg);
- }
- warned = true;
- }
- return fn.apply(this, arguments);
- }
- return deprecated;
- }
- /**
- * Checks `localStorage` for boolean values for the given `name`.
- *
- * @param {String} name
- * @returns {Boolean}
- * @api private
- */
- function config (name) {
- // accessing global.localStorage can trigger a DOMException in sandboxed iframes
- try {
- if (!global.localStorage) return false;
- } catch (_) {
- return false;
- }
- var val = global.localStorage[name];
- if (null == val) return false;
- return String(val).toLowerCase() === 'true';
- }
- }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
- },{}],38:[function(require,module,exports){
- module.exports = function numberFormat(number, dec, dsep, tsep) {
- if (isNaN(number) || number == null) return '';
- number = number.toFixed(~~dec);
- tsep = typeof tsep == 'string' ? tsep : ',';
- var parts = number.split('.'),
- fnums = parts[0],
- decimals = parts[1] ? (dsep || '.') + parts[1] : '';
- return fnums.replace(/(\d)(?=(?:\d{3})+$)/g, '$1' + tsep) + decimals;
- };
- },{}],39:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- var strRepeat = require('./helper/strRepeat');
- module.exports = function pad(str, length, padStr, type) {
- str = makeString(str);
- length = ~~length;
- var padlen = 0;
- if (!padStr)
- padStr = ' ';
- else if (padStr.length > 1)
- padStr = padStr.charAt(0);
- switch (type) {
- case 'right':
- padlen = length - str.length;
- return str + strRepeat(padStr, padlen);
- case 'both':
- padlen = length - str.length;
- return strRepeat(padStr, Math.ceil(padlen / 2)) + str + strRepeat(padStr, Math.floor(padlen / 2));
- default: // 'left'
- padlen = length - str.length;
- return strRepeat(padStr, padlen) + str;
- }
- };
- },{"./helper/makeString":20,"./helper/strRepeat":21}],40:[function(require,module,exports){
- var adjacent = require('./helper/adjacent');
- module.exports = function succ(str) {
- return adjacent(str, -1);
- };
- },{"./helper/adjacent":15}],41:[function(require,module,exports){
- /**
- * _s.prune: a more elegant version of truncate
- * prune extra chars, never leaving a half-chopped word.
- * @author github.com/rwz
- */
- var makeString = require('./helper/makeString');
- var rtrim = require('./rtrim');
- module.exports = function prune(str, length, pruneStr) {
- str = makeString(str);
- length = ~~length;
- pruneStr = pruneStr != null ? String(pruneStr) : '...';
- if (str.length <= length) return str;
- var tmpl = function(c) {
- return c.toUpperCase() !== c.toLowerCase() ? 'A' : ' ';
- },
- template = str.slice(0, length + 1).replace(/.(?=\W*\w*$)/g, tmpl); // 'Hello, world' -> 'HellAA AAAAA'
- if (template.slice(template.length - 2).match(/\w\w/))
- template = template.replace(/\s*\S+$/, '');
- else
- template = rtrim(template.slice(0, template.length - 1));
- return (template + pruneStr).length > str.length ? str : str.slice(0, template.length) + pruneStr;
- };
- },{"./helper/makeString":20,"./rtrim":47}],42:[function(require,module,exports){
- var surround = require('./surround');
- module.exports = function quote(str, quoteChar) {
- return surround(str, quoteChar || '"');
- };
- },{"./surround":58}],43:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- var strRepeat = require('./helper/strRepeat');
- module.exports = function repeat(str, qty, separator) {
- str = makeString(str);
- qty = ~~qty;
- // using faster implementation if separator is not needed;
- if (separator == null) return strRepeat(str, qty);
- // this one is about 300x slower in Google Chrome
- /*eslint no-empty: 0*/
- for (var repeat = []; qty > 0; repeat[--qty] = str) {}
- return repeat.join(separator);
- };
- },{"./helper/makeString":20,"./helper/strRepeat":21}],44:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function replaceAll(str, find, replace, ignorecase) {
- var flags = (ignorecase === true)?'gi':'g';
- var reg = new RegExp(find, flags);
- return makeString(str).replace(reg, replace);
- };
- },{"./helper/makeString":20}],45:[function(require,module,exports){
- var chars = require('./chars');
- module.exports = function reverse(str) {
- return chars(str).reverse().join('');
- };
- },{"./chars":3}],46:[function(require,module,exports){
- var pad = require('./pad');
- module.exports = function rpad(str, length, padStr) {
- return pad(str, length, padStr, 'right');
- };
- },{"./pad":39}],47:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- var defaultToWhiteSpace = require('./helper/defaultToWhiteSpace');
- var nativeTrimRight = String.prototype.trimRight;
- module.exports = function rtrim(str, characters) {
- str = makeString(str);
- if (!characters && nativeTrimRight) return nativeTrimRight.call(str);
- characters = defaultToWhiteSpace(characters);
- return str.replace(new RegExp(characters + '+$'), '');
- };
- },{"./helper/defaultToWhiteSpace":16,"./helper/makeString":20}],48:[function(require,module,exports){
- var trim = require('./trim');
- var dasherize = require('./dasherize');
- var cleanDiacritics = require('./cleanDiacritics');
- module.exports = function slugify(str) {
- return trim(dasherize(cleanDiacritics(str).replace(/[^\w\s-]/g, '-').toLowerCase()), '-');
- };
- },{"./cleanDiacritics":7,"./dasherize":9,"./trim":65}],49:[function(require,module,exports){
- var chars = require('./chars');
- module.exports = function splice(str, i, howmany, substr) {
- var arr = chars(str);
- arr.splice(~~i, ~~howmany, substr);
- return arr.join('');
- };
- },{"./chars":3}],50:[function(require,module,exports){
- var deprecate = require('util-deprecate');
- module.exports = deprecate(require('sprintf-js').sprintf,
- 'sprintf() will be removed in the next major release, use the sprintf-js package instead.');
- },{"sprintf-js":36,"util-deprecate":37}],51:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- var toPositive = require('./helper/toPositive');
- module.exports = function startsWith(str, starts, position) {
- str = makeString(str);
- starts = '' + starts;
- position = position == null ? 0 : Math.min(toPositive(position), str.length);
- return str.lastIndexOf(starts, position) === position;
- };
- },{"./helper/makeString":20,"./helper/toPositive":22}],52:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function strLeft(str, sep) {
- str = makeString(str);
- sep = makeString(sep);
- var pos = !sep ? -1 : str.indexOf(sep);
- return~ pos ? str.slice(0, pos) : str;
- };
- },{"./helper/makeString":20}],53:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function strLeftBack(str, sep) {
- str = makeString(str);
- sep = makeString(sep);
- var pos = str.lastIndexOf(sep);
- return~ pos ? str.slice(0, pos) : str;
- };
- },{"./helper/makeString":20}],54:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function strRight(str, sep) {
- str = makeString(str);
- sep = makeString(sep);
- var pos = !sep ? -1 : str.indexOf(sep);
- return~ pos ? str.slice(pos + sep.length, str.length) : str;
- };
- },{"./helper/makeString":20}],55:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function strRightBack(str, sep) {
- str = makeString(str);
- sep = makeString(sep);
- var pos = !sep ? -1 : str.lastIndexOf(sep);
- return~ pos ? str.slice(pos + sep.length, str.length) : str;
- };
- },{"./helper/makeString":20}],56:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function stripTags(str) {
- return makeString(str).replace(/<\/?[^>]+>/g, '');
- };
- },{"./helper/makeString":20}],57:[function(require,module,exports){
- var adjacent = require('./helper/adjacent');
- module.exports = function succ(str) {
- return adjacent(str, 1);
- };
- },{"./helper/adjacent":15}],58:[function(require,module,exports){
- module.exports = function surround(str, wrapper) {
- return [wrapper, str, wrapper].join('');
- };
- },{}],59:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function swapCase(str) {
- return makeString(str).replace(/\S/g, function(c) {
- return c === c.toUpperCase() ? c.toLowerCase() : c.toUpperCase();
- });
- };
- },{"./helper/makeString":20}],60:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function titleize(str) {
- return makeString(str).toLowerCase().replace(/(?:^|\s|-)\S/g, function(c) {
- return c.toUpperCase();
- });
- };
- },{"./helper/makeString":20}],61:[function(require,module,exports){
- var trim = require('./trim');
- function boolMatch(s, matchers) {
- var i, matcher, down = s.toLowerCase();
- matchers = [].concat(matchers);
- for (i = 0; i < matchers.length; i += 1) {
- matcher = matchers[i];
- if (!matcher) continue;
- if (matcher.test && matcher.test(s)) return true;
- if (matcher.toLowerCase() === down) return true;
- }
- }
- module.exports = function toBoolean(str, trueValues, falseValues) {
- if (typeof str === 'number') str = '' + str;
- if (typeof str !== 'string') return !!str;
- str = trim(str);
- if (boolMatch(str, trueValues || ['true', '1'])) return true;
- if (boolMatch(str, falseValues || ['false', '0'])) return false;
- };
- },{"./trim":65}],62:[function(require,module,exports){
- module.exports = function toNumber(num, precision) {
- if (num == null) return 0;
- var factor = Math.pow(10, isFinite(precision) ? precision : 0);
- return Math.round(num * factor) / factor;
- };
- },{}],63:[function(require,module,exports){
- var rtrim = require('./rtrim');
- module.exports = function toSentence(array, separator, lastSeparator, serial) {
- separator = separator || ', ';
- lastSeparator = lastSeparator || ' and ';
- var a = array.slice(),
- lastMember = a.pop();
- if (array.length > 2 && serial) lastSeparator = rtrim(separator) + lastSeparator;
- return a.length ? a.join(separator) + lastSeparator + lastMember : lastMember;
- };
- },{"./rtrim":47}],64:[function(require,module,exports){
- var toSentence = require('./toSentence');
- module.exports = function toSentenceSerial(array, sep, lastSep) {
- return toSentence(array, sep, lastSep, true);
- };
- },{"./toSentence":63}],65:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- var defaultToWhiteSpace = require('./helper/defaultToWhiteSpace');
- var nativeTrim = String.prototype.trim;
- module.exports = function trim(str, characters) {
- str = makeString(str);
- if (!characters && nativeTrim) return nativeTrim.call(str);
- characters = defaultToWhiteSpace(characters);
- return str.replace(new RegExp('^' + characters + '+|' + characters + '+$', 'g'), '');
- };
- },{"./helper/defaultToWhiteSpace":16,"./helper/makeString":20}],66:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- module.exports = function truncate(str, length, truncateStr) {
- str = makeString(str);
- truncateStr = truncateStr || '...';
- length = ~~length;
- return str.length > length ? str.slice(0, length) + truncateStr : str;
- };
- },{"./helper/makeString":20}],67:[function(require,module,exports){
- var trim = require('./trim');
- module.exports = function underscored(str) {
- return trim(str).replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
- };
- },{"./trim":65}],68:[function(require,module,exports){
- var makeString = require('./helper/makeString');
- var htmlEntities = require('./helper/htmlEntities');
- module.exports = function unescapeHTML(str) {
- return makeString(str).replace(/\&([^;]+);/g, function(entity, entityCode) {
- var match;
- if (entityCode in htmlEntities) {
- return htmlEntities[entityCode];
- /*eslint no-cond-assign: 0*/
- } else if (match = entityCode.match(/^#x([\da-fA-F]+)$/)) {
- return String.fromCharCode(parseInt(match[1], 16));
- /*eslint no-cond-assign: 0*/
- } else if (match = entityCode.match(/^#(\d+)$/)) {
- return String.fromCharCode(~~match[1]);
- } else {
- return entity;
- }
- });
- };
- },{"./helper/htmlEntities":19,"./helper/makeString":20}],69:[function(require,module,exports){
- module.exports = function unquote(str, quoteChar) {
- quoteChar = quoteChar || '"';
- if (str[0] === quoteChar && str[str.length - 1] === quoteChar)
- return str.slice(1, str.length - 1);
- else return str;
- };
- },{}],70:[function(require,module,exports){
- var deprecate = require('util-deprecate');
- module.exports = deprecate(require('sprintf-js').vsprintf,
- 'vsprintf() will be removed in the next major release, use the sprintf-js package instead.');
- },{"sprintf-js":36,"util-deprecate":37}],71:[function(require,module,exports){
- var isBlank = require('./isBlank');
- var trim = require('./trim');
- module.exports = function words(str, delimiter) {
- if (isBlank(str)) return [];
- return trim(str, delimiter).split(delimiter || /\s+/);
- };
- },{"./isBlank":27,"./trim":65}],72:[function(require,module,exports){
- // Wrap
- // wraps a string by a certain width
- var makeString = require('./helper/makeString');
- module.exports = function wrap(str, options){
- str = makeString(str);
-
- options = options || {};
-
- var width = options.width || 75;
- var seperator = options.seperator || '\n';
- var cut = options.cut || false;
- var preserveSpaces = options.preserveSpaces || false;
- var trailingSpaces = options.trailingSpaces || false;
-
- var result;
-
- if(width <= 0){
- return str;
- }
-
- else if(!cut){
-
- var words = str.split(' ');
- var current_column = 0;
- result = '';
-
- while(words.length > 0){
-
- // if adding a space and the next word would cause this line to be longer than width...
- if(1 + words[0].length + current_column > width){
- //start a new line if this line is not already empty
- if(current_column > 0){
- // add a space at the end of the line is preserveSpaces is true
- if (preserveSpaces){
- result += ' ';
- current_column++;
- }
- // fill the rest of the line with spaces if trailingSpaces option is true
- else if(trailingSpaces){
- while(current_column < width){
- result += ' ';
- current_column++;
- }
- }
- //start new line
- result += seperator;
- current_column = 0;
- }
- }
-
- // if not at the begining of the line, add a space in front of the word
- if(current_column > 0){
- result += ' ';
- current_column++;
- }
-
- // tack on the next word, update current column, a pop words array
- result += words[0];
- current_column += words[0].length;
- words.shift();
-
- }
-
- // fill the rest of the line with spaces if trailingSpaces option is true
- if(trailingSpaces){
- while(current_column < width){
- result += ' ';
- current_column++;
- }
- }
-
- return result;
-
- }
-
- else {
-
- var index = 0;
- result = '';
-
- // walk through each character and add seperators where appropriate
- while(index < str.length){
- if(index % width == 0 && index > 0){
- result += seperator;
- }
- result += str.charAt(index);
- index++;
- }
-
- // fill the rest of the line with spaces if trailingSpaces option is true
- if(trailingSpaces){
- while(index % width > 0){
- result += ' ';
- index++;
- }
- }
-
- return result;
- }
- };
- },{"./helper/makeString":20}]},{},[25])(25)
- });
|