2 // (c) 2010 Esa-Matti Suuronen <esa-matti aet suuronen dot org>
3 // Underscore.string is freely distributable under the terms of the MIT license.
4 // Documentation: https://github.com/epeli/underscore.string
5 // Some code is borrowed from MooTools and Alexandru Marasteanu.
11 /* jshint validthis: true */
12 if (!(this instanceof s)) return new s(value);
13 this._wrapped = value;
18 s.isBlank = require('./isBlank');
19 s.stripTags = require('./stripTags');
20 s.capitalize = require('./capitalize');
21 s.decapitalize = require('./decapitalize');
22 s.chop = require('./chop');
23 s.trim = require('./trim');
24 s.clean = require('./clean');
25 s.cleanDiacritics = require('./cleanDiacritics');
26 s.count = require('./count');
27 s.chars = require('./chars');
28 s.swapCase = require('./swapCase');
29 s.escapeHTML = require('./escapeHTML');
30 s.unescapeHTML = require('./unescapeHTML');
31 s.splice = require('./splice');
32 s.insert = require('./insert');
33 s.replaceAll = require('./replaceAll');
34 s.include = require('./include');
35 s.join = require('./join');
36 s.lines = require('./lines');
37 s.dedent = require('./dedent');
38 s.reverse = require('./reverse');
39 s.startsWith = require('./startsWith');
40 s.endsWith = require('./endsWith');
41 s.pred = require('./pred');
42 s.succ = require('./succ');
43 s.titleize = require('./titleize');
44 s.camelize = require('./camelize');
45 s.underscored = require('./underscored');
46 s.dasherize = require('./dasherize');
47 s.classify = require('./classify');
48 s.humanize = require('./humanize');
49 s.ltrim = require('./ltrim');
50 s.rtrim = require('./rtrim');
51 s.truncate = require('./truncate');
52 s.prune = require('./prune');
53 s.words = require('./words');
54 s.pad = require('./pad');
55 s.lpad = require('./lpad');
56 s.rpad = require('./rpad');
57 s.lrpad = require('./lrpad');
58 s.sprintf = require('./sprintf');
59 s.vsprintf = require('./vsprintf');
60 s.toNumber = require('./toNumber');
61 s.numberFormat = require('./numberFormat');
62 s.strRight = require('./strRight');
63 s.strRightBack = require('./strRightBack');
64 s.strLeft = require('./strLeft');
65 s.strLeftBack = require('./strLeftBack');
66 s.toSentence = require('./toSentence');
67 s.toSentenceSerial = require('./toSentenceSerial');
68 s.slugify = require('./slugify');
69 s.surround = require('./surround');
70 s.quote = require('./quote');
71 s.unquote = require('./unquote');
72 s.repeat = require('./repeat');
73 s.naturalCmp = require('./naturalCmp');
74 s.levenshtein = require('./levenshtein');
75 s.toBoolean = require('./toBoolean');
76 s.exports = require('./exports');
77 s.escapeRegExp = require('./helper/escapeRegExp');
78 s.wrap = require('./wrap');
79 s.map = require('./map');
88 s.contains = s.include;
90 s.toBool = s.toBoolean;
91 s.camelcase = s.camelize;
97 value: function value() {
102 function fn2method(key, fn) {
103 if (typeof fn !== "function") return;
104 s.prototype[key] = function() {
105 var args = [this._wrapped].concat(Array.prototype.slice.call(arguments));
106 var res = fn.apply(null, args);
107 // if the result is non-string stop the chain and return the value
108 return typeof res === 'string' ? new s(res) : res;
112 // Copy functions to instance methods for chaining
113 for (var key in s) fn2method(key, s[key]);
115 fn2method("tap", function tap(string, fn) {
119 function prototype2method(methodName) {
120 fn2method(methodName, function(context) {
121 var args = Array.prototype.slice.call(arguments, 1);
122 return String.prototype[methodName].apply(context, args);
126 var prototypeMethods = [
137 for (var method in prototypeMethods) prototype2method(prototypeMethods[method]);