-
Notifications
You must be signed in to change notification settings - Fork 16
/
underscore.string.javascript.txt
92 lines (73 loc) · 5.59 KB
/
underscore.string.javascript.txt
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
UNDERSCORE.STRING
ALTERNATIVES ==> #See camelize
VERSION ==> #3.3.6
#Node or browser (global/AMD).
require("underscore.string") #Returns S.
#Every function actually returns S, except S.value()->STR (chaining)
require
("underscore.string/FUNC") #Require only a single function, with no chaining.
S.tap(FUNC(STR)->STR2) #Returns STR2
S.FUNC(...) #Any STRING function
S.numberFormat #Returns as STR3. NUM2 are number of decimals (def: 0), STR decimal separator (def: "."),
(NUM[, NUM2[, STR[, STR2]]]) #STR2 thousands separator (def: ",")
#Not localized
S.toNumber('NUM'[, NUM2]) #Returns as NUM3, with NUM2 decimals (def: 0, can be negative), or NaN if can't.
S.pad(STR,NUM[,STR2[,STR3]]) #Adds STR2 (single chars) to STR3 "left|side|both" (def: "left") until length is NUM charS.
S.[l][r]pad(...) #Same with different default STR3
S.strLeft|Right[Back] #Returns part of STR after|before first|last (according to "Back") occurence of STR2 from
(STR, STR2) #Left|Right
S.replaceAll(STR, STR2, STR3
[, BOOL]) #If true, case insensitive
S.insert(STR, NUM, STR2) #Inserts STR2 at position NUM inside STR
S.splice(STR, NUM, NUM2,STR2) #Same but first remove first NUM2 chars from position NUM.
S.include(STR, STR2) #True if STR2 is inside STR
S.starts|endsWith
(STR, STR2[, NUM]) #
S.count(STR, STR2) #Returns how many times STR2 is inside STR
S.levenshtein(STR, STR2) #Returns NUM
aa_aa_aa type -> AaAaAaType
S.swapCase(STR) #aAbBc -> AaBbC
S.capitalize(STR) #aA bB CC -> Aa bB CC
S.capitalize(STR, true) #aA bB CC -> Aa bb cc
S.decapitalize(STR) #Aa bb cc -> aa bb cc
S.titleize(STR) #aa bb cc -> Aa Bb Cc
S.camelize(STR[, BOOL]) #Aa-bb_cc dd -> AaBbCcDd (if true, aaBbCcDd)
S.classify(STR) #Same with all but [[:alnum:]]
S.dasherize(STR) #aa-bb_cc dd -> -aa-bb-cc-dd
S.underscored(STR) #aa-bb_cc dd -> aa_bb_cc_dd
S.humanize(STR) #Like classify() + camelize() + put spaces between words, then capitalize() + trim()
S.slugify(STR) #Replace any non [[:alnum:]] with -, and accented char without accent
S.cleanDiacritics(STR) #Replace diacritics to closest ASCII chars
S.repeat(STR, NUM) #Returns STR NUM times as single STR2
S.surround(STR, STR2) #Returns STR + STR2 + STR
S.quote(STR[, STR2]) #Same with def: '"'
S.unquote(STR[, STR2]) #Inverse
S.join(STR, STR2...) #Returns as single STR3 with STR2 joined with STR
S.toSentence[Serial] #Returns as single STR3 with STR as delimiter (def: ", ") and STR2 as final one (def: " and ")
(ARR[, STR[, STR2]]) #If "Serial", final delimiter is STR + STR2
S.words(STR[, REGEXP]) #Returns as STR2_ARR according to delimiter REGEXP (def: /\s+/)
S.chop(STR, NUM) #Returns as STR2_ARR, where each STR2 has size NUM
S.chars(STR) #Same as S.chop(STR,1)
S.wrap(STR[, OPTS]) #Adds OPTS.separator (def: '\n') at each OPTS.width (def: 75) bytes (not chars)
#OPTS:
# - trailingSpaces BOOL (def: false): forces width by adding spaces at end
# - preserveSpaces BOOL (def: false)
# - cut BOOL (def: false): allow cutting in middle of words
S.[l|r]trim(STR[, STR2]) #Def STR2 is " \t\n"
S.truncate(STR, NUM[, STR2]) #Can append STR2 if truncated (will not be beyond NUM chars)
S.prune(STR, NUM[, STR2]) #Same but with STR2 def to "..."
S.reverse(STR) #
S.toBoolean(STR
[,STR|REGEXP[_ARR2]] #Returns true if matching first part (def: ["true","TRUE","1"]), false if second (def: ["false",
[,STR|REGEXP[_ARR3]]) #"FALSE","0"]), undefined otherwise.
S.isBlank(STR) #True if whitespace or ""
S.clean(STR) #Compress whitespaces into one
S.dedent(STR[, STR2]) #Remove STR2 from beginning of lines. STR2 def is min indentation.
S.lines(STR) #Returns number of lines (according to newlines \r or \n).
S.[un]escapeHTML(STR) #Converts to|from HTML encoding
S.stripTags(STR) #Removes all HTML tags, but not their content.
S.pred|succ(STR) #Returns prev|next letter|number.
S.naturalCmp(STR, STR2) #Sort first part of STR as string, then if it continues as number sort rest as number.
#Returns -1|0|1