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
|
||||
If the substring is a string literal (and not a variable),
|
||||
`/sub$/.test(str)` or `!!/sub$/.exec(str)` is shorter than `Ox.ends(str,
|
||||
sub)`.
|
||||
Ox.endsWith <f> Tests if a string ends with a given substring
|
||||
Equivalent to `new RegExp(Ox.escapeRegExp(substring) + '$').test(string)`.
|
||||
(string, substring) -> <b> True if string ends with substring
|
||||
> Ox.endsWith('foobar', 'bar')
|
||||
true
|
||||
> Ox.endsWith('foobar', 'foo')
|
||||
false
|
||||
@*/
|
||||
Ox.ends = Ox.endsWith = function(string, substring) {
|
||||
Ox.endsWith = function(string, substring) {
|
||||
string = string.toString();
|
||||
substring = substring.toString();
|
||||
return string.slice(string.length - substring.length) == substring;
|
||||
|
@ -100,14 +101,15 @@ Ox.pad <f> Pad a string to a given length
|
|||
'foo'
|
||||
> Ox.pad('foobar', 'left', 3)
|
||||
'bar'
|
||||
> Ox.pad('foo', -1)
|
||||
''
|
||||
@*/
|
||||
Ox.pad = function(string, position, length, padding) {
|
||||
// fixme: weird for negative numbers
|
||||
var hasPosition = Ox.isString(arguments[1]),
|
||||
isNumber = Ox.isNumber(arguments[0]),
|
||||
last = Ox.last(arguments);
|
||||
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
|
||||
: isNumber && position == 'left' ? '0' : ' ';
|
||||
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
|
||||
If the substring is a string literal (and not a variable),
|
||||
`/^sub/.test(str)` or `!!/^sub/.exec(str)` is shorter than `Ox.starts(str,
|
||||
sub)`.
|
||||
Ox.startsWith <f> Tests if a string ends with a given substring
|
||||
Equivalent to `new RegExp('^' + Ox.escapeRegExp(substring)).test(string)`.
|
||||
(string, substring) -> <b> True if string starts with substring
|
||||
> Ox.startsWith('foobar', 'foo')
|
||||
true
|
||||
> Ox.startsWith('foobar', 'bar')
|
||||
false
|
||||
@*/
|
||||
Ox.starts = Ox.startsWith = function(string, substring) {
|
||||
// fixme: rename to starts
|
||||
Ox.startsWith = function(string, substring) {
|
||||
string = string.toString();
|
||||
substring = substring.toString();
|
||||
return string.slice(0, substring.length) == substring;
|
||||
|
|
Loading…
Reference in a new issue