remove 'Ox.starts' and 'Ox.ends' aliases, update documentation; fix Ox.pad with negative length
This commit is contained in:
parent
a5c6747b57
commit
cd8b2e297d
1 changed files with 15 additions and 13 deletions
|
@ -36,14 +36,15 @@ Ox.clean = function(string) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.endsWith <f> Checks if a string ends with a given substring
|
Ox.endsWith <f> Tests if a string ends with a given substring
|
||||||
If the substring is a string literal (and not a variable),
|
Equivalent to `new RegExp(Ox.escapeRegExp(substring) + '$').test(string)`.
|
||||||
`/sub$/.test(str)` or `!!/sub$/.exec(str)` is shorter than `Ox.ends(str,
|
(string, substring) -> <b> True if string ends with substring
|
||||||
sub)`.
|
|
||||||
> Ox.endsWith('foobar', 'bar')
|
> Ox.endsWith('foobar', 'bar')
|
||||||
true
|
true
|
||||||
|
> Ox.endsWith('foobar', 'foo')
|
||||||
|
false
|
||||||
@*/
|
@*/
|
||||||
Ox.ends = Ox.endsWith = function(string, substring) {
|
Ox.endsWith = function(string, substring) {
|
||||||
string = string.toString();
|
string = string.toString();
|
||||||
substring = substring.toString();
|
substring = substring.toString();
|
||||||
return string.slice(string.length - substring.length) == substring;
|
return string.slice(string.length - substring.length) == substring;
|
||||||
|
@ -100,14 +101,15 @@ Ox.pad <f> Pad a string to a given length
|
||||||
'foo'
|
'foo'
|
||||||
> Ox.pad('foobar', 'left', 3)
|
> Ox.pad('foobar', 'left', 3)
|
||||||
'bar'
|
'bar'
|
||||||
|
> Ox.pad('foo', -1)
|
||||||
|
''
|
||||||
@*/
|
@*/
|
||||||
Ox.pad = function(string, position, length, padding) {
|
Ox.pad = function(string, position, length, padding) {
|
||||||
// fixme: weird for negative numbers
|
|
||||||
var hasPosition = Ox.isString(arguments[1]),
|
var hasPosition = Ox.isString(arguments[1]),
|
||||||
isNumber = Ox.isNumber(arguments[0]),
|
isNumber = Ox.isNumber(arguments[0]),
|
||||||
last = Ox.last(arguments);
|
last = Ox.last(arguments);
|
||||||
position = hasPosition ? arguments[1] : isNumber ? 'left' : 'right';
|
position = hasPosition ? arguments[1] : isNumber ? 'left' : 'right';
|
||||||
length = hasPosition ? arguments[2] : arguments[1];
|
length = Math.max(hasPosition ? arguments[2] : arguments[1], 0);
|
||||||
padding = Ox.isString(last) ? last
|
padding = Ox.isString(last) ? last
|
||||||
: isNumber && position == 'left' ? '0' : ' ';
|
: isNumber && position == 'left' ? '0' : ' ';
|
||||||
string = string.toString();
|
string = string.toString();
|
||||||
|
@ -410,15 +412,15 @@ Ox.splice = function(string, index, remove) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.startsWith <f> Checks if a string starts with a given substring
|
Ox.startsWith <f> Tests if a string ends with a given substring
|
||||||
If the substring is a string literal (and not a variable),
|
Equivalent to `new RegExp('^' + Ox.escapeRegExp(substring)).test(string)`.
|
||||||
`/^sub/.test(str)` or `!!/^sub/.exec(str)` is shorter than `Ox.starts(str,
|
(string, substring) -> <b> True if string starts with substring
|
||||||
sub)`.
|
|
||||||
> Ox.startsWith('foobar', 'foo')
|
> Ox.startsWith('foobar', 'foo')
|
||||||
true
|
true
|
||||||
|
> Ox.startsWith('foobar', 'bar')
|
||||||
|
false
|
||||||
@*/
|
@*/
|
||||||
Ox.starts = Ox.startsWith = function(string, substring) {
|
Ox.startsWith = function(string, substring) {
|
||||||
// fixme: rename to starts
|
|
||||||
string = string.toString();
|
string = string.toString();
|
||||||
substring = substring.toString();
|
substring = substring.toString();
|
||||||
return string.slice(0, substring.length) == substring;
|
return string.slice(0, substring.length) == substring;
|
||||||
|
|
Loading…
Reference in a new issue