forked from esamattis/underscore.string
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
112 lines (102 loc) · 3.78 KB
/
index.js
File metadata and controls
112 lines (102 loc) · 3.78 KB
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
// 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 '2.4.0'
'use strict';
function s(value) {
/* jshint validthis: true */
if (!(this instanceof s)) return new s(value);
this._wrapped = value;
}
s.VERSION = '2.4.0';
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.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.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');
// 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;
// Implement chaining
s.prototype = {
value: function() {
return this._wrapped;
},
tap: function(fn) {
return new s(fn(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]);
module.exports = s;