underscore.string-3.3.4/0000755000175600017570000000000012663266217014253 5ustar pravipraviunderscore.string-3.3.4/map.js0000644000175600017570000000034712663266217015372 0ustar pravipravivar 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); }; underscore.string-3.3.4/index.js0000644000175600017570000001066612663266217015731 0ustar pravipravi/* * Underscore.string * (c) 2010 Esa-Matti Suuronen * 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; underscore.string-3.3.4/bower.json0000644000175600017570000000204412663266217016264 0ustar pravipravi{ "name": "underscore.string", "version": "3.3.4", "description": "String manipulation extensions for Underscore.js javascript library.", "homepage": "http://epeli.github.com/underscore.string/", "contributors": [ "Esa-Matti Suuronen (http://esa-matti.suuronen.org/)", "Edward Tsech ", "Pavel Pravosud ()", "Sasha Koss (http://koss.nocorp.me/)", "Vladimir Dronnikov ", "Pete Kruckenberg ()", "Paul Chavard ()", "Ed Finkler ()" ], "keywords": [ "underscore", "string" ], "main": "./dist/underscore.string.js", "ignore": [], "repository": { "type": "git", "url": "https://github.com/epeli/underscore.string.git" }, "bugs": { "url": "https://github.com/epeli/underscore.string/issues" }, "licenses": [ { "type": "MIT" } ] } underscore.string-3.3.4/reverse.js0000644000175600017570000000016512663266217016266 0ustar pravipravivar chars = require('./chars'); module.exports = function reverse(str) { return chars(str).reverse().join(''); }; underscore.string-3.3.4/slugify.js0000644000175600017570000000040412663266217016271 0ustar pravipravivar 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()), '-'); }; underscore.string-3.3.4/escapeHTML.js0000644000175600017570000000060612663266217016540 0ustar pravipravivar 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] + ';'; }); }; underscore.string-3.3.4/strLeft.js0000644000175600017570000000035012663266217016232 0ustar pravipravivar 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; }; underscore.string-3.3.4/humanize.js0000644000175600017570000000036612663266217016436 0ustar pravipravivar 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, ' '))); }; underscore.string-3.3.4/.eslintrc0000644000175600017570000000064012663266217016077 0ustar pravipravi{ "rules": { "indent": [ 2, 2 ], "quotes": [ 2, "single" ], "linebreak-style": [ 2, "unix" ], "semi": [ 2, "always" ] }, "env": { "mocha": true, "node": true, "browser": true }, "extends": "eslint:recommended" } underscore.string-3.3.4/capitalize.js0000644000175600017570000000042412663266217016736 0ustar pravipravivar 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; }; underscore.string-3.3.4/scripts/0000755000175600017570000000000012663266217015742 5ustar pravipraviunderscore.string-3.3.4/scripts/bump-version.js0000644000175600017570000000076512663266217020736 0ustar pravipravivar replace = require('replace'); var package = require('../package.json'); var VERSION_FILES = ['./component.json', './bower.json', './index.js', './package.js']; replace({ regex: /(version?\s?=?\:?\s\')([\d\.]*)\'/gi, replacement: '$1' + package.version + "'", paths: VERSION_FILES, recursive: false, silent: false }); replace({ regex: /(version?"\s?:?\:?\s")([\d\.]*)"/gi, replacement: '$1' + package.version + "\"", paths: VERSION_FILES, recursive: false, silent: false }); underscore.string-3.3.4/scripts/push-tags.js0000644000175600017570000000042212663266217020211 0ustar pravipravivar exec = require('child_process').exec; var version = require('../package.json').version; exec('git add -A && git commit -m "Version ' + version + '" && git push origin master && git tag -a ' + version + ' -m "' + version + '" && git push origin --tags && npm publish'); underscore.string-3.3.4/.eslintignore0000644000175600017570000000013712663266217016757 0ustar pravipravi.eslintrc.js gulpfile.js meteor-*.js package.js dist/** scripts/** coverage/** node_modules/** underscore.string-3.3.4/decapitalize.js0000644000175600017570000000026112663266217017246 0ustar pravipravivar makeString = require('./helper/makeString'); module.exports = function decapitalize(str) { str = makeString(str); return str.charAt(0).toLowerCase() + str.slice(1); }; underscore.string-3.3.4/lines.js0000644000175600017570000000016012663266217015720 0ustar pravipravimodule.exports = function lines(str) { if (str == null) return []; return String(str).split(/\r\n?|\n/); }; underscore.string-3.3.4/.npmignore0000644000175600017570000000003512663266217016250 0ustar pravipravitests bench coverage scripts underscore.string-3.3.4/dasherize.js0000644000175600017570000000024312663266217016566 0ustar pravipravivar trim = require('./trim'); module.exports = function dasherize(str) { return trim(str).replace(/([A-Z])/g, '-$1').replace(/[-_\s]+/g, '-').toLowerCase(); }; underscore.string-3.3.4/toNumber.js0000644000175600017570000000030312663266217016400 0ustar pravipravimodule.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; }; underscore.string-3.3.4/levenshtein.js0000644000175600017570000000241212663266217017134 0ustar pravipravivar 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; }; underscore.string-3.3.4/bench/0000755000175600017570000000000012663266217015332 5ustar pravipraviunderscore.string-3.3.4/bench/reverse.js0000644000175600017570000000014112663266217017337 0ustar pravipravivar reverse = require('../reverse'); module.exports = function() { reverse('Hello World'); }; underscore.string-3.3.4/bench/slugify.js0000644000175600017570000000016712663266217017356 0ustar pravipravivar slugify = require('../slugify'); module.exports = function() { slugify('Un éléphant à l\'orée du bois'); }; underscore.string-3.3.4/bench/escapeHTML.js0000644000175600017570000000017012663266217017613 0ustar pravipravivar escapeHTML = require('../escapeHTML'); module.exports = function() { escapeHTML('
Blah blah blah
'); }; underscore.string-3.3.4/bench/strLeft.js0000644000175600017570000000014612663266217017314 0ustar pravipravivar strLeft = require('../strLeft'); module.exports = function() { strLeft('aaa_bbb_ccc', '_'); }; underscore.string-3.3.4/bench/toNumber.js0000644000175600017570000000014512663266217017463 0ustar pravipravivar toNumber = require('../toNumber'); module.exports = function() { toNumber('10.232323', 2); }; underscore.string-3.3.4/bench/levenshtein.js0000644000175600017570000000044412663266217020216 0ustar pravipravivar levenshtein = require('../levenshtein'); module.exports = function() { levenshtein('pineapple', 'potato'); levenshtein('seven', 'eight'); levenshtein('the very same string', 'the very same string'); levenshtein('very very very long string', 'something completely different'); }; underscore.string-3.3.4/bench/prune.js0000644000175600017570000000013612663266217017021 0ustar pravipravivar prune = require('../prune'); module.exports = function() { prune('Hello world', 5); }; underscore.string-3.3.4/bench/strLeftBack.js0000644000175600017570000000016212663266217020073 0ustar pravipravivar strLeftBack = require('../strLeftBack'); module.exports = function() { strLeftBack('aaa_bbb_ccc', '_'); }; underscore.string-3.3.4/bench/succ.js0000644000175600017570000000032212663266217016622 0ustar pravipravivar succ = require('../succ'); module.exports = function() { var letter = 'a', alphabet = []; for (var i=0; i < 26; i++) { alphabet.push(letter); letter = succ(letter); } return alphabet; }; underscore.string-3.3.4/bench/splice.js0000644000175600017570000000023312663266217017145 0ustar pravipravivar splice = require('../splice'); module.exports = function() { splice('https://edtsech@bitbucket.org/edtsech/underscore.strings', 30, 7, 'epeli'); }; underscore.string-3.3.4/bench/unescapeHTML.js0000644000175600017570000000021212663266217020153 0ustar pravipravivar unescapeHTML = require('../unescapeHTML'); module.exports = function() { unescapeHTML('<div>Blah blah blah</div>'); }; underscore.string-3.3.4/bench/isBlank.js0000644000175600017570000000012612663266217017252 0ustar pravipravivar isBlank = require('../isBlank'); module.exports = function() { isBlank(''); }; underscore.string-3.3.4/bench/pad.js0000644000175600017570000000066612663266217016444 0ustar pravipravivar pad = require('../pad'); var tests = {}; tests['pad default'] = function(){ pad('foo', 12); }; tests['pad hash left'] = function(){ pad('foo', 12, '#'); }; tests['pad hash right'] = function(){ pad('foo', 12, '#', 'right'); }; tests['pad hash both'] = function(){ pad('foo', 12, '#', 'both'); }; tests['pad hash both longPad'] = function(){ pad('foo', 12, 'f00f00f00', 'both'); }; module.exports = { tests: tests }; underscore.string-3.3.4/bench/chop.js0000644000175600017570000000013212663266217016615 0ustar pravipravivar chop = require('../chop'); module.exports = function() { chop('whitespace', 2); }; underscore.string-3.3.4/bench/strRightBack.js0000644000175600017570000000016512663266217020261 0ustar pravipravivar strRightBack = require('../strRightBack'); module.exports = function() { strRightBack('aaa_bbb_ccc', '_'); }; underscore.string-3.3.4/bench/startsWith.js0000644000175600017570000000015412663266217020044 0ustar pravipravivar startsWith = require('../startsWith'); module.exports = function() { startsWith('foobar', 'foo'); }; underscore.string-3.3.4/bench/insert.js0000644000175600017570000000014512663266217017174 0ustar pravipravivar insert = require('../insert'); module.exports = function() { insert('Hello ', 6, 'world'); }; underscore.string-3.3.4/bench/count.js0000644000175600017570000000014012663266217017013 0ustar pravipravivar count = require('../count'); module.exports = function() { count('Hello worls', 'l'); }; underscore.string-3.3.4/bench/titleize.js0000644000175600017570000000016312663266217017521 0ustar pravipravivar titleize = require('../titleize'); module.exports = function() { titleize('the titleize string method'); }; underscore.string-3.3.4/bench/trim.js0000644000175600017570000000046512663266217016650 0ustar pravipravivar s = require('../'); var tests = {}; tests['trimNoNative'] = function() { return s.trim(' foobar ', ' '); }; tests['trim'] = function() { return s.trim(' foobar '); }; tests['trim object-oriented'] = function() { return s(' foobar ').trim().value(); }; module.exports = { tests: tests }; underscore.string-3.3.4/bench/endsWith.js0000644000175600017570000000014512663266217017455 0ustar pravipravivar endsWith = require('../endsWith'); module.exports = function() { endsWith('foobar', 'xx'); }; underscore.string-3.3.4/bench/strRight.js0000644000175600017570000000015112663266217017473 0ustar pravipravivar strRight = require('../strRight'); module.exports = function() { strRight('aaa_bbb_ccc', '_'); }; underscore.string-3.3.4/bench/join.js0000644000175600017570000000021212663266217016622 0ustar pravipravivar join = require('../join'); module.exports = function() { join('separator', 1, 2, 3, 4, 5, 6, 7, 8, 'foo', 'bar', 'lol', 'wut'); }; underscore.string-3.3.4/bench/truncate.js0000644000175600017570000000014712663266217017517 0ustar pravipravivar truncate = require('../truncate'); module.exports = function() { truncate('Hello world', 5); }; underscore.string-3.3.4/quote.js0000644000175600017570000000020612663266217015744 0ustar pravipravivar surround = require('./surround'); module.exports = function quote(str, quoteChar) { return surround(str, quoteChar || '"'); }; underscore.string-3.3.4/underscored.js0000644000175600017570000000026012663266217017124 0ustar pravipravivar trim = require('./trim'); module.exports = function underscored(str) { return trim(str).replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase(); }; underscore.string-3.3.4/prune.js0000644000175600017570000000161412663266217015744 0ustar pravipravi/** * _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; }; underscore.string-3.3.4/strLeftBack.js0000644000175600017570000000034412663266217017016 0ustar pravipravivar 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; }; underscore.string-3.3.4/toSentenceSerial.js0000644000175600017570000000024012663266217020054 0ustar pravipravivar toSentence = require('./toSentence'); module.exports = function toSentenceSerial(array, sep, lastSep) { return toSentence(array, sep, lastSep, true); }; underscore.string-3.3.4/chars.js0000644000175600017570000000020012663266217015701 0ustar pravipravivar makeString = require('./helper/makeString'); module.exports = function chars(str) { return makeString(str).split(''); }; underscore.string-3.3.4/rtrim.js0000644000175600017570000000064712663266217015755 0ustar pravipravivar 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 + '+$'), ''); }; underscore.string-3.3.4/tests/0000755000175600017570000000000012663266217015415 5ustar pravipraviunderscore.string-3.3.4/tests/map.js0000644000175600017570000000137612663266217016537 0ustar pravipravivar equal = require('assert').equal; var map = require('../map'); test('#map', function() { equal(map('Hello world', function(x) { return x; }), 'Hello world'); equal(map(12345, function(x) { return x; }), '12345'); equal(map('Hello world', function(x) { if (x === 'o') x = 'O'; return x; }), 'HellO wOrld'); equal(map('', function(x) { return x; }), ''); equal(map(null, function(x) { return x; }), ''); equal(map(undefined, function(x) { return x; }), ''); equal(map('Hello world', ''), 'Hello world'); equal(map('Hello world', null), 'Hello world'); equal(map('Hello world', undefined), 'Hello world'); equal(map('', ''), ''); equal(map(null, null), ''); equal(map(undefined, undefined), ''); }); underscore.string-3.3.4/tests/reverse.js0000644000175600017570000000112312663266217017423 0ustar pravipravivar equal = require('assert').equal; var reverse = require('../reverse'); test('#reverse', function() { equal(reverse('foo'), 'oof' ); equal(reverse('foobar'), 'raboof' ); equal(reverse('foo bar'), 'rab oof' ); equal(reverse('saippuakauppias'), 'saippuakauppias' ); equal(reverse(123), '321', 'Non string'); equal(reverse(123.45), '54.321', 'Non string'); equal(reverse(''), '', 'reversing empty string returns empty string' ); equal(reverse(null), '', 'reversing null returns empty string' ); equal(reverse(undefined), '', 'reversing undefined returns empty string' ); }); underscore.string-3.3.4/tests/slugify.js0000644000175600017570000000151412663266217017436 0ustar pravipravivar equal = require('assert').equal; var slugify = require('../slugify'); test('#slugify', function() { equal(slugify('Jack & Jill like numbers 1,2,3 and 4 and silly characters ?%.$!/'), 'jack-jill-like-numbers-1-2-3-and-4-and-silly-characters'); equal(slugify('Un éléphant à l\'orée du bois'), 'un-elephant-a-l-oree-du-bois'); equal(slugify('I know latin characters: á í ó ú ç ã õ ñ ü ă ș ț'), 'i-know-latin-characters-a-i-o-u-c-a-o-n-u-a-s-t'); equal(slugify('I am a word too, even though I am but a single letter: i!'), 'i-am-a-word-too-even-though-i-am-but-a-single-letter-i'); equal(slugify('Some asian 天地人 characters'), 'some-asian-characters'); equal(slugify('SOME Capital Letters'), 'some-capital-letters'); equal(slugify(''), ''); equal(slugify(null), ''); equal(slugify(undefined), ''); }); underscore.string-3.3.4/tests/escapeHTML.js0000644000175600017570000000107612663266217017704 0ustar pravipravivar equal = require('assert').equal; var escapeHTML = require('../escapeHTML'); test('#escapeHTML', function(){ equal(escapeHTML('
Blah & "blah" & \'blah\'
'), '<div>Blah & "blah" & 'blah'</div>'); equal(escapeHTML('<'), '&lt;'); equal(escapeHTML(' '), ' '); equal(escapeHTML('¢'), '¢'); equal(escapeHTML('¢ £ ¥ € © ®'), '¢ £ ¥ € © ®'); equal(escapeHTML(5), '5'); equal(escapeHTML(''), ''); equal(escapeHTML(null), ''); equal(escapeHTML(undefined), ''); }); underscore.string-3.3.4/tests/strLeft.js0000644000175600017570000000110512663266217017373 0ustar pravipravivar equal = require('assert').equal; var strLeft = require('../strLeft'); test('#strLeft', function() { equal(strLeft('This_is_a_test_string', '_'), 'This'); equal(strLeft('This_is_a_test_string', 'This'), ''); equal(strLeft('This_is_a_test_string'), 'This_is_a_test_string'); equal(strLeft('This_is_a_test_string', ''), 'This_is_a_test_string'); equal(strLeft('This_is_a_test_string', '-'), 'This_is_a_test_string'); equal(strLeft('', 'foo'), ''); equal(strLeft(null, 'foo'), ''); equal(strLeft(undefined, 'foo'), ''); equal(strLeft(123454321, 3), '12'); }); underscore.string-3.3.4/tests/humanize.js0000644000175600017570000000147412663266217017601 0ustar pravipravivar equal = require('assert').equal; var humanize = require('../humanize'); test('#humanize', function(){ equal(humanize('the_humanize_string_method'), 'The humanize string method'); equal(humanize('ThehumanizeStringMethod'), 'Thehumanize string method'); equal(humanize('-ThehumanizeStringMethod'), 'Thehumanize string method'); equal(humanize('the humanize string method'), 'The humanize string method'); equal(humanize('the humanize_id string method_id'), 'The humanize id string method'); equal(humanize('the humanize string method '), 'The humanize string method'); equal(humanize(' capitalize dash-CamelCase_underscore trim '), 'Capitalize dash camel case underscore trim'); equal(humanize(123), '123'); equal(humanize(''), ''); equal(humanize(null), ''); equal(humanize(undefined), ''); }); underscore.string-3.3.4/tests/capitalize.js0000644000175600017570000000323712663266217020105 0ustar pravipravivar equal = require('assert').equal; var capitalize = require('../capitalize'); test('#capitalize', function() { equal(capitalize('fabio'), 'Fabio', 'First letter is upper case'); equal(capitalize('fabio'), 'Fabio', 'First letter is upper case'); equal(capitalize('FOO'), 'FOO', 'Other letters unchanged'); equal(capitalize('FOO', false), 'FOO', 'Other letters unchanged'); equal(capitalize('foO', false), 'FoO', 'Other letters unchanged'); equal(capitalize('FOO', true), 'Foo', 'Other letters are lowercased'); equal(capitalize('foO', true), 'Foo', 'Other letters are lowercased'); equal(capitalize('f', false), 'F', 'Should uppercase 1 letter'); equal(capitalize('f', true), 'F', 'Should uppercase 1 letter'); equal(capitalize('f'), 'F', 'Should uppercase 1 letter'); equal(capitalize(123), '123', 'Non string'); equal(capitalize(123, true), '123', 'Non string'); equal(capitalize(123, false), '123', 'Non string'); equal(capitalize(''), '', 'Capitalizing empty string returns empty string'); equal(capitalize(null), '', 'Capitalizing null returns empty string'); equal(capitalize(undefined), '', 'Capitalizing undefined returns empty string'); equal(capitalize('', true), '', 'Capitalizing empty string returns empty string'); equal(capitalize(null, true), '', 'Capitalizing null returns empty string'); equal(capitalize(undefined, true), '', 'Capitalizing undefined returns empty string'); equal(capitalize('', false), '', 'Capitalizing empty string returns empty string'); equal(capitalize(null, false), '', 'Capitalizing null returns empty string'); equal(capitalize(undefined, false), '', 'Capitalizing undefined returns empty string'); }); underscore.string-3.3.4/tests/standalone.js0000644000175600017570000000451412663266217020107 0ustar pravipravivar s = require('../'); var equal = require('assert').equal; var deepEqual = require('assert').deepEqual; var strictEqual = require('assert').strictEqual; test('provides standalone functions via the s global', function() { equal(typeof s.trim, 'function'); }); test('has standalone chaining', function() { var res = s(' foo ').trim().capitalize().value(); equal(res, 'Foo'); }); test('chaining supports tapping', function() { var res = s('foo').tap(function(value) { return 'BAR' + value + 'BAR'; }).value(); equal(res, 'BARfooBAR'); }); test('tap breaks the chain if the return value is not a string', function() { var res = s('foo').tap(function(value) { return value === 'foo'; }); strictEqual(res, true); }); test('chain objects are immutable', function() { var chain = s('foo'); chain.capitalize(); equal(chain.value(), 'foo'); }); test('methods returning non-string values stops the chain', function() { strictEqual(s('foobar').startsWith('foo'), true); strictEqual(s('foobar').endsWith('foo'), false); deepEqual(s('hello\nworld').lines(), ['hello', 'world']); }); test('prototype methods are available in the chain', function() { var chain = s('foo'); [ 'toUpperCase', 'toLowerCase', 'split', 'replace', 'slice', 'substring', 'substr', 'concat' ].forEach(function(method) { equal(typeof chain[method], 'function', 'has method: ' + method); }); }); test('PROTOTYPE: toUpperCase', function() { equal(s('foo').toUpperCase().value(), 'FOO'); }); test('PROTOTYPE: toLowerCase', function() { equal(s('BAR').toLowerCase().value(), 'bar'); }); test('PROTOTYPE: split', function() { deepEqual(s('foo bar').split(' '), ['foo', 'bar']); }); test('PROTOTYPE: replace', function() { equal(s('faa').replace('a', 'o').value(), 'foa'); }); test('PROTOTYPE: slice', function() { equal(s('#anchor').slice(1).value(), 'anchor'); }); test('PROTOTYPE: substring', function() { equal(s('foobar').substring(0, 3).value(), 'foo'); }); test('PROTOTYPE: substring', function() { equal(s('foobar!').substr(3, 3).value(), 'bar'); }); test('PROTOTYPE: concat', function() { equal(s('foo').concat('bar').value(), 'foobar'); }); test('PROTOTYPE: can combine methods', function() { equal( s(' foo bar').toUpperCase().concat(' BAZ').clean().value(), 'FOO BAR BAZ' ); }); underscore.string-3.3.4/tests/decapitalize.js0000644000175600017570000000105512663266217020412 0ustar pravipravivar equal = require('assert').equal; var decapitalize = require('../decapitalize'); test('#decapitalize', function() { equal(decapitalize('Fabio'), 'fabio', 'First letter is lower case'); equal(decapitalize('FOO'), 'fOO', 'Other letters unchanged'); equal(decapitalize(123), '123', 'Non string'); equal(decapitalize(''), '', 'Decapitalizing empty string returns empty string'); equal(decapitalize(null), '', 'Decapitalizing null returns empty string'); equal(decapitalize(undefined), '', 'Decapitalizing undefined returns empty string'); }); underscore.string-3.3.4/tests/lines.js0000644000175600017570000000120312663266217017061 0ustar pravipravivar equal = require('assert').equal; var deepEqual = require('assert').deepEqual; var lines = require('../lines'); test('#lines', function() { equal(lines('Hello\nWorld').length, 2); equal(lines('Hello\rWorld').length, 2); equal(lines('Hello World').length, 1); equal(lines('\r\n\n\r').length, 4); equal(lines('Hello\r\r\nWorld').length, 3); equal(lines('Hello\r\rWorld').length, 3); equal(lines(123).length, 1); deepEqual(lines(''), ['']); deepEqual(lines(null), []); deepEqual(lines(undefined), []); deepEqual(lines('Hello\rWorld'), ['Hello', 'World']); deepEqual(lines('Hello\r\nWorld'), ['Hello', 'World']); }); underscore.string-3.3.4/tests/dasherize.js0000644000175600017570000000166712663266217017743 0ustar pravipravivar equal = require('assert').equal; var dasherize = require('../dasherize'); test('#dasherize', function(){ equal(dasherize('the_dasherize_string_method'), 'the-dasherize-string-method'); equal(dasherize('TheDasherizeStringMethod'), '-the-dasherize-string-method'); equal(dasherize('thisIsATest'), 'this-is-a-test'); equal(dasherize('this Is A Test'), 'this-is-a-test'); equal(dasherize('thisIsATest123'), 'this-is-a-test123'); equal(dasherize('123thisIsATest'), '123this-is-a-test'); equal(dasherize('the dasherize string method'), 'the-dasherize-string-method'); equal(dasherize('the dasherize string method '), 'the-dasherize-string-method'); equal(dasherize('téléphone'), 'téléphone'); equal(dasherize('foo$bar'), 'foo$bar'); equal(dasherize('input with a-dash'), 'input-with-a-dash'); equal(dasherize(''), ''); equal(dasherize(null), ''); equal(dasherize(undefined), ''); equal(dasherize(123), '123'); }); underscore.string-3.3.4/tests/toNumber.js0000644000175600017570000000234112663266217017546 0ustar pravipravivar equal = require('assert').equal; var ok = require('assert').ok; var _ = require('underscore'); var toNumber = require('../toNumber'); test('#toNumber', function() { _.each(['not a number', NaN, {}, [/a/], 'alpha6'], function(val) { ok(isNaN(toNumber('not a number'))); equal(toNumber(Math.PI, val), 3); }); equal(toNumber(0), 0); equal(toNumber('0'), 0); equal(toNumber('0.0'), 0); equal(toNumber(' 0.0 '), 0); equal(toNumber('0.1'), 0); equal(toNumber('0.1', 1), 0.1); equal(toNumber(' 0.1 ', 1), 0.1); equal(toNumber('0000'), 0); equal(toNumber('2.345'), 2); equal(toNumber('2.345', NaN), 2); equal(toNumber('2.345', 2), 2.35); equal(toNumber('2.344', 2), 2.34); equal(toNumber('2', 2), 2.00); equal(toNumber(2, 2), 2.00); equal(toNumber(-2), -2); equal(toNumber('-2'), -2); equal(toNumber(-2.5123, 3), -2.512); // Negative precisions equal(toNumber(-234, -1), -230); equal(toNumber(234, -2), 200); equal(toNumber('234', -2), 200); _.each(['', null, undefined], function(val) { equal(toNumber(val), 0); }); _.each([Infinity, -Infinity], function(val) { equal(toNumber(val), val); equal(toNumber(val, val), val); equal(toNumber(1, val), 1); }); }); underscore.string-3.3.4/tests/levenshtein.js0000644000175600017570000000150012663266217020273 0ustar pravipravivar equal = require('assert').equal; var levenshtein = require('../levenshtein'); test('#levenshtein', function() { equal(levenshtein('Godfather', 'Godfather'), 0); equal(levenshtein('Godfather', 'Godfathe'), 1); equal(levenshtein('Godfather', 'odfather'), 1); equal(levenshtein('Godfather', 'godfather'), 1); equal(levenshtein('Godfather', 'Gdfthr'), 3); equal(levenshtein('seven', 'eight'), 5); equal(levenshtein('123', 123), 0); equal(levenshtein(321, '321'), 0); equal(levenshtein('lol', null), 3); equal(levenshtein('lol'), 3); equal(levenshtein(null, 'lol'), 3); equal(levenshtein(undefined, 'lol'), 3); equal(levenshtein(), 0); }); test('#levenshtein non-latin', function() { equal(levenshtein('因為我是中國人所以我會說中文', '因為我是英國人所以我會說英文'), 2); }); underscore.string-3.3.4/tests/quote.js0000644000175600017570000000057312663266217017115 0ustar pravipravivar equal = require('assert').equal; var quote = require('../quote'); var q = require('../').q; test('#quote', function(){ equal(quote('foo'), '"foo"'); equal(quote('"foo"'), '""foo""'); equal(quote(1), '"1"'); equal(quote('foo', '\''), '\'foo\''); // alias equal(q('foo'), '"foo"'); equal(q(''), '""'); equal(q(null), '""'); equal(q(undefined), '""'); }); underscore.string-3.3.4/tests/underscored.js0000644000175600017570000000113312663266217020266 0ustar pravipravivar equal = require('assert').equal; var underscored = require('../underscored'); test('#underscored', function(){ equal(underscored('the-underscored-string-method'), 'the_underscored_string_method'); equal(underscored('theUnderscoredStringMethod'), 'the_underscored_string_method'); equal(underscored('TheUnderscoredStringMethod'), 'the_underscored_string_method'); equal(underscored(' the underscored string method'), 'the_underscored_string_method'); equal(underscored(''), ''); equal(underscored(null), ''); equal(underscored(undefined), ''); equal(underscored(123), '123'); }); underscore.string-3.3.4/tests/prune.js0000644000175600017570000000220012663266217017076 0ustar pravipravivar equal = require('assert').equal; var prune = require('../prune'); test('#prune', function(){ equal(prune('Hello, cruel world', 6, ' read more'), 'Hello read more'); equal(prune('Hello, world', 5, 'read a lot more'), 'Hello, world'); equal(prune('Hello, world', 5), 'Hello...'); equal(prune('Hello, world', 8), 'Hello...'); equal(prune('Hello, cruel world', 15), 'Hello, cruel...'); equal(prune('Hello world', 22), 'Hello world'); equal(prune('Привет, жестокий мир', 6, ' read more'), 'Привет read more'); equal(prune('Привет, мир', 6, 'read a lot more'), 'Привет, мир'); equal(prune('Привет, мир', 6), 'Привет...'); equal(prune('Привет, мир', 8), 'Привет...'); equal(prune('Привет, жестокий мир', 16), 'Привет, жестокий...'); equal(prune('Привет, мир', 22), 'Привет, мир'); equal(prune('alksjd!!!!!!....', 100, ''), 'alksjd!!!!!!....'); equal(prune(123, 10), '123'); equal(prune(123, 1, 321), '321'); equal(prune('', 5), ''); equal(prune(null, 5), ''); equal(prune(undefined, 5), ''); }); underscore.string-3.3.4/tests/strLeftBack.js0000644000175600017570000000120312663266217020153 0ustar pravipravivar equal = require('assert').equal; var strLeftBack = require('../strLeftBack'); test('#strLeftBack', function() { equal(strLeftBack('This_is_a_test_string', '_'), 'This_is_a_test'); equal(strLeftBack('This_is_a_test_string', 'This'), ''); equal(strLeftBack('This_is_a_test_string'), 'This_is_a_test_string'); equal(strLeftBack('This_is_a_test_string', ''), 'This_is_a_test_string'); equal(strLeftBack('This_is_a_test_string', '-'), 'This_is_a_test_string'); equal(strLeftBack('', 'foo'), ''); equal(strLeftBack(null, 'foo'), ''); equal(strLeftBack(undefined, 'foo'), ''); equal(strLeftBack(123454321, 3), '123454'); }); underscore.string-3.3.4/tests/toSentenceSerial.js0000644000175600017570000000055012663266217021222 0ustar pravipravivar equal = require('assert').equal; var toSentenceSerial = require('../toSentenceSerial'); test('#toSentenceSerial', function (){ equal(toSentenceSerial(['jQuery']), 'jQuery'); equal(toSentenceSerial(['jQuery', 'MooTools']), 'jQuery and MooTools'); equal(toSentenceSerial(['jQuery', 'MooTools', 'Prototype']), 'jQuery, MooTools, and Prototype'); }); underscore.string-3.3.4/tests/chars.js0000644000175600017570000000041612663266217017054 0ustar pravipravivar equal = require('assert').equal; var chars = require('../chars'); test('#chars', function() { equal(chars('Hello').length, 5); equal(chars(123).length, 3); equal(chars('').length, 0); equal(chars(null).length, 0); equal(chars(undefined).length, 0); }); underscore.string-3.3.4/tests/rtrim.js0000644000175600017570000000125612663266217017114 0ustar pravipravivar equal = require('assert').equal; var rtrim = require('../rtrim'); test('#rtrim', function() { equal(rtrim('http://foo/', '/'), 'http://foo', 'clean trailing slash'); equal(rtrim(' foo'), ' foo'); equal(rtrim('foo '), 'foo'); equal(rtrim('foo '), 'foo'); equal(rtrim('foo bar '), 'foo bar'); equal(rtrim(' foo '), ' foo'); equal(rtrim('ffoo', 'f'), 'ffoo'); equal(rtrim('ooff', 'f'), 'oo'); equal(rtrim('ffooff', 'f'), 'ffoo'); equal(rtrim('_-foobar-_', '_-'), '_-foobar'); equal(rtrim(123, 3), '12'); equal(rtrim(''), '', 'rtrim empty string should return empty string'); equal(rtrim(null), '', 'rtrim null should return empty string'); }); underscore.string-3.3.4/tests/succ.js0000644000175600017570000000076212663266217016715 0ustar pravipravivar equal = require('assert').equal; var deepEqual = require('assert').deepEqual; var succ = require('../succ'); test('#succ', function(){ equal(succ('a'), 'b'); equal(succ('A'), 'B'); equal(succ('+'), ','); equal(succ(1), '2'); deepEqual(succ().length, 0); deepEqual(succ('').length, 0); deepEqual(succ(null).length, 0); deepEqual(succ(undefined).length, 0); deepEqual(succ(), ''); deepEqual(succ(''), ''); deepEqual(succ(null), ''); deepEqual(succ(undefined), ''); }); underscore.string-3.3.4/tests/numberFormat.js0000644000175600017570000000171712663266217020422 0ustar pravipravivar equal = require('assert').equal; var numberFormat = require('../numberFormat'); test('#numberFormat', function() { equal(numberFormat(9000), '9,000'); equal(numberFormat(9000, 0), '9,000'); equal(numberFormat(9000, 0, '', ''), '9000'); equal(numberFormat(90000, 2), '90,000.00'); equal(numberFormat(1000.754), '1,001'); equal(numberFormat(1000.754, 2), '1,000.75'); equal(numberFormat(1000.755, 2), '1,000.75'); equal(numberFormat(1000.756, 2), '1,000.76'); equal(numberFormat(1000.754, 0, ',', '.'), '1.001'); equal(numberFormat(1000.754, 2, ',', '.'), '1.000,75'); equal(numberFormat(1000000.754, 2, ',', '.'), '1.000.000,75'); equal(numberFormat(1000000000), '1,000,000,000'); equal(numberFormat(100000000), '100,000,000'); equal(numberFormat('not number'), ''); equal(numberFormat(), ''); equal(numberFormat(null, '.', ','), ''); equal(numberFormat(undefined, '.', ','), ''); equal(numberFormat(new Number(5000)), '5,000'); }); underscore.string-3.3.4/tests/splice.js0000644000175600017570000000050712663266217017234 0ustar pravipravivar equal = require('assert').equal; var splice = require('../splice'); test('#splice', function(){ equal(splice('https://edtsech@bitbucket.org/edtsech/underscore.strings', 30, 7, 'epeli'), 'https://edtsech@bitbucket.org/epeli/underscore.strings'); equal(splice(12345, 1, 2, 321), '132145', 'Non strings'); }); underscore.string-3.3.4/tests/unescapeHTML.js0000644000175600017570000000245012663266217020244 0ustar pravipravivar equal = require('assert').equal; var unescapeHTML = require('../unescapeHTML'); test('#unescapeHTML', function(){ equal(unescapeHTML('<div>Blah & "blah" & 'blah'</div>'), '
Blah & "blah" & \'blah\'
'); equal(unescapeHTML('&lt;'), '<'); equal(unescapeHTML('''), '\''); equal(unescapeHTML('''), '\''); equal(unescapeHTML('''), '\''); equal(unescapeHTML('J'), 'J'); equal(unescapeHTML('J'), 'J'); equal(unescapeHTML('J'), 'J'); equal(unescapeHTML('&_#39;'), '&_#39;'); equal(unescapeHTML(''_;'), ''_;'); equal(unescapeHTML('&#38;'), '&'); equal(unescapeHTML('&amp;'), '&'); equal(unescapeHTML('''), '\''); equal(unescapeHTML(''), ''); equal(unescapeHTML(' '), ' '); equal(unescapeHTML('what is the ¥ to £ to € conversion process?'), 'what is the ¥ to £ to € conversion process?'); equal(unescapeHTML('® trademark'), '® trademark'); equal(unescapeHTML('© 1992. License available for 50 ¢'), '© 1992. License available for 50 ¢'); equal(unescapeHTML(' '), ' '); equal(unescapeHTML(' '), ' '); equal(unescapeHTML(null), ''); equal(unescapeHTML(undefined), ''); equal(unescapeHTML(5), '5'); }); underscore.string-3.3.4/tests/wrap.js0000644000175600017570000000474112663266217016732 0ustar pravipravivar equal = require('assert').equal; var wrap = require('../wrap'); test('#wrap', function(){ // without trailing spaces equal(wrap('My name is', { width: 2, seperator:'.', cut:false, trailingSpaces:false } ), 'My.name.is', 'works with width 2 and cut = false'); equal(wrap('My name is', { width: 2, seperator:'.', cut:true, trailingSpaces:false } ), 'My. n.am.e .is', 'works with width 2 and cut = true'); equal(wrap('My name is', { width: 3, seperator:'.', cut:false, trailingSpaces:false } ), 'My.name.is', 'works with width 3 and cut = true'); equal(wrap('My name is', { width: 3, seperator:'.', cut:true, trailingSpaces:false } ), 'My .nam.e i.s', 'works with width 3 and cut = true'); // with trailing spaces equal(wrap('My name is', { width: 2, seperator:'.', cut:false, trailingSpaces:true } ), 'My.name.is', 'works with width 2 and cut = false and trailingSpaces = true'); equal(wrap('My name is', { width: 2, seperator:'.', cut:true, trailingSpaces:true } ), 'My. n.am.e .is', 'works with width 2 and cut = true and trailingSpaces = true'); equal(wrap('My name is', { width: 3, seperator:'.', cut:false, trailingSpaces:true } ), 'My .name.is ', 'works with width 3 and cut = true and trailingSpaces = true'); equal(wrap('My name is', { width: 3, seperator:'.', cut:true, trailingSpaces:true } ), 'My .nam.e i.s ', 'works with width 3 and cut = true and trailingSpaces = true'); // with preserveSpaces equal(wrap('My name is', {width: 2, seperator:'.', cut:false, preserveSpaces:true }), 'My .name .is', 'preserve spaces keeps the space at the end of a line'); equal(wrap('My name is', {width: 3, seperator:'.', cut:false, preserveSpaces:true }), 'My .name .is', 'preserve spaces keeps the space at the end of a line'); // with preserveSpaces and trailingSpaces equal(wrap('My name is', {width: 2, seperator:'.', cut:false, preserveSpaces:true, trailingSpaces:true }), 'My .name .is', 'preserve spaces takes precedence over trailing spaces'); // defaults equal(wrap('My name is', { width: 3 } ), 'My\nname\nis', 'Default parameters work'); equal(wrap('My name is'), 'My name is', 'Default parameters work'); equal(wrap('', { width: 5 } ), '', 'Empty string'); equal(wrap('My name is', { width: 0 } ), 'My name is', 'Just return original line if width <= 0'); equal(wrap('My name is', { width: -1 } ), 'My name is', 'Just return original line if width <= 0'); equal(wrap(null, { width: 5 } ), '', 'null'); equal(wrap(undefined, { width: 5 } ), '', 'undefined'); }); underscore.string-3.3.4/tests/naturalCmp.js0000644000175600017570000000177012663266217020066 0ustar pravipravivar naturalCmp = require('../naturalCmp'); var _ = require('underscore'); var equal = require('assert').equal; test('#naturalCmp', function() { // Should be associative _.each([ ['abc', null], ['abc', '123'], ['def', 'abc'], ['ab', 'a'], ['r69', 'r9'], ['123', '122'], ['ac2', 'ab3'], ['a-12', 'a-11'], ['11', '-12'], ['15.05', '15'], ['15ac', '15ab32'], ['16', '15ab'], ['15a123', '15a122'], ['15ab16', '15ab'], ['abc', 'Abc'], ['abc', 'aBc'], ['aBc', 'Abc'] ], function(vals) { var a = vals[0], b = vals[1]; equal(naturalCmp(a, b), 1, '\'' + a + '\' >= \'' + b + '\''); equal(naturalCmp(b, a), -1, '\'' + b + '\' <= \'' + a + '\''); }); _.each([ ['123', '123'], ['abc', 'abc'], ['r12', 'r12'], ['12a', '12a'] ], function(vals) { var a = vals[0], b = vals[1]; equal(naturalCmp(a, b), 0, '\'' + a + '\' == \'' + b + '\''); equal(naturalCmp(b, a), 0, '\'' + b + '\' == \'' + a + '\''); }); }); underscore.string-3.3.4/tests/rpad.js0000644000175600017570000000060212663266217016677 0ustar pravipravivar equal = require('assert').equal; var rpad = require('../rpad'); test('#rpad', function() { equal(rpad('1', 8), '1 '); equal(rpad(1, 8), '1 '); equal(rpad('1', 8, '0'), '10000000'); equal(rpad('foo', 8, '0'), 'foo00000'); equal(rpad('foo', 7, '0'), 'foo0000'); equal(rpad('', 2), ' '); equal(rpad(null, 2), ' '); equal(rpad(undefined, 2), ' '); }); underscore.string-3.3.4/tests/swapCase.js0000644000175600017570000000045312663266217017523 0ustar pravipravivar equal = require('assert').equal; var swapCase = require('../swapCase'); test('#swapCase', function(){ equal(swapCase('AaBbCcDdEe'), 'aAbBcCdDeE'); equal(swapCase('Hello World'), 'hELLO wORLD'); equal(swapCase(''), ''); equal(swapCase(null), ''); equal(swapCase(undefined), ''); }); underscore.string-3.3.4/tests/cleanDiacritics.js0000644000175600017570000000146412663266217021041 0ustar pravipravi var equal = require('assert').equal; var cleanDiacritics = require('../cleanDiacritics'); var from = 'ąàáäâãåæăćčĉęèéëêĝĥìíïîĵłľńňòóöőôõðøśșşšŝťțţŭùúüűûñÿýçżźž', to = 'aaaaaaaaaccceeeeeghiiiijllnnoooooooossssstttuuuuuunyyczzz'; test('#cleanDiacritics', function() { equal(cleanDiacritics(from), to); equal(cleanDiacritics(from.toUpperCase()), to.toUpperCase()); equal(cleanDiacritics('ä'), 'a'); equal(cleanDiacritics('Ä Ø'), 'A O'); equal(cleanDiacritics('1 foo ääkkönen'), '1 foo aakkonen'); equal(cleanDiacritics('Äöö ÖÖ'), 'Aoo OO'); equal(cleanDiacritics(' ä '), ' a '); equal(cleanDiacritics('- " , £ $ ä'), '- " , £ $ a'); equal(cleanDiacritics('ß'), 'ss'); equal(cleanDiacritics('Schuß'), 'Schuss'); }); underscore.string-3.3.4/tests/exports.js0000644000175600017570000000042512663266217017460 0ustar pravipravivar _ = require('underscore'); var deepEqual = require('assert').deepEqual; var s = require('../'); test('#exports', function() { deepEqual(_.intersection(Object.keys(s.exports()), _.functions(_)), [], 'Conflicts exist between exports and underscore functions' ); }); underscore.string-3.3.4/tests/isBlank.js0000644000175600017570000000047212663266217017341 0ustar pravipravivar ok = require('assert').ok; var isBlank = require('../isBlank'); test('#isBlank', function(){ ok(isBlank('')); ok(isBlank(' ')); ok(isBlank('\n')); ok(!isBlank('a')); ok(!isBlank('0')); ok(!isBlank(0)); ok(isBlank('')); ok(isBlank(null)); ok(isBlank(undefined)); ok(!isBlank(false)); }); underscore.string-3.3.4/tests/replaceAll.js0000644000175600017570000000137312663266217020023 0ustar pravipravivar equal = require('assert').equal; var replaceAll = require('../replaceAll'); test('#replaceAll', function(){ equal(replaceAll('a', 'a', 'b'), 'b'); equal(replaceAll('aa', 'a', 'b'), 'bb'); equal(replaceAll('aca', 'a', 'b'), 'bcb'); equal(replaceAll('ccc', 'a', 'b'), 'ccc'); equal(replaceAll('AAa', 'a', 'b'), 'AAb'); equal(replaceAll('Aa', 'a', 'b', true), 'bb'); equal(replaceAll('foo bar foo', 'foo', 'moo'), 'moo bar moo'); equal(replaceAll('foo bar\n foo', 'foo', 'moo'), 'moo bar\n moo'); equal(replaceAll('foo bar FoO', 'foo', 'moo', true), 'moo bar moo'); equal(replaceAll('', 'a', 'b'), ''); equal(replaceAll(null, 'a', 'b'), ''); equal(replaceAll(undefined, 'a', 'b'), ''); equal(replaceAll(12345, 'a', 'b'), 12345); }); underscore.string-3.3.4/tests/lrpad.js0000644000175600017570000000070212663266217017054 0ustar pravipravivar equal = require('assert').equal; var lrpad = require('../lrpad'); test('#lrpad', function() { equal(lrpad('1', 8), ' 1 '); equal(lrpad(1, 8), ' 1 '); equal(lrpad('1', 8, '0'), '00001000'); equal(lrpad('foo', 8, '0'), '000foo00'); equal(lrpad('foo', 7, '0'), '00foo00'); equal(lrpad('foo', 7, '!@$%dofjrofj'), '!!foo!!'); equal(lrpad('', 2), ' '); equal(lrpad(null, 2), ' '); equal(lrpad(undefined, 2), ' '); }); underscore.string-3.3.4/tests/toBoolean.js0000644000175600017570000000231712663266217017700 0ustar pravipravivar strictEqual = require('assert').strictEqual; var toBoolean = require('../toBoolean'); test('#toBoolean', function() { strictEqual(toBoolean('false'), false); strictEqual(toBoolean('false'), false); strictEqual(toBoolean('False'), false); strictEqual(toBoolean('Falsy',null,['false', 'falsy']), false); strictEqual(toBoolean('true'), true); strictEqual(toBoolean('the truth', 'the truth', 'this is falsy'), true); strictEqual(toBoolean('this is falsy', 'the truth', 'this is falsy'), false); strictEqual(toBoolean('true'), true); strictEqual(toBoolean('trUe'), true); strictEqual(toBoolean('trUe', /tru?/i), true); strictEqual(toBoolean('something else'), undefined); strictEqual(toBoolean(function(){}), true); strictEqual(toBoolean(/regexp/), true); strictEqual(toBoolean(''), undefined); strictEqual(toBoolean(0), false); strictEqual(toBoolean(1), true); strictEqual(toBoolean('1'), true); strictEqual(toBoolean('0'), false); strictEqual(toBoolean(2), undefined); strictEqual(toBoolean('foo true bar'), undefined); strictEqual(toBoolean('foo true bar', /true/), true); strictEqual(toBoolean('foo FALSE bar', null, /FALSE/), false); strictEqual(toBoolean(' true '), true); }); underscore.string-3.3.4/tests/pad.js0000644000175600017570000000112012663266217016511 0ustar pravipravivar equal = require('assert').equal; var pad = require('../pad'); test('#pad', function() { equal(pad('1', 8), ' 1'); equal(pad(1, 8), ' 1'); equal(pad('1', 8, '0'), '00000001'); equal(pad('1', 8, '0', 'left'), '00000001'); equal(pad('1', 8, '0', 'right'), '10000000'); equal(pad('1', 8, '0', 'both'), '00001000'); equal(pad('foo', 8, '0', 'both'), '000foo00'); equal(pad('foo', 7, '0', 'both'), '00foo00'); equal(pad('foo', 7, '!@$%dofjrofj', 'both'), '!!foo!!'); equal(pad('', 2), ' '); equal(pad(null, 2), ' '); equal(pad(undefined, 2), ' '); }); underscore.string-3.3.4/tests/camelize.js0000644000175600017570000000407112663266217017546 0ustar pravipravivar equal = require('assert').equal; var camelize = require('../camelize'); test('#camelize', function(){ equal(camelize('the_camelize_string_method'), 'theCamelizeStringMethod'); equal(camelize('webkit-transform'), 'webkitTransform'); equal(camelize('-the-camelize-string-method'), 'TheCamelizeStringMethod'); equal(camelize('_the_camelize_string_method'), 'TheCamelizeStringMethod'); equal(camelize('The-camelize-string-method'), 'TheCamelizeStringMethod'); equal(camelize('the camelize string method'), 'theCamelizeStringMethod'); equal(camelize(' the camelize string method'), 'theCamelizeStringMethod'); equal(camelize('the camelize string method'), 'theCamelizeStringMethod'); equal(camelize(' with spaces'), 'withSpaces'); equal(camelize('_som eWeird---name-'), 'SomEWeirdName'); equal(camelize(''), '', 'Camelize empty string returns empty string'); equal(camelize(null), '', 'Camelize null returns empty string'); equal(camelize(undefined), '', 'Camelize undefined returns empty string'); equal(camelize(123), '123'); equal(camelize('the_camelize_string_method', true), 'theCamelizeStringMethod'); equal(camelize('webkit-transform', true), 'webkitTransform'); equal(camelize('-the-camelize-string-method', true), 'theCamelizeStringMethod'); equal(camelize('_the_camelize_string_method', true), 'theCamelizeStringMethod'); equal(camelize('The-camelize-string-method', true), 'theCamelizeStringMethod'); equal(camelize('the camelize string method', true), 'theCamelizeStringMethod'); equal(camelize(' the camelize string method', true), 'theCamelizeStringMethod'); equal(camelize('the camelize string method', true), 'theCamelizeStringMethod'); equal(camelize(' with spaces', true), 'withSpaces'); equal(camelize('_som eWeird---name-', true), 'somEWeirdName'); equal(camelize('', true), '', 'Camelize empty string returns empty string'); equal(camelize(null, true), '', 'Camelize null returns empty string'); equal(camelize(undefined, true), '', 'Camelize undefined returns empty string'); equal(camelize(123, true), '123'); }); underscore.string-3.3.4/tests/chop.js0000644000175600017570000000063612663266217016711 0ustar pravipravivar ok = require('assert').ok; var chop = require('../chop'); test('#chop', function(){ ok(chop(null, 2).length === 0, 'output []'); ok(chop('whitespace', 2).length === 5, 'output [wh, it, es, pa, ce]'); ok(chop('whitespace', 3).length === 4, 'output [whi, tes, pac, e]'); ok(chop('whitespace')[0].length === 10, 'output [whitespace]'); ok(chop(12345, 1).length === 5, 'output [1, 2, 3, 4, 5]'); }); underscore.string-3.3.4/tests/sprintf.js0000644000175600017570000000133412663266217017441 0ustar pravipravivar equal = require('assert').equal; var sprintf = require('../sprintf'); test('#sprintf', function() { // Should be very tested function already. Thanks to // http://www.diveintojavascript.com/projects/sprintf-for-javascript equal(sprintf('Hello %s', 'me'), 'Hello me', 'basic'); equal(sprintf('Hello %s', 'me'), 'Hello me', 'object'); equal(sprintf('%.1f', 1.22222), '1.2', 'round'); equal(sprintf('%.1f', 1.17), '1.2', 'round 2'); equal(sprintf('%(id)d - %(name)s', {id: 824, name: 'Hello World'}), '824 - Hello World', 'Named replacements work'); equal(sprintf('%(args[0].id)d - %(args[1].name)s', {args: [{id: 824}, {name: 'Hello World'}]}), '824 - Hello World', 'Named replacements with arrays work'); }); underscore.string-3.3.4/tests/strRightBack.js0000644000175600017570000000120212663266217020335 0ustar pravipravivar equal = require('assert').equal; var strRightBack = require('../strRightBack'); test('#strRightBack', function() { equal(strRightBack('This_is_a_test_string', '_'), 'string'); equal(strRightBack('This_is_a_test_string', 'string'), ''); equal(strRightBack('This_is_a_test_string'), 'This_is_a_test_string'); equal(strRightBack('This_is_a_test_string', ''), 'This_is_a_test_string'); equal(strRightBack('This_is_a_test_string', '-'), 'This_is_a_test_string'); equal(strRightBack('', 'foo'), ''); equal(strRightBack(null, 'foo'), ''); equal(strRightBack(undefined, 'foo'), ''); equal(strRightBack(12345, 2), '345'); }); underscore.string-3.3.4/tests/startsWith.js0000644000175600017570000000353712663266217020137 0ustar pravipravivar ok = require('assert').ok; var strictEqual = require('assert').strictEqual; var startsWith = require('../startsWith'); test('#startsWith', function() { ok(startsWith('foobar', 'foo'), 'foobar starts with foo'); ok(!startsWith('oobar', 'foo'), 'oobar does not start with foo'); ok(startsWith('oobar', 'o'), 'oobar starts with o'); ok(startsWith(12345, 123), '12345 starts with 123'); ok(!startsWith(2345, 123), '2345 does not start with 123'); ok(startsWith('', ''), 'empty string starts with empty string'); ok(startsWith(null, ''), 'null starts with empty string'); ok(!startsWith(null, 'foo'), 'null starts with foo'); ok(startsWith('-foobar', 'foo', 1), 'foobar starts with foo at position 1'); ok(startsWith('foobar', 'foo', 0), 'foobar starts with foo at position 0'); ok(!startsWith('foobar', 'foo', 1), 'foobar starts not with foo at position 1'); ok(startsWith('Äpfel', 'Ä'), 'string starts with a unicode'); strictEqual(startsWith('hello', 'hell'), true); strictEqual(startsWith('HELLO', 'HELL'), true); strictEqual(startsWith('HELLO', 'hell'), false); strictEqual(startsWith('HELLO', 'hell'), false); strictEqual(startsWith('hello', 'hell', 0), true); strictEqual(startsWith('HELLO', 'HELL', 0), true); strictEqual(startsWith('HELLO', 'hell', 0), false); strictEqual(startsWith('HELLO', 'hell', 0), false); strictEqual(startsWith('HELLO'), false); strictEqual(startsWith('undefined'), true); strictEqual(startsWith('null', null), true); strictEqual(startsWith('hello', 'hell', -20), true); strictEqual(startsWith('hello', 'hell', 1), false); strictEqual(startsWith('hello', 'hell', 2), false); strictEqual(startsWith('hello', 'hell', 3), false); strictEqual(startsWith('hello', 'hell', 4), false); strictEqual(startsWith('hello', 'hell', 5), false); strictEqual(startsWith('hello', 'hell', 20), false); }); underscore.string-3.3.4/tests/insert.js0000644000175600017570000000100012663266217017246 0ustar pravipravivar equal = require('assert').equal; var insert = require('../insert'); test('#insert', function(){ equal(insert('Hello ', 6, 'Jessy'), 'Hello Jessy'); equal(insert('Hello', 0, 'Jessy '), 'Jessy Hello'); equal(insert('Hello ', 100, 'Jessy'), 'Hello Jessy'); equal(insert('', 100, 'Jessy'), 'Jessy'); equal(insert(null, 100, 'Jessy'), 'Jessy'); equal(insert(undefined, 100, 'Jessy'), 'Jessy'); equal(insert(12345, 5, 'Jessy'), '12345Jessy'); equal(insert(12345, 3, 'Jessy'), '123Jessy45'); }); underscore.string-3.3.4/tests/pred.js0000644000175600017570000000076212663266217016712 0ustar pravipravivar equal = require('assert').equal; var deepEqual = require('assert').deepEqual; var pred = require('../pred'); test('#pred', function(){ equal(pred('b'), 'a'); equal(pred('B'), 'A'); equal(pred(','), '+'); equal(pred(2), '1'); deepEqual(pred().length, 0); deepEqual(pred('').length, 0); deepEqual(pred(null).length, 0); deepEqual(pred(undefined).length, 0); deepEqual(pred(), ''); deepEqual(pred(''), ''); deepEqual(pred(null), ''); deepEqual(pred(undefined), ''); }); underscore.string-3.3.4/tests/count.js0000644000175600017570000000117712663266217017111 0ustar pravipravivar equal = require('assert').equal; var count = require('../count'); test('#count', function(){ equal(count('Hello world', 'l'), 3); equal(count('Hello world', 'Hello'), 1); equal(count('Hello world', 'foo'), 0); equal(count('x.xx....x.x', 'x'), 5); equal(count('', 'x'), 0); equal(count(null, 'x'), 0); equal(count(undefined, 'x'), 0); equal(count(12345, 1), 1); equal(count(11345, 1), 2); equal(count('Hello World', ''), 0); equal(count('Hello World', null), 0); equal(count('Hello World', undefined), 0); equal(count('', ''), 0); equal(count(null, null), 0); equal(count(undefined, undefined), 0); }); underscore.string-3.3.4/tests/dedent.js0000644000175600017570000000322712663266217017222 0ustar pravipravivar equal = require('assert').equal; var deepEqual = require('assert').deepEqual; var dedent = require('../dedent'); test('#dedent', function() { equal(dedent('Hello\nWorld'), 'Hello\nWorld'); equal(dedent('Hello\t\nWorld'), 'Hello\t\nWorld'); equal(dedent('Hello \nWorld'), 'Hello \nWorld'); equal(dedent('Hello\n World'), 'Hello\n World'); equal(dedent(' Hello\n World'), ' Hello\nWorld'); equal(dedent(' Hello\nWorld'), ' Hello\nWorld'); equal(dedent(' Hello World'), 'Hello World'); equal(dedent(' Hello\n World'), 'Hello\nWorld'); equal(dedent(' Hello\n World'), 'Hello\n World'); equal(dedent('\t\tHello\tWorld'), 'Hello\tWorld'); equal(dedent('\t\tHello\n\t\tWorld'), 'Hello\nWorld'); equal(dedent('Hello\n\t\tWorld'), 'Hello\n\t\tWorld'); equal(dedent('\t\tHello\n\t\t\t\tWorld'), 'Hello\n\t\tWorld'); equal(dedent('\t\tHello\r\n\t\t\t\tWorld'), 'Hello\r\n\t\tWorld'); equal(dedent('\t\tHello\r\n\r\n\t\t\t\tWorld'), 'Hello\r\n\r\n\t\tWorld'); equal(dedent('\t\tHello\n\n\n\n\t\t\t\tWorld'), 'Hello\n\n\n\n\t\tWorld'); equal(dedent('\t\t\tHello\n\t\tWorld', '\\t'), '\t\tHello\n\tWorld'); equal(dedent(' Hello\n World', ' '), ' Hello\n World'); equal(dedent(' Hello\n World', ''), ' Hello\n World'); equal(dedent('\t\tHello\n\n\n\n\t\t\t\tWorld', '\\t'), '\tHello\n\n\n\n\t\t\tWorld'); equal(dedent('Hello\n\t\tWorld', '\t'), 'Hello\n\t\tWorld'); equal(dedent('Hello\n World', ' '), 'Hello\n World'); equal(dedent(' Hello\nWorld', ' '), ' Hello\nWorld'); deepEqual(dedent(123), '123'); deepEqual(dedent(''), ''); deepEqual(dedent(null), ''); deepEqual(dedent(undefined), ''); }); underscore.string-3.3.4/tests/naturalSort.js0000644000175600017570000000046212663266217020273 0ustar pravipravivar assert = require('assert'); var naturalCmp = require('../naturalCmp'); test('#naturalSort', function() { var arr = ['foo2', 'foo1', 'foo10', 'foo30', 'foo100', 'foo10bar'], sorted = ['foo1', 'foo2', 'foo10', 'foo10bar', 'foo30', 'foo100']; assert.deepEqual(arr.sort(naturalCmp), sorted); }); underscore.string-3.3.4/tests/escapeRegExp.js0000644000175600017570000000052112663266217020324 0ustar pravipravivar equal = require('assert').equal; var escapeRegExp = require('../helper/escapeRegExp'); test('#escapeRegExp', function(){ equal(escapeRegExp(/hello(?=\sworld)/.source), 'hello\\(\\?\\=\\\\sworld\\)', 'with lookahead'); equal(escapeRegExp(/hello(?!\shell)/.source), 'hello\\(\\?\\!\\\\shell\\)', 'with negative lookahead'); }); underscore.string-3.3.4/tests/titleize.js0000644000175600017570000000133612663266217017607 0ustar pravipravivar equal = require('assert').equal; var titleize = require('../titleize'); test('#titleize', function(){ equal(titleize('the titleize string method'), 'The Titleize String Method'); equal(titleize('the titleize string method'), 'The Titleize String Method'); equal(titleize(''), '', 'Titleize empty string returns empty string'); equal(titleize(null), '', 'Titleize null returns empty string'); equal(titleize(undefined), '', 'Titleize undefined returns empty string'); equal(titleize('let\'s have some fun'), 'Let\'s Have Some Fun'); equal(titleize('a-dash-separated-string'), 'A-Dash-Separated-String'); equal(titleize('A-DASH-SEPARATED-STRING'), 'A-Dash-Separated-String'); equal(titleize(123), '123'); }); underscore.string-3.3.4/tests/unquote.js0000644000175600017570000000037612663266217017461 0ustar pravipravivar equal = require('assert').equal; var unquote = require('../unquote'); test('#unquote', function(){ equal(unquote('"foo"'), 'foo'); equal(unquote('""foo""'), '"foo"'); equal(unquote('"1"'), '1'); equal(unquote('\'foo\'', '\''), 'foo'); }); underscore.string-3.3.4/tests/ltrim.js0000644000175600017570000000120312663266217017076 0ustar pravipravivar equal = require('assert').equal; var ltrim = require('../ltrim'); test('#ltrim', function() { equal(ltrim(' foo'), 'foo'); equal(ltrim(' foo'), 'foo'); equal(ltrim('foo '), 'foo '); equal(ltrim(' foo '), 'foo '); equal(ltrim(''), '', 'ltrim empty string should return empty string'); equal(ltrim(null), '', 'ltrim null should return empty string'); equal(ltrim(undefined), '', 'ltrim undefined should return empty string'); equal(ltrim('ffoo', 'f'), 'oo'); equal(ltrim('ooff', 'f'), 'ooff'); equal(ltrim('ffooff', 'f'), 'ooff'); equal(ltrim('_-foobar-_', '_-'), 'foobar-_'); equal(ltrim(123, 1), '23'); }); underscore.string-3.3.4/tests/lpad.js0000644000175600017570000000053712663266217016700 0ustar pravipravivar equal = require('assert').equal; var lpad = require('../lpad'); test('#lpad', function() { equal(lpad('1', 8), ' 1'); equal(lpad(1, 8), ' 1'); equal(lpad('1', 8, '0'), '00000001'); equal(lpad('1', 8, '0', 'left'), '00000001'); equal(lpad('', 2), ' '); equal(lpad(null, 2), ' '); equal(lpad(undefined, 2), ' '); }); underscore.string-3.3.4/tests/toSentence.js0000644000175600017570000000124612663266217020065 0ustar pravipravivar equal = require('assert').equal; var toSentence = require('../toSentence'); test('#toSentence', function() { equal(toSentence(['jQuery']), 'jQuery', 'array with a single element'); equal(toSentence(['jQuery', 'MooTools']), 'jQuery and MooTools', 'array with two elements'); equal(toSentence(['jQuery', 'MooTools', 'Prototype']), 'jQuery, MooTools and Prototype', 'array with three elements'); equal(toSentence(['jQuery', 'MooTools', 'Prototype', 'YUI']), 'jQuery, MooTools, Prototype and YUI', 'array with multiple elements'); equal(toSentence(['jQuery', 'MooTools', 'Prototype'], ',', ' or '), 'jQuery,MooTools or Prototype', 'handles custom separators'); }); underscore.string-3.3.4/tests/trim.js0000644000175600017570000000162212663266217016727 0ustar pravipravivar trim = require('../trim'); var equal = require('assert').equal; test('#trim', function() { equal(trim(123), '123', 'Non string'); equal(trim(' foo'), 'foo'); equal(trim('foo '), 'foo'); equal(trim(' foo '), 'foo'); equal(trim(' foo '), 'foo'); equal(trim(' foo '), 'foo', 'Manually set whitespace'); equal(trim('\t foo \t '), 'foo', 'Manually set RegExp /\\s+/'); equal(trim('ffoo', 'ff'), 'oo'); equal(trim('ooff', 'ff'), 'oo'); equal(trim('ffooff', 'ff'), 'oo'); equal(trim('_-foobar-_', '_-'), 'foobar'); equal(trim('http://foo/', '/'), 'http://foo'); equal(trim('c:\\', '\\'), 'c:'); equal(trim(123), '123'); equal(trim(123, 3), '12'); equal(trim(''), '', 'Trim empty string should return empty string'); equal(trim(null), '', 'Trim null should return empty string'); equal(trim(undefined), '', 'Trim undefined should return empty string'); }); underscore.string-3.3.4/tests/stripTags.js0000644000175600017570000000075412663266217017741 0ustar pravipravivar equal = require('assert').equal; var stripTags = require('../stripTags'); test('#stripTags', function() { equal(stripTags('a link'), 'a link'); equal(stripTags('a link"); // => "a linkalert("hello world!")" ``` #### toSentence(array, [delimiter, lastDelimiter]) => string Join an array into a human readable sentence. ```javascript toSentence(["jQuery", "Mootools", "Prototype"]); // => "jQuery, Mootools and Prototype"; toSentence(["jQuery", "Mootools", "Prototype"], ", ", " unt "); // => "jQuery, Mootools unt Prototype"; ``` #### toSentenceSerial(array, [delimiter, lastDelimiter]) => string The same as `toSentence`, but adjusts delimeters to use [Serial comma](http://en.wikipedia.org/wiki/Serial_comma). ```javascript toSentenceSerial(["jQuery", "Mootools"]); // => "jQuery and Mootools" toSentenceSerial(["jQuery", "Mootools", "Prototype"]); // => "jQuery, Mootools, and Prototype" toSentenceSerial(["jQuery", "Mootools", "Prototype"], ", ", " unt "); // => "jQuery, Mootools, unt Prototype" ``` #### repeat(string, count, [separator]) => string Repeats a string count times. ```javascript repeat("foo", 3); // => "foofoofoo" repeat("foo", 3, "bar"); // => "foobarfoobarfoo" ``` #### surround(string, wrap) => string Surround a string with another string. ```javascript surround("foo", "ab"); // => "abfooab" ``` #### quote(string, quoteChar) or q(string, quoteChar) => string Quotes a string. `quoteChar` defaults to `"`. ```javascript quote("foo", '"'); // => '"foo"'; ``` #### unquote(string, quoteChar) => string Unquotes a string. `quoteChar` defaults to `"`. ```javascript unquote('"foo"'); // => "foo" unquote("'foo'", "'"); // => "foo" ``` #### slugify(string) => string Transform text into an ascii slug which can be used in safely in URLs. Replaces whitespaces, accentuated, and special characters with a dash. Limited set of non-ascii characters are transformed to similar versions in the ascii character set such as `ä` to `a`. ```javascript slugify("Un éléphant à l\'orée du bois"); // => "un-elephant-a-l-oree-du-bois" ``` ***Caution: this function is charset dependent*** #### naturalCmp(string1, string2) => number Naturally sort strings like humans would do. None numbers are compared by their [ASCII values](http://www.asciitable.com/). Note: this means "a" > "A". Use `.toLowerCase` if this isn't to be desired. Just past it to `Array#sort`. ```javascript ["foo20", "foo5"].sort(naturalCmp); // => ["foo5", "foo20"] ``` #### toBoolean(string) => boolean Turn strings that can be commonly considered as booleas to real booleans. Such as "true", "false", "1" and "0". This function is case insensitive. ```javascript toBoolean("true"); // => true toBoolean("FALSE"); // => false toBoolean("random"); // => undefined ``` It can be customized by giving arrays of truth and falsy value matcher as parameters. Matchers can be also RegExp objects. ```javascript toBoolean("truthy", ["truthy"], ["falsy"]); // => true toBoolean("true only at start", [/^true/]); // => true ``` #### map(string, function) => string Creates a new string with the results of calling a provided function on every character of the given string. ```javascript map("Hello world", function(x) { return x; }); // => "Hello world" map(12345, function(x) { return x; }); // => "12345" map("Hello world", function(x) { if (x === 'o') x = 'O'; return x; }); // => "HellO wOrld" ``` ### Library functions If you require the full library you can use chaining and aliases #### s(string) => chain Start a chain. Returns an immutable chain object with the string functions as methods which return a new chain object instead of the plain string value. The chain object includes also following native Javascript string methods: - [toUpperCase](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase) - [toLowerCase](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase) - [split](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) - [replace](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) - [slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) - [substring](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/substring) - [substr](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) - [concat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat) #### chain.value() Return the string value from the chain ```javascript s(" foo ").trim().capitalize().value(); // => "Foo" ``` When calling a method which does not return a string the resulting value is immediately returned ```javascript s(" foobar ").trim().startsWith("foo"); // => true ``` #### chain.tap(function) => chain Tap into the chain with a custom function ```javascript s("foo").tap(function(value){ return value + "bar"; }).value(); // => "foobar" ``` #### Aliases ```javascript strip = trim lstrip = ltrim rstrip = rtrim center = lrpad rjust = lpad ljust = rpad contains = include q = quote toBool = toBoolean camelcase = camelize ``` ## Maintainers ## This library is maintained by - Esa-Matti Suuronen – ***[@epeli](https://github.com/epeli)*** - Christoph Hermann – ***[@stoeffel](https://github.com/stoeffel)*** ## Licence ## The MIT License Copyright (c) 2011 Esa-Matti Suuronen esa-matti@suuronen.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. [d]: http://www.diveintojavascript.com/core-javascript-reference/the-string-object underscore.string-3.3.4/clean.js0000644000175600017570000000016412663266217015674 0ustar pravipravivar trim = require('./trim'); module.exports = function clean(str) { return trim(str).replace(/\s\s+/g, ' '); }; underscore.string-3.3.4/endsWith.js0000644000175600017570000000067212663266217016403 0ustar pravipravivar 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; }; underscore.string-3.3.4/.travis.yml0000644000175600017570000000006312663266217016363 0ustar pravipravilanguage: node_js node_js: - "0.12" - "stable" underscore.string-3.3.4/words.js0000644000175600017570000000032012663266217015742 0ustar pravipravivar isBlank = require('./isBlank'); var trim = require('./trim'); module.exports = function words(str, delimiter) { if (isBlank(str)) return []; return trim(str, delimiter).split(delimiter || /\s+/); }; underscore.string-3.3.4/include.js0000644000175600017570000000027112663266217016234 0ustar pravipravivar makeString = require('./helper/makeString'); module.exports = function include(str, needle) { if (needle === '') return true; return makeString(str).indexOf(needle) !== -1; }; underscore.string-3.3.4/strRight.js0000644000175600017570000000037712663266217016426 0ustar pravipravivar 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; }; underscore.string-3.3.4/vsprintf.js0000644000175600017570000000030712663266217016464 0ustar pravipravivar 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.'); underscore.string-3.3.4/component.json0000644000175600017570000000051112663266217017145 0ustar pravipravi{ "name": "underscore.string", "repo": "epeli/underscore.string", "description": "String manipulation extensions for Underscore.js javascript library", "version": "3.3.4", "keywords": [ "underscore", "string" ], "dependencies": {}, "development": {}, "main": "index.js", "scripts": [ "*.js" ] } underscore.string-3.3.4/helper/0000755000175600017570000000000012663266217015532 5ustar pravipraviunderscore.string-3.3.4/helper/strRepeat.js0000644000175600017570000000030312663266217020035 0ustar pravipravimodule.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; }; underscore.string-3.3.4/helper/defaultToWhiteSpace.js0000644000175600017570000000041612663266217021775 0ustar pravipravivar escapeRegExp = require('./escapeRegExp'); module.exports = function defaultToWhiteSpace(characters) { if (characters == null) return '\\s'; else if (characters.source) return characters.source; else return '[' + escapeRegExp(characters) + ']'; }; underscore.string-3.3.4/helper/toPositive.js0000644000175600017570000000013412663266217020233 0ustar pravipravimodule.exports = function toPositive(number) { return number < 0 ? 0 : (+number || 0); }; underscore.string-3.3.4/helper/htmlEntities.js0000644000175600017570000000046012663266217020541 0ustar pravipravi/* 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; underscore.string-3.3.4/helper/escapeRegExp.js0000644000175600017570000000024412663266217020443 0ustar pravipravivar makeString = require('./makeString'); module.exports = function escapeRegExp(str) { return makeString(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1'); }; underscore.string-3.3.4/helper/escapeChars.js0000644000175600017570000000064312663266217020314 0ustar pravipravi/* 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; underscore.string-3.3.4/helper/adjacent.js0000644000175600017570000000040612663266217017641 0ustar pravipravivar 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); }; underscore.string-3.3.4/helper/makeString.js0000644000175600017570000000024112663266217020171 0ustar pravipravi/** * Ensure some object is a coerced to a string **/ module.exports = function makeString(object) { if (object == null) return ''; return '' + object; }; underscore.string-3.3.4/meteor-pre.js0000644000175600017570000000042712663266217016673 0ustar pravipravi// Defining this will trick dist/underscore.string.js into putting its exports into module.exports // Credit to Tim Heckel for this trick - see https://github.com/TimHeckel/meteor-underscore-string module = {}; // This also needed, otherwise above doesn't work??? exports = {}; underscore.string-3.3.4/join.js0000644000175600017570000000033412663266217015550 0ustar pravipravivar makeString = require('./helper/makeString'); var slice = [].slice; module.exports = function join() { var args = slice.call(arguments), separator = args.shift(); return args.join(makeString(separator)); }; underscore.string-3.3.4/truncate.js0000644000175600017570000000042112663266217016433 0ustar pravipravivar 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; }; underscore.string-3.3.4/repeat.js0000644000175600017570000000074012663266217016072 0ustar pravipravivar 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); }; underscore.string-3.3.4/surround.js0000644000175600017570000000014112663266217016466 0ustar pravipravimodule.exports = function surround(str, wrapper) { return [wrapper, str, wrapper].join(''); };