1 |
7876
|
aaronmk
|
function is_undef(value) { return typeof value === 'undefined' }
|
2 |
|
|
|
3 |
|
|
function coalesce(value, empty) { return !is_undef(value) ? value : empty }
|
4 |
|
|
|
5 |
|
|
function starts_with(str, prefix)
|
6 |
|
|
{
|
7 |
|
|
return str.substr(0, prefix.length) === prefix
|
8 |
|
|
}
|
9 |
|
|
|
10 |
|
|
function ends_with(str, suffix) { return str.substr(-suffix.length) === suffix }
|
11 |
|
|
|
12 |
|
|
function rm_prefix(prefix, str)
|
13 |
|
|
{
|
14 |
|
|
return starts_with(str, prefix) ? str.substr(prefix.length) : str
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
function rm_suffix(suffix, str)
|
18 |
|
|
{
|
19 |
|
|
return ends_with(str, suffix) ?
|
20 |
|
|
str.substr(0, str.length - suffix.length) : str
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
function partition(str, delim)
|
24 |
|
|
{
|
25 |
|
|
var delim_idx = str.indexOf(delim)
|
26 |
|
|
return delim_idx >= 0 ? {head: str.substr(0, delim_idx),
|
27 |
|
|
tail: str.substr(delim_idx+delim.length)} : {head: str, tail: ''}
|
28 |
|
|
}
|