Ox.toArray -> Ox.slice

This commit is contained in:
rolux 2013-12-01 14:57:52 +01:00
parent 3a28b08d46
commit 031aa4367b
11 changed files with 20 additions and 20 deletions

View file

@ -296,7 +296,7 @@ My.range <f> Returns a python-style range
*/
My.range = function() {
var a = [];
Ox.loop.apply(null, Ox.toArray(arguments).concat(function(i) {
Ox.loop.apply(null, Ox.slice(arguments).concat(function(i) {
a.push(i);
}));
return a;
@ -358,7 +358,7 @@ My.localStorage = function(ns) {
}
storage.delete = function() {
var keys = arguments.length == 0 ? Object.keys(storage())
: Ox.toArray(arguments)
: Ox.slice(arguments)
keys.forEach(function(key) {
delete localStorage[ns + '.' + key];
});

View file

@ -1286,7 +1286,7 @@ Ox.Calendar = function(options, self) {
{id, {key: value, ...}} -> <o> Calendar object
@*/
that.editEvent = function() {
var args = Ox.toArray(arguments),
var args = Ox.slice(arguments),
id = args.shift(),
data = Ox.makeObject(args),
event = Ox.getObjectById(self.options.events, id),

View file

@ -45,7 +45,7 @@ Ox.App = function(options) {
location: {href: location.href},
navigator: {
cookieEnabled: navigator.cookieEnabled,
plugins: Ox.toArray(navigator.plugins).map(function(plugin) {
plugins: Ox.slice(navigator.plugins).map(function(plugin) {
return plugin.name;
}),
userAgent: navigator.userAgent

View file

@ -445,7 +445,7 @@ Ox.Element = function(options, self) {
@*/
that.toggleOption = function() {
var options = {};
Ox.toArray(arguments).forEach(function(key) {
Ox.slice(arguments).forEach(function(key) {
options[key] == !self.options[key];
});
that.options(options);

View file

@ -58,7 +58,7 @@ Ox.Event = (function() {
Event names can be namespaced, like `'click.foo'`
*/
that.bind = function() {
var args = Ox.toArray(arguments), once, self;
var args = Ox.slice(arguments), once, self;
if (args.length == 1) {
eventHandlers.push(args[0])
} else {

View file

@ -560,7 +560,7 @@ Ox.makeArray <f> Wraps any non-array in an array.
Ox.makeArray = function(value) {
var ret, type = Ox.typeOf(value);
if (type == 'arguments') {
ret = Ox.toArray(value);
ret = Ox.slice(value);
} else if (type == 'array') {
ret = value;
} else {
@ -624,7 +624,7 @@ Ox.range <f> Python-style range
@*/
Ox.range = function() {
var array = [];
Ox.loop.apply(null, Ox.toArray(arguments).concat(function(index) {
Ox.loop.apply(null, Ox.slice(arguments).concat(function(index) {
array.push(index);
}));
return array;
@ -761,7 +761,7 @@ Ox.zip <f> Zips an array of arrays
[[0, 3], [1, 4], [2, 5]]
@*/
Ox.zip = function() {
var args = arguments.length == 1 ? arguments[0] : Ox.toArray(arguments),
var args = arguments.length == 1 ? arguments[0] : Ox.slice(arguments),
array = [];
args[0].forEach(function(value, index) {
array[index] = [];

View file

@ -47,7 +47,7 @@
n, time, type = Ox.typeOf(collection);
callback = Ox.isFunction(last) ? last : arguments[arguments.length - 2];
collection = type == 'array' || type == 'object'
? collection : Ox.toArray(collection);
? collection : Ox.slice(collection);
keys = type == 'object'
? Object.keys(collection) : Ox.range(collection.length);
ms = ms || 1000;
@ -149,7 +149,7 @@
var i = 0, n, type = Ox.typeOf(collection);
callback = callback || (arguments.length == 3 ? arguments[2] : Ox.noop);
collection = type == 'array' || type == 'object'
? collection : Ox.toArray(collection);
? collection : Ox.slice(collection);
n = Ox.len(collection);
that = arguments.length == 4 ? that : null;
Ox.forEach(collection, function(value, key, collection) {
@ -192,7 +192,7 @@
undefined
@*/
Ox.parallelMap = function() {
asyncMap.apply(null, [Ox.parallelForEach].concat(Ox.toArray(arguments)));
asyncMap.apply(null, [Ox.parallelForEach].concat(Ox.slice(arguments)));
};
/*@
@ -222,7 +222,7 @@
var i = 0, keys, n, type = Ox.typeOf(collection);
callback = callback || (arguments.length == 3 ? arguments[2] : Ox.noop);
collection = type == 'array' || type == 'object'
? collection : Ox.toArray(collection);
? collection : Ox.slice(collection);
keys = type == 'object'
? Object.keys(collection) : Ox.range(collection.length);
n = Ox.len(collection);
@ -280,7 +280,7 @@
undefined
@*/
Ox.serialMap = function(collection, iterator, that, callback) {
asyncMap.apply(null, [Ox.serialForEach].concat(Ox.toArray(arguments)));
asyncMap.apply(null, [Ox.serialForEach].concat(Ox.slice(arguments)));
};
// FIXME: The above test with 10000 iterations blows the stack

View file

@ -18,7 +18,7 @@ Ox.hsl <f> Takes RGB values and returns HSL values
Ox.hsl = function(rgb) {
var hsl = [0, 0, 0], max, min;
if (arguments.length == 3) {
rgb = Ox.toArray(arguments);
rgb = Ox.slice(arguments);
}
rgb = Ox.clone(rgb).map(function(value) {
return value / 255;
@ -65,7 +65,7 @@ Ox.rgb <f> Takes HSL values and returns RGB values
Ox.rgb = function(hsl) {
var rgb = [0, 0, 0], v1, v2, v3;
if (arguments.length == 3) {
hsl = Ox.toArray(arguments);
hsl = Ox.slice(arguments);
}
hsl = Ox.clone(hsl);
hsl[0] /= 360;

View file

@ -123,7 +123,7 @@ Ox.localStorage = function(namespace) {
// IE 8 doesn't like `storage.delete`
storage['delete'] = function() {
var keys = arguments.length == 0 ? Object.keys(storage())
: Ox.toArray(arguments)
: Ox.slice(arguments)
keys.forEach(function(key) {
delete localStorage[namespace + '.' + key];
});
@ -173,7 +173,7 @@ Ox.Log = (function() {
}));
};
that.log = function() {
var args = Ox.toArray(arguments), date, ret;
var args = Ox.slice(arguments), date, ret;
if (!log.filterEnabled || log.filter.indexOf(args[0]) > -1) {
date = new Date();
args.unshift(

View file

@ -222,7 +222,7 @@ Ox.decodeDeflate = function(string, callback) {
// Unfortunately, we can't synchronously set the source of an image,
// draw it onto a canvas, and read its data.
image.onload = function() {
string = Ox.toArray(Ox.canvas(image).data).map(function(value, index) {
string = Ox.slice(Ox.canvas(image).data).map(function(value, index) {
// Read one character per RGB byte, ignore ALPHA.
return index % 4 < 3 ? Ox.char(value) : '';
}).join('');

View file

@ -149,7 +149,7 @@ Ox.getFile = (function() {
}
}
function findFileInHead() {
return Ox.toArray(
return Ox.slice(
document.getElementsByTagName(type == 'css' ? 'link' : 'script')
).map(function(element) {
return element[type == 'css' ? 'href' : 'src'] == file;