misc updates to ox.js

This commit is contained in:
rolux 2012-01-04 13:12:48 +05:30
commit 2ef642fdeb
11 changed files with 136 additions and 93 deletions

View file

@ -37,12 +37,12 @@ Ox.clean = function(str) {
/*@
Ox.endsWith <f> Checks if a string ends with a given substring
If the substring is a string literal (and not a variable),
<code>/sub$/.test(str)</code> or <code>!!/sub$/(str)</code>
<code>/sub$/.test(str)</code> or <code>!!/sub$/.exec(str)</code>
is shorter than <code>Ox.ends(str, sub)</code>.
> Ox.endsWith('foobar', 'bar')
true
@*/
Ox.endsWith = function(str, sub) {
Ox.ends = Ox.endsWith = function(str, sub) {
// fixme: rename to ends
return str.substr(str.length - sub.length) == sub;
};
@ -248,23 +248,24 @@ Ox.repeat = function(val, num) {
return ret;
};
/*@
Ox.reverse <f> Reverses a string
> Ox.reverse('foobar')
'raboof'
@*/
Ox.reverse = function(str) {
/*
Ox.reverse("foo")
oof
*/
return str.toString().split('').reverse().join('');
};
/*@
Ox.startsWith <f> Checks if a string starts with a given substring
If the substring is a string literal (and not a variable),
<code>/^sub/.test(str)</code> or <code>!!/^sub/(str)</code>
<code>/^sub/.test(str)</code> or <code>!!/^sub/.exec(str)</code>
is shorter than <code>Ox.starts(str, sub)</code>.
> Ox.startsWith('foobar', 'foo')
true
@*/
Ox.startsWith = function(str, sub) {
Ox.starts = Ox.startsWith = function(str, sub) {
// fixme: rename to starts
return str.substr(0, sub.length) == sub;
};