forked from evanx/redexutil
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStrings.js
37 lines (31 loc) · 844 Bytes
/
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
// Copyright (c) 2015, Evan Summers (twitter.com/evanxsummers)
// ISC license, see http://github.com/evanx/redexutil/LICENSE
const logger = Loggers.create(__filename, 'info');
export function formatEmpty(string, defaultString) {
if (string) {
return string;
} else {
return defaultString || '';
}
}
export function formatNullable(string) { // deprecated
return formatEmpty(string);
}
export function padLeftZero(value, length) {
let string = value.toString();
while (string.length < length) {
string = '0' + string;
}
return string;
}
export function joinColon() { // deprecated
return Array.prototype.slice.call(arguments).join(':');
}
export function extractRegex(string, regex) {
if (string) {
let match = string.match(regex);
if (match && match.length > 1) {
return match[1];
}
}
}