update documentation

This commit is contained in:
rolux 2012-06-02 15:17:56 +02:00
parent cb208f2333
commit 686df92efa

View file

@ -363,8 +363,8 @@ Ox.api = function(items, options) {
};
/*@
Ox.compact <f> Removes `null` or `undefined` values
(array) -> <a> Array
Ox.compact <f> Removes `null` or `undefined` values from an array
(array) -> <a> Array without `null` or `undefined` values
> Ox.compact([null,,1,,2,,3])
[1, 2, 3]
@*/
@ -378,27 +378,31 @@ Ox.compact = function(array) {
Ox.find <f> Returns array elements that match a string
Returns an array of case-insensitive matches: exact match first, then
leading matches, then other matches
(array, query[, leading]) -> Array of matches
array <[s]> Array of strings
query <s> Query string
leading <b> If true, returns leading matches only
> Ox.find(['Bar', 'Barfoo', 'Foo', 'Foobar'], 'foo')
['Foo', 'Foobar', 'Barfoo']
> Ox.find(['Bar', 'Barfoo', 'Foo', 'Foobar'], 'foo', true)
['Foo', 'Foobar']
@*/
Ox.find = function(array, string, leading) {
var ret = [[], []];
var matches = [[], []];
string = string.toLowerCase();
array.forEach(function(value) {
var lowerCase = value.toLowerCase(),
index = lowerCase.indexOf(string);
index > -1 && ret[index == 0 ? 0 : 1][
index > -1 && matches[index == 0 ? 0 : 1][
lowerCase == string ? 'unshift' : 'push'
](value);
})
return leading ? ret[0] : ret[0].concat(ret[1]);
return leading ? matches[0] : matches[0].concat(matches[1]);
};
/*@
Ox.flatten <f> Flattens an array
(arr) -> <a> Array
(array) -> <a> Flattened array
> Ox.flatten([1, [2, [3], 2], 1])
[1, 2, 3, 2, 1]
@*/
@ -418,6 +422,9 @@ Ox.flatten = function(array) {
/*@
Ox.getIndexById <f> Returns the first array index of an object with a given id
(array, id) -> <n> Index (or `-1`)
array <[o]> Array of objects with a unique `'id'` property
id <s> Id
> Ox.getIndexById([{id: 'foo', str: 'Foo'}, {id: 'bar', str: 'Bar'}], 'bar')
1
> Ox.getIndexById([{id: 'foo', str: 'Foo'}, {id: 'bar', str: 'Bar'}], 'baz')
@ -431,6 +438,9 @@ Ox.getIndexById = function(array, id) {
/*@
Ox.getObjectById <f> Returns the first object in an array with a given id
(array, id) -> <o> Object (or `null`)
array <[o]> Array of objects with a unique `'id'` property
id <s> Id
> Ox.getObjectById([{id: 'foo', str: 'Foo'}, {id: 'bar', str: 'Bar'}], 'bar')
{id: "bar", str: "Bar"}
> Ox.getObjectById([{id: 'foo', str: 'Foo'}, {id: 'bar', str: 'Bar'}], 'baz')
@ -449,6 +459,8 @@ Ox.indexOf = function(arr) {
/*@
Ox.makeArray <f> Wraps any non-array in an array.
(value) -> <a> Array
value <*> Any value
> Ox.makeArray('foo')
['foo']
> Ox.makeArray(['foo'])
@ -646,7 +658,7 @@ Ox.toArray = function(collection) {
try {
Array.prototype.slice.call(document.getElementsByTagName('a'));
} catch (error) {
// Handle MSIE NodeLists
// Handle IE NodeLists
Ox.toArray = function(collection) {
var i, length, ret = [];
try {
@ -662,8 +674,8 @@ try {
}
/*@
Ox.unique <f> Returns an array without duplicate values
(array) -> <a> Array
Ox.unique <f> Removes duplicate values from an array
(array) -> <a> Array without duplicate values
> Ox.unique([1, 2, 3, 2, 1])
[1, 2, 3]
> Ox.unique([NaN, NaN])