-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrafity.strings.js
executable file
·66 lines (54 loc) · 1.18 KB
/
crafity.strings.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
/*jslint bitwise: true, unparam: true, maxerr: 50, white: true */
/*globals window*/
/*!
* crafity.arrays
* Copyright(c) 2011 Crafity
* Copyright(c) 2011 Bart Riemens
* Copyright(c) 2011 Galina Slavova
* MIT Licensed
*/
(function (crafity) {
"use strict";
var strings = (crafity.strings = {});
strings.trim = function(value) {
return (value || this).replace(/^\s+|\s+$/g, "");
};
/**
* Trim spaces on the left
* @param value
*/
strings.ltrim = function(value) {
return value.replace(/^\s+/, "");
};
/**
* trim space from the right
* @param value
*/
strings.rtrim = function(value) {
return value.replace(/\s+$/, "");
};
/**
* Apply character padding on the left
* @param value
* @param character
* @param length
*/
strings.lpad = function(value, character, length) {
while (value.length < length) {
value = character + value;
}
return value;
};
/**
* Apply character padding on the right
* @param value
* @param character
* @param length
*/
strings.rpad = function(value, character, length) {
while (value.length < length) {
value = value + character;
}
return value;
};
}(window.crafity = window.crafity || {}));