-
Notifications
You must be signed in to change notification settings - Fork 22
/
string.js
70 lines (55 loc) · 1.56 KB
/
string.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
var assert = require('assert')
, string = require('../lib/string');
tests = {
'test reverse': function () {
var str = 'abcdef'
, actual = string.reverse(str);
assert.equal('fedcba', actual);
}
, 'test ltrim': function () {
var str = ' foo'
, actual = string.ltrim(str);
assert.equal('foo', actual);
}
, 'test rtrim': function () {
var str = 'foo '
, actual = string.rtrim(str);
assert.equal('foo', actual);
}
, 'test trim': function () {
var str = ' foo '
, actual = string.trim(str);
assert.equal('foo', actual);
}
, 'test lpad': function () {
var str = 'foo'
, actual = string.lpad(str, 'x', 7);
assert.equal('xxxxfoo', actual);
}
, 'test rpad': function () {
var str = 'foo'
, actual = string.rpad(str, 'x', 7);
assert.equal('fooxxxx', actual);
}
, 'test camelize basic': function () {
var str = 'foo_bar_baz'
, actual = string.camelize(str);
assert.equal('fooBarBaz', actual);
}
, 'test camelize no initial cap from capitalized snake': function () {
var str = 'Foo_bar_baz'
, actual = string.camelize(str);
assert.equal('fooBarBaz', actual);
}
, 'test camelize initial cap': function () {
var str = 'foo_bar_baz'
, actual = string.camelize(str, {initialCap: true});
assert.equal('FooBarBaz', actual);
}
, 'test camelize leading underscore': function () {
var str = '_foo_bar_baz'
, actual = string.camelize(str, {leadingUnderscore: true});
assert.equal('_fooBarBaz', actual);
}
};
module.exports = tests;