1
0
Fork 0
forked from 0x2620/oxjs

use markdown

This commit is contained in:
rolux 2012-05-30 13:34:57 +02:00
commit 9269b96469
4 changed files with 44 additions and 47 deletions

View file

@ -2,15 +2,15 @@
/*@
Ox.api <f> Turns an array into a list API
<code>Ox.api</code> takes an array and returns a function that allows you to
run complex queries against it. See the examples below for details.
`Ox.api` takes an array and returns a function that allows you to run
complex queries against it. See the examples below for details.
(items, options) -> <f> List API
items <[o]> An array of objects (key/value stores)
options <o> Options object
cache <b|false> If true, cache results
enums <o> Enumerables, for example <code>{size: ['S', 'M', 'L']}</code>
enums <o> Enumerables, for example `{size: ['S', 'M', 'L']}`
geo <b|false> If true, return combined area with totals
sort <[o]|[s]> Default sort, for example <code> ['+name', '-age']
sort <[o]|[s]> Default sort, for example `['+name', '-age']`
sums <[s]> List of keys to be included in totals
unique <s|'id'> The name of the unique key
<script>
@ -328,7 +328,7 @@ Ox.api = function(items, options) {
};
/*@
Ox.compact <f> Removes <code>null</code> or <code>undefined</code> values
Ox.compact <f> Removes `null` or `undefined` values
(array) -> <a> Array
> Ox.compact([null,,1,,2,,3])
[1, 2, 3]
@ -434,14 +434,13 @@ Ox.makeArray = function(value) {
/*@
Ox.range <f> Python-style range
(stop) -> <[n]> range
Returns an array of integers from <code>0</code> (inclusive) to
<code>stop</code> (exclusive).
Returns an array of integers from `0` (inclusive) to `stop` (exclusive).
(start, stop) -> <[n]> range
Returns an array of integers from <code>start</code> (inclusive) to
<code>stop</code> (exclusive).
Returns an array of integers from `start` (inclusive) to `stop`
(exclusive).
(start, stop, step) -> <[n]> range
Returns an array of numbers from <code>start</code> (inclusive) to
<code>stop</code> (exclusive), incrementing by <code>step</code>.
Returns an array of numbers from `start` (inclusive) to `stop`
(exclusive), incrementing by `step`.
start <n> Start value
stop <n> Stop value
step <n> Step value

View file

@ -79,8 +79,7 @@ Ox.count = function(collection) {
/*@
Ox.every <f> Tests if every element of a collection satisfies a given condition
Unlike <code>[].every()</code>, <code>Ox.every()</code> works for arrays,
objects and strings.
Unlike `[].every()`, `Ox.every()` works for arrays, objects and strings.
> Ox.every([0, 1, 2], function(v, i) { return v == i; })
true
> Ox.every({a: 1, b: 2, c: 3}, function(v) { return v == 1; })
@ -98,8 +97,7 @@ Ox.every = function(collection, iterator) {
/*@
Ox.filter <f> Filters a collection by a given condition
Unlike <code>[].filter()</code>, <code>Ox.filter()</code> works for arrays,
objects and strings.
Unlike `[].filter()`, `Ox.filter()` works for arrays, objects and strings.
> Ox.filter([2, 1, 0], function(v, i) { return v == i; })
[1]
> Ox.filter({a: 'c', b: 'b', c: 'a'}, function(v, k) { return v == k; })
@ -129,12 +127,10 @@ Ox.filter = function(collection, iterator, that) {
// FIXME: documentation is outdated!
/*@
Ox.forEach <f> forEach loop
<code>Ox.forEach()</code> loops over arrays, objects and strings.
Returning <code>false</code> from the iterator function acts like a
<code>break</code> statement (unlike <code>[].forEach()</code>, like
<code>$.each()</code>). The arguments of the iterator function are
<code>(value, key, index)</code> (more like <code>[].forEach()</code>
than like <code>$.each()</code>).
`Ox.forEach()` loops over arrays, objects and strings. Returning `false`
from the iterator function acts like a `break` statement (unlike
`[].forEach()`, like `$.each()`). The arguments of the iterator function are
`(value, key, index)` (more like `[].forEach()` than like `$.each()`).
(collection, callback) <a|o|s> The collection
(collection, callback, includePrototype) <a|o|s> The collection
collection <a|o|s> An array, object or string
@ -248,8 +244,8 @@ Ox.isEmpty = function(value) {
/*@
Ox.last <f> Gets or sets the last element of an array
Unlike <code>arrayWithALongName[arrayWithALongName.length - 1]</code>,
<code>Ox.last(arrayWithALongName)</code> is short.
Unlike `arrayWithALongName[arrayWithALongName.length - 1]`,
`Ox.last(arrayWithALongName)` is short.
<script>
Ox.test.array = [1, 2, 3];
</script>
@ -275,9 +271,8 @@ Ox.last = function(array, value) {
/*@
Ox.len <f> Returns the length of an array, node list, object or string
Not to be confused with <code>Ox.length</code>, which is the
<code>length</code> property of the <code>Ox</code> function
(<code>1</code>).
Not to be confused with `Ox.length`, which is the `length` property of the
`Ox` function (`1`).
> Ox.len((function() { return arguments; }(1, 2, 3)))
3
> Ox.len([1, 2, 3])
@ -309,8 +304,7 @@ Ox.len = function(collection) {
/*@
Ox.map <f> Transforms the values of an array, object or string
Unlike <code>[].map()</code>, <code>Ox.map()</code> works for arrays,
objects and strings.
Unlike `[].map()`, `Ox.map()` works for arrays, objects and strings.
> Ox.map([2, 1, 0], function(v, i) { return v == i; })
[false, true, false]
> Ox.map({a: 'b', b: 'b', c: 'b'}, function(v, k) { return v == k; })
@ -454,7 +448,7 @@ Ox.shuffle = function(collection) {
};
/*@
Ox.slice <f> Alias for <code>Array.prototype.slice.call</code>
Ox.slice <f> Alias for `Array.prototype.slice.call`
> (function() { return Ox.slice(arguments, 1, -1); }(1, 2, 3))
[2]
> (function() { return Ox.slice(arguments, 1); }(1, 2, 3))
@ -484,8 +478,7 @@ if (
/*@
Ox.some <f> Tests if one or more elements of a collection meet a given condition
Unlike <code>[].some()</code>, <code>Ox.some()</code> works for arrays,
objects and strings.
Unlike `[].some()`, `Ox.some()` works for arrays, objects and strings.
> Ox.some([2, 1, 0], function(i, v) { return i == v; })
true
> Ox.some({a: 1, b: 2, c: 3}, function(v) { return v == 1; })