traverson
Version:
Hypermedia API/HATEOAS client for Node.js and the browser
43 lines (35 loc) • 1.09 kB
JavaScript
;
/*
* Copied from underscore.string module. Just the functions we need, to reduce
* the browserified size.
*/
var _s = {
startsWith: function(str, starts) {
if (starts === '') return true;
if (str == null || starts == null) return false;
str = String(str); starts = String(starts);
return str.length >= starts.length && str.slice(0, starts.length) === starts;
},
endsWith: function(str, ends){
if (ends === '') return true;
if (str == null || ends == null) return false;
str = String(str); ends = String(ends);
return str.length >= ends.length &&
str.slice(str.length - ends.length) === ends;
},
splice: function(str, i, howmany, substr){
var arr = _s.chars(str);
arr.splice(~~i, ~~howmany, substr);
return arr.join('');
},
contains: function(str, needle){
if (needle === '') return true;
if (str == null) return false;
return String(str).indexOf(needle) !== -1;
},
chars: function(str) {
if (str == null) return [];
return String(str).split('');
}
};
module.exports = _s;