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() { My.range = function() {
var a = []; 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); a.push(i);
})); }));
return a; return a;
@ -358,7 +358,7 @@ My.localStorage = function(ns) {
} }
storage.delete = function() { storage.delete = function() {
var keys = arguments.length == 0 ? Object.keys(storage()) var keys = arguments.length == 0 ? Object.keys(storage())
: Ox.toArray(arguments) : Ox.slice(arguments)
keys.forEach(function(key) { keys.forEach(function(key) {
delete localStorage[ns + '.' + key]; delete localStorage[ns + '.' + key];
}); });

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -47,7 +47,7 @@
n, time, type = Ox.typeOf(collection); n, time, type = Ox.typeOf(collection);
callback = Ox.isFunction(last) ? last : arguments[arguments.length - 2]; callback = Ox.isFunction(last) ? last : arguments[arguments.length - 2];
collection = type == 'array' || type == 'object' collection = type == 'array' || type == 'object'
? collection : Ox.toArray(collection); ? collection : Ox.slice(collection);
keys = type == 'object' keys = type == 'object'
? Object.keys(collection) : Ox.range(collection.length); ? Object.keys(collection) : Ox.range(collection.length);
ms = ms || 1000; ms = ms || 1000;
@ -149,7 +149,7 @@
var i = 0, n, type = Ox.typeOf(collection); var i = 0, n, type = Ox.typeOf(collection);
callback = callback || (arguments.length == 3 ? arguments[2] : Ox.noop); callback = callback || (arguments.length == 3 ? arguments[2] : Ox.noop);
collection = type == 'array' || type == 'object' collection = type == 'array' || type == 'object'
? collection : Ox.toArray(collection); ? collection : Ox.slice(collection);
n = Ox.len(collection); n = Ox.len(collection);
that = arguments.length == 4 ? that : null; that = arguments.length == 4 ? that : null;
Ox.forEach(collection, function(value, key, collection) { Ox.forEach(collection, function(value, key, collection) {
@ -192,7 +192,7 @@
undefined undefined
@*/ @*/
Ox.parallelMap = function() { 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); var i = 0, keys, n, type = Ox.typeOf(collection);
callback = callback || (arguments.length == 3 ? arguments[2] : Ox.noop); callback = callback || (arguments.length == 3 ? arguments[2] : Ox.noop);
collection = type == 'array' || type == 'object' collection = type == 'array' || type == 'object'
? collection : Ox.toArray(collection); ? collection : Ox.slice(collection);
keys = type == 'object' keys = type == 'object'
? Object.keys(collection) : Ox.range(collection.length); ? Object.keys(collection) : Ox.range(collection.length);
n = Ox.len(collection); n = Ox.len(collection);
@ -280,7 +280,7 @@
undefined undefined
@*/ @*/
Ox.serialMap = function(collection, iterator, that, callback) { 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 // 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) { Ox.hsl = function(rgb) {
var hsl = [0, 0, 0], max, min; var hsl = [0, 0, 0], max, min;
if (arguments.length == 3) { if (arguments.length == 3) {
rgb = Ox.toArray(arguments); rgb = Ox.slice(arguments);
} }
rgb = Ox.clone(rgb).map(function(value) { rgb = Ox.clone(rgb).map(function(value) {
return value / 255; return value / 255;
@ -65,7 +65,7 @@ Ox.rgb <f> Takes HSL values and returns RGB values
Ox.rgb = function(hsl) { Ox.rgb = function(hsl) {
var rgb = [0, 0, 0], v1, v2, v3; var rgb = [0, 0, 0], v1, v2, v3;
if (arguments.length == 3) { if (arguments.length == 3) {
hsl = Ox.toArray(arguments); hsl = Ox.slice(arguments);
} }
hsl = Ox.clone(hsl); hsl = Ox.clone(hsl);
hsl[0] /= 360; hsl[0] /= 360;

View file

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

View file

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

View file

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