-
Notifications
You must be signed in to change notification settings - Fork 375
/
index.js
143 lines (128 loc) · 4.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* 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.6'
* @preserve
*/
'use strict';
function s(value) {
/* jshint validthis: true */
if (!(this instanceof s)) return new s(value);
this._wrapped = value;
}
s.VERSION = '3.3.6';
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;