less obscure Ox.map
This commit is contained in:
parent
33390069b9
commit
12cf77cef5
21 changed files with 125 additions and 101 deletions
|
@ -147,7 +147,7 @@ Ox.load.Image = function(options, callback) {
|
||||||
val = Ox.hsl([rgba[0], rgba[1], rgba[2]])[i];
|
val = Ox.hsl([rgba[0], rgba[1], rgba[2]])[i];
|
||||||
rgb = i == 0
|
rgb = i == 0
|
||||||
? Ox.rgb([val, 1, 0.5])
|
? Ox.rgb([val, 1, 0.5])
|
||||||
: Ox.map(Ox.range(3), function(v) {
|
: Ox.range(3).map(function() {
|
||||||
return parseInt(val * 255);
|
return parseInt(val * 255);
|
||||||
});
|
});
|
||||||
return Ox.merge(rgb, rgba[3]);
|
return Ox.merge(rgb, rgba[3]);
|
||||||
|
@ -343,9 +343,9 @@ Ox.load.Image = function(options, callback) {
|
||||||
: Ox.isNumber(arguments[2]) ? arguments[2] : 0,
|
: Ox.isNumber(arguments[2]) ? arguments[2] : 0,
|
||||||
b = 0, bin,
|
b = 0, bin,
|
||||||
// Array of bits per byte to be modified (0 is LSB)
|
// Array of bits per byte to be modified (0 is LSB)
|
||||||
bits = mode < 1 ? [-mode] : Ox.map(Ox.range(8), function(bit) {
|
bits = mode < 1 ? [-mode] : Ox.filter(Ox.range(8), function(i) {
|
||||||
return mode & 1 << bit ? bit : null;
|
return mode & 1 << i;
|
||||||
}),
|
};
|
||||||
cap = getCapacity(bits.length), len;
|
cap = getCapacity(bits.length), len;
|
||||||
// Compress the string
|
// Compress the string
|
||||||
str = Ox[deflate ? 'encodeDeflate' : 'encodeUTF8'](str);
|
str = Ox[deflate ? 'encodeDeflate' : 'encodeUTF8'](str);
|
||||||
|
@ -359,7 +359,7 @@ Ox.load.Image = function(options, callback) {
|
||||||
str = str.substr(0, Math.ceil(cap));
|
str = str.substr(0, Math.ceil(cap));
|
||||||
// Create an array of bit values
|
// Create an array of bit values
|
||||||
bin = Ox.flatten(Ox.map(str, function(chr) {
|
bin = Ox.flatten(Ox.map(str, function(chr) {
|
||||||
return Ox.map(Ox.range(8), function(i) {
|
return Ox.range(8).map(function(i) {
|
||||||
return chr.charCodeAt(0) >> 7 - i & 1;
|
return chr.charCodeAt(0) >> 7 - i & 1;
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
@ -414,8 +414,8 @@ Ox.load.Image = function(options, callback) {
|
||||||
: Ox.isNumber(arguments[1]) ? arguments[1] : 0,
|
: Ox.isNumber(arguments[1]) ? arguments[1] : 0,
|
||||||
bin = '',
|
bin = '',
|
||||||
// Array of bits per byte to be modified (0 is LSB)
|
// Array of bits per byte to be modified (0 is LSB)
|
||||||
bits = mode < 1 ? [-mode] : Ox.map(Ox.range(8), function(b) {
|
bits = mode < 1 ? [-mode] : Ox.range(8).filter(function(i) {
|
||||||
return mode & 1 << b ? b : null;
|
return mode & 1 << i;
|
||||||
}),
|
}),
|
||||||
done = 0, len = 4, str = '';
|
done = 0, len = 4, str = '';
|
||||||
that.forEach(function(rgba, xy, index) {
|
that.forEach(function(rgba, xy, index) {
|
||||||
|
|
|
@ -262,9 +262,7 @@ Ox.URL = function(options) {
|
||||||
parts.push(constructFind(state.find));
|
parts.push(constructFind(state.find));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return '/' + Ox.map(parts, function(part) {
|
return '/' + Ox.filter(parts).join('/');
|
||||||
return part || null;
|
|
||||||
}).join('/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function constructValue(str, key) {
|
function constructValue(str, key) {
|
||||||
|
|
|
@ -116,8 +116,9 @@ Ox.ArrayInput = function(options, self) {
|
||||||
|
|
||||||
function getValue() {
|
function getValue() {
|
||||||
return Ox.map(self.$input, function($input) {
|
return Ox.map(self.$input, function($input) {
|
||||||
var value = $input.value();
|
return $input.value();
|
||||||
return value === '' ? null : value;
|
}).filter(function(value) {
|
||||||
|
return value !== '';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -357,8 +357,6 @@ Ox.Input = function(options, self) {
|
||||||
}
|
}
|
||||||
newLength = newValue.length;
|
newLength = newValue.length;
|
||||||
|
|
||||||
//Ox.Log('Form', 'selectEnd', selectEnd)
|
|
||||||
|
|
||||||
if (self.options.autocompleteReplace) {
|
if (self.options.autocompleteReplace) {
|
||||||
value = self.options.value;
|
value = self.options.value;
|
||||||
self.options.value = newValue;
|
self.options.value = newValue;
|
||||||
|
@ -374,27 +372,32 @@ Ox.Input = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.options.autocompleteSelect) {
|
if (self.options.autocompleteSelect) {
|
||||||
value = (self.options.autocompleteReplace ? value : self.options.value).toLowerCase();
|
value = (
|
||||||
|
self.options.autocompleteReplace
|
||||||
|
? value : self.options.value
|
||||||
|
).toLowerCase();
|
||||||
if (values.length) {
|
if (values.length) {
|
||||||
self.oldCursor = cursor();
|
self.oldCursor = cursor();
|
||||||
self.oldValue = self.options.value;
|
self.oldValue = self.options.value;
|
||||||
self.$autocompleteMenu.options({
|
self.$autocompleteMenu.options({
|
||||||
items: Ox.map(values, function(v, i) {
|
items: Ox.filter(values, function(v, i) {
|
||||||
var ret = null;
|
var ret = false;
|
||||||
if (
|
if (
|
||||||
!self.options.autocompleteSelectMax ||
|
!self.options.autocompleteSelectMax ||
|
||||||
i < self.options.autocompleteSelectMax
|
i < self.options.autocompleteSelectMax
|
||||||
) {
|
) {
|
||||||
if (value == v.toLowerCase()) {
|
if (v.toLowerCase() === value) {
|
||||||
selected = i;
|
selected = i;
|
||||||
}
|
}
|
||||||
ret = {
|
ret = true;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}).map(function(v) {
|
||||||
|
return {
|
||||||
id: v.toLowerCase().replace(/ /g, '_'), // fixme: need function to do lowercase, underscores etc?
|
id: v.toLowerCase().replace(/ /g, '_'), // fixme: need function to do lowercase, underscores etc?
|
||||||
title: self.options.autocompleteSelectHighlight ?
|
title: self.options.autocompleteSelectHighlight ?
|
||||||
Ox.highlight(v, value, 'OxHighlight') : v
|
Ox.highlight(v, value, 'OxHighlight') : v
|
||||||
};
|
};
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
if (!self.selectEventBound) {
|
if (!self.selectEventBound) {
|
||||||
|
@ -403,7 +406,6 @@ Ox.Input = function(options, self) {
|
||||||
});
|
});
|
||||||
self.selectEventBound = true;
|
self.selectEventBound = true;
|
||||||
}
|
}
|
||||||
Ox.Log('AUTO', 'show menu')
|
|
||||||
self.$autocompleteMenu.options({
|
self.$autocompleteMenu.options({
|
||||||
selected: selected
|
selected: selected
|
||||||
}).showMenu();
|
}).showMenu();
|
||||||
|
|
|
@ -45,8 +45,8 @@ Ox.OptionGroup = function(items, min, max, property) {
|
||||||
@*/
|
@*/
|
||||||
// FIXME: isn't value more useful in all cases?
|
// FIXME: isn't value more useful in all cases?
|
||||||
this[property] = function() {
|
this[property] = function() {
|
||||||
return Ox.map(items, function(item, i) {
|
return Ox.indicesOf(items, function(item) {
|
||||||
return item[property] ? i : null;
|
return item[property];
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,10 @@ Ox.SelectInput = function(options, self) {
|
||||||
return value[value[0] == self.other ? 1 : 0]
|
return value[value[0] == self.other ? 1 : 0]
|
||||||
},
|
},
|
||||||
split: function(value) {
|
split: function(value) {
|
||||||
return Ox.map(self.options.items, function(item, i) {
|
return Ox.filter(self.options.items, function(item, i) {
|
||||||
return i < item.length - 1 ? item.id : null;
|
return i < item.length - 1;
|
||||||
|
}).map(function(item) {
|
||||||
|
return item.id;
|
||||||
}).indexOf(value) > -1 ? [value, ''] : [self.other, value];
|
}).indexOf(value) > -1 ? [value, ''] : [self.other, value];
|
||||||
},
|
},
|
||||||
width: self.options.width
|
width: self.options.width
|
||||||
|
@ -89,8 +91,10 @@ Ox.SelectInput = function(options, self) {
|
||||||
function setValue(isOther) {
|
function setValue(isOther) {
|
||||||
if (
|
if (
|
||||||
(!self.options.value && isOther !== true)
|
(!self.options.value && isOther !== true)
|
||||||
|| Ox.map(self.options.items, function(item) {
|
|| Ox.filter(self.options.items, function(item) {
|
||||||
return item.id != self.other ? item.id : null;
|
return item.id != self.other;
|
||||||
|
}).map(function(item) {
|
||||||
|
return item.id;
|
||||||
}).indexOf(self.options.value) > -1
|
}).indexOf(self.options.value) > -1
|
||||||
) {
|
) {
|
||||||
self.$select.options({
|
self.$select.options({
|
||||||
|
|
|
@ -154,8 +154,8 @@ Ox.Chart = function(options, self) {
|
||||||
});
|
});
|
||||||
while (Ox.sum(widths) != totalWidth) {
|
while (Ox.sum(widths) != totalWidth) {
|
||||||
max = Ox.max(widths);
|
max = Ox.max(widths);
|
||||||
maxKeys = Ox.map(Object.keys(widths), function(key) {
|
maxKeys = Object.keys(widths).filter(function(key) {
|
||||||
return widths[key] == max ? key : null;
|
return widths[key] == max;
|
||||||
});
|
});
|
||||||
widths[maxKeys[0]] += Ox.sum(widths) < totalWidth ? 1 : -1;
|
widths[maxKeys[0]] += Ox.sum(widths) < totalWidth ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,16 +160,13 @@ Ox.IconItem = function(options, self) {
|
||||||
text = Ox.isArray(text) ? text.join(', ') : text;
|
text = Ox.isArray(text) ? text.join(', ') : text;
|
||||||
var lines = Ox.wordwrap(text, maxLength, '\n', true, false).split('\n');
|
var lines = Ox.wordwrap(text, maxLength, '\n', true, false).split('\n');
|
||||||
return Ox.highlightHTML(
|
return Ox.highlightHTML(
|
||||||
Ox.map(lines, function(line, i) {
|
lines.slice(0, maxLines).map(function(line, i) {
|
||||||
if (i < maxLines - 1) {
|
return i < maxLines - 1 || lines.length == maxLines
|
||||||
return line;
|
? line
|
||||||
} else if (i == maxLines - 1) {
|
: Ox.truncate(
|
||||||
return lines.length == maxLines ? line : Ox.truncate(lines.map(function(line, i) {
|
lines.slice(maxLines).join(' '),
|
||||||
return i < maxLines - 1 ? null : line;
|
maxLength, '...', 'center'
|
||||||
}).join(' '), maxLength, '...', 'center');
|
);
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}).join(' <br/>'),
|
}).join(' <br/>'),
|
||||||
self.options.find, 'OxHighlight', ['br']
|
self.options.find, 'OxHighlight', ['br']
|
||||||
).replace(/ (<.*?>)?<br\/>/g, ' $1<br\/>');
|
).replace(/ (<.*?>)?<br\/>/g, ' $1<br\/>');
|
||||||
|
|
|
@ -183,8 +183,10 @@ Ox.TextList = function(options, self) {
|
||||||
max: -1,
|
max: -1,
|
||||||
min: 1,
|
min: 1,
|
||||||
type: 'image',
|
type: 'image',
|
||||||
value: Ox.map(self.options.columns, function(column) {
|
value: Ox.filter(self.options.columns, function(column) {
|
||||||
return column.visible ? column.id : null;
|
return column.visible;
|
||||||
|
}).map(function(column) {
|
||||||
|
return column.id;
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.bindEvent('change', changeColumns)
|
.bindEvent('change', changeColumns)
|
||||||
|
|
|
@ -160,7 +160,7 @@ Ox.TreeList = function(options, self) {
|
||||||
if (type == 'array' || type == 'object') {
|
if (type == 'array' || type == 'object') {
|
||||||
ret.title += Ox.toTitleCase(type)
|
ret.title += Ox.toTitleCase(type)
|
||||||
+ ' <span class="OxLight">[' + Ox.len(value) + ']</span>';
|
+ ' <span class="OxLight">[' + Ox.len(value) + ']</span>';
|
||||||
ret.items = Ox.map(Ox.sort(Ox.keys(value)), function(k) {
|
ret.items = Ox.sort(Ox.keys(value).map(function(k) {
|
||||||
return parseData(k, value[k]);
|
return parseData(k, value[k]);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -328,7 +328,7 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAnnotations() {
|
function getAnnotations() {
|
||||||
return Ox.map(self.options.items, function(item) {
|
return Ox.filter(self.options.items, function(item) {
|
||||||
return self.editing && item.id == self.options.selected || (
|
return self.editing && item.id == self.options.selected || (
|
||||||
(
|
(
|
||||||
self.options.range == 'all' || (
|
self.options.range == 'all' || (
|
||||||
|
@ -344,7 +344,7 @@ Ox.AnnotationFolder = function(options, self) {
|
||||||
self.options.users == 'all'
|
self.options.users == 'all'
|
||||||
|| self.options.users.indexOf(item.user) > -1
|
|| self.options.users.indexOf(item.user) > -1
|
||||||
)
|
)
|
||||||
) ? item : null;
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -425,11 +425,11 @@ Ox.VideoEditor = function(options, self) {
|
||||||
{key: 'G', action: 'Go to Next Result'},
|
{key: 'G', action: 'Go to Next Result'},
|
||||||
{key: Ox.UI.symbols['return'], action: 'Edit/Submit'},
|
{key: Ox.UI.symbols['return'], action: 'Edit/Submit'},
|
||||||
{key: Ox.UI.symbols.escape, action: 'Cancel/Deselect'}
|
{key: Ox.UI.symbols.escape, action: 'Cancel/Deselect'}
|
||||||
], Ox.map(self.options.layers, function(layer, i) {
|
], Ox.filter(self.options.layers.map(function(layer, i) {
|
||||||
return layer.editable
|
return layer.editable
|
||||||
? {key: i + 1, action: 'Add ' + layer.item}
|
? {key: i + 1, action: 'Add ' + layer.item}
|
||||||
: null;
|
: null;
|
||||||
})).forEach(function(shortcut) {
|
}))).forEach(function(shortcut) {
|
||||||
self.$keyboardShortcuts.append(
|
self.$keyboardShortcuts.append(
|
||||||
$('<div>').css({display: 'table-row'})
|
$('<div>').css({display: 'table-row'})
|
||||||
.append(
|
.append(
|
||||||
|
|
|
@ -1175,14 +1175,27 @@ Ox.VideoPlayer = function(options, self) {
|
||||||
var results = [];
|
var results = [];
|
||||||
if (query.length) {
|
if (query.length) {
|
||||||
query = query.toLowerCase();
|
query = query.toLowerCase();
|
||||||
results = Ox.map(self.options.annotations, function(annotation) {
|
results = Ox.filter(self.options.annotations, function(annotation) {
|
||||||
return Ox.decodeHTML(Ox.stripTags(
|
return Ox.decodeHTML(Ox.stripTags(
|
||||||
annotation.text.toLowerCase()
|
annotation.text.toLowerCase()
|
||||||
)).indexOf(query) > -1 ? {
|
)).indexOf(query) > -1;
|
||||||
|
}).map(function(annotation) {
|
||||||
|
return {
|
||||||
id: annotation.id,
|
id: annotation.id,
|
||||||
'in': annotation['in'],
|
'in': annotation['in'],
|
||||||
out: annotation.out
|
out: annotation.out
|
||||||
} : null;
|
};
|
||||||
|
})
|
||||||
|
results = Ox.filter(self.options.annotations, function(annotation) {
|
||||||
|
return Ox.decodeHTML(Ox.stripTags(
|
||||||
|
annotation.text.toLowerCase()
|
||||||
|
)).indexOf(query) > -1;
|
||||||
|
}).map(function(annotation) {
|
||||||
|
return {
|
||||||
|
id: annotation.id,
|
||||||
|
'in': annotation['in'],
|
||||||
|
out: annotation.out
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//Ox.print('FIND RESULTS:', results);
|
//Ox.print('FIND RESULTS:', results);
|
||||||
|
|
|
@ -496,9 +496,7 @@ Ox.Dialog = function(options, self) {
|
||||||
function setButtons() {
|
function setButtons() {
|
||||||
var buttonsLeft,
|
var buttonsLeft,
|
||||||
buttonsRight,
|
buttonsRight,
|
||||||
index = Ox.map(self.options.buttons, function(v, i) {
|
index = Ox.indexOf(self.options.buttons, Ox.isEmpty);
|
||||||
return Ox.isEmpty(v) ? i : null;
|
|
||||||
})[0];
|
|
||||||
if (index) {
|
if (index) {
|
||||||
buttonsLeft = Ox.sub(self.options.buttons, 0, index);
|
buttonsLeft = Ox.sub(self.options.buttons, 0, index);
|
||||||
buttonsRight = Ox.sub(self.options.buttons, index + 1);
|
buttonsRight = Ox.sub(self.options.buttons, index + 1);
|
||||||
|
|
|
@ -111,6 +111,7 @@ Ox.filter <f> Filters a collection by a given condition
|
||||||
@*/
|
@*/
|
||||||
Ox.filter = function(col, fn, that) {
|
Ox.filter = function(col, fn, that) {
|
||||||
var ret, type = Ox.typeOf(col);
|
var ret, type = Ox.typeOf(col);
|
||||||
|
fn = fn || Ox.identity;
|
||||||
if (type == 'object') {
|
if (type == 'object') {
|
||||||
ret = {};
|
ret = {};
|
||||||
Ox.forEach(col, function(val, key) {
|
Ox.forEach(col, function(val, key) {
|
||||||
|
@ -303,6 +304,16 @@ Ox.indexOf = function(col, fn) {
|
||||||
return index == col.length ? -1 : index;
|
return index == col.length ? -1 : index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// FIXME: use this instead of `Ox.filter(Ox.map())` when it's just about getting
|
||||||
|
// the original indices
|
||||||
|
Ox.indicesOf = function(col, fn) {
|
||||||
|
return Ox.map(col, function(val, i) {
|
||||||
|
return fn(val) ? i : null;
|
||||||
|
}).filter(function(index) {
|
||||||
|
return index !== null;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.isEmpty <f> Tests if a value is an empty array, object or string
|
Ox.isEmpty <f> Tests if a value is an empty array, object or string
|
||||||
(value) -> <b> True if the value is an empty array, object or string
|
(value) -> <b> True if the value is an empty array, object or string
|
||||||
|
@ -460,8 +471,7 @@ Ox.makeObject = function(arr) {
|
||||||
/*@
|
/*@
|
||||||
Ox.map <f> Transforms the values of an array, object or string
|
Ox.map <f> Transforms the values of an array, object or string
|
||||||
Unlike <code>[].map()</code>, <code>Ox.map()</code> works for arrays,
|
Unlike <code>[].map()</code>, <code>Ox.map()</code> works for arrays,
|
||||||
objects and strings. Returning <code>null</code> from the iterator
|
objects and strings.
|
||||||
function will remove the element from the collection.
|
|
||||||
> Ox.map([0, 0, 0], function(v, i) { return v == i; })
|
> Ox.map([0, 0, 0], function(v, i) { return v == i; })
|
||||||
[true, false, false]
|
[true, false, false]
|
||||||
> Ox.map({a: 'a', b: 'a', c: 'a'}, function(v, k) { return v == k; })
|
> Ox.map({a: 'a', b: 'a', c: 'a'}, function(v, k) { return v == k; })
|
||||||
|
@ -474,21 +484,19 @@ Ox.map <f> Transforms the values of an array, object or string
|
||||||
# > Ox.map([,], function(v, i) { return i; })
|
# > Ox.map([,], function(v, i) { return i; })
|
||||||
# [0]
|
# [0]
|
||||||
@*/
|
@*/
|
||||||
|
Ox.map = function(col, fn, that) {
|
||||||
// FIXME: it would sometimes be nice to have Ox.map(3, function(i) {...})
|
var type = Ox.typeOf(col), ret;
|
||||||
// instead of Ox.range(3).map(function(i) {...})
|
if (type == 'object') {
|
||||||
|
ret = {};
|
||||||
Ox.map = function(obj, fn) {
|
Ox.forEach(col, function(val, key) {
|
||||||
// fixme: return null to filter out may be a bit esoteric
|
ret[key] = fn.call(that, val, key, col);
|
||||||
var isObject = Ox.isObject(obj),
|
|
||||||
ret = isObject ? {} : [];
|
|
||||||
Ox.forEach(obj, function(val, key) {
|
|
||||||
// FIXME: is there any reason for this strange assignment?
|
|
||||||
var map;
|
|
||||||
if ((map = fn(val, key)) !== null) {
|
|
||||||
ret[isObject ? key : ret.length] = map;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
ret = Ox.toArray(col).map(fn);
|
||||||
|
if (type == 'string') {
|
||||||
|
ret = ret.join('');
|
||||||
|
}
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,9 @@ Ox.getDateInWeek = function(date, weekday, utc) {
|
||||||
date = Ox.makeDate(date);
|
date = Ox.makeDate(date);
|
||||||
var sourceWeekday = Ox.getISODay(date, utc),
|
var sourceWeekday = Ox.getISODay(date, utc),
|
||||||
targetWeekday = Ox.isNumber(weekday) ? weekday
|
targetWeekday = Ox.isNumber(weekday) ? weekday
|
||||||
: Ox.map(Ox.WEEKDAYS, function(v, i) {
|
: Ox.indexOf(Ox.WEEKDAYS, function(v) {
|
||||||
return v.substr(0, 3) == weekday.substr(0, 3) ? i + 1 : null;
|
return v.substr(0, 3) == weekday.substr(0, 3);
|
||||||
})[0];
|
}) + 1;
|
||||||
return Ox.setDate(date, Ox.getDate(date, utc) - sourceWeekday + targetWeekday, utc);
|
return Ox.setDate(date, Ox.getDate(date, utc) - sourceWeekday + targetWeekday, utc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,9 +71,9 @@ Ox.getDaysInMonth <f> Get the number of days in a given month
|
||||||
Ox.getDaysInMonth = function(year, month) {
|
Ox.getDaysInMonth = function(year, month) {
|
||||||
year = Ox.makeYear(year);
|
year = Ox.makeYear(year);
|
||||||
month = Ox.isNumber(month) ? month
|
month = Ox.isNumber(month) ? month
|
||||||
: Ox.map(Ox.MONTHS, function(v, i) {
|
: Ox.getIndexOf(Ox.MONTHS, function(v) {
|
||||||
return v.substr(0, 3) == month.substr(0, 3) ? i + 1 : null;
|
return v.substr(0, 3) == month.substr(0, 3);
|
||||||
})[0];
|
}) + 1;
|
||||||
return new Date(year, month, 0).getDate();
|
return new Date(year, month, 0).getDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -279,8 +279,9 @@
|
||||||
Ox.encodeHTML = function(str) {
|
Ox.encodeHTML = function(str) {
|
||||||
return Ox.map(str.toString(), function(v) {
|
return Ox.map(str.toString(), function(v) {
|
||||||
var code = v.charCodeAt(0);
|
var code = v.charCodeAt(0);
|
||||||
return code < 128 ? (v in Ox.HTML_ENTITIES ? Ox.HTML_ENTITIES[v] : v) :
|
return code < 128
|
||||||
'&#x' + Ox.pad(code.toString(16).toUpperCase(), 4) + ';';
|
? (v in Ox.HTML_ENTITIES ? Ox.HTML_ENTITIES[v] : v)
|
||||||
|
: '&#x' + Ox.pad(code.toString(16).toUpperCase(), 4) + ';';
|
||||||
}).join('');
|
}).join('');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -366,9 +366,9 @@ Ox.formatDateRangeDuration = function(start, end, utc) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return Ox.map(values, function(value, i) {
|
return Ox.filter(Ox.map(values, function(value, i) {
|
||||||
return value ? value + ' ' + keys[i] + (value > 1 ? 's' : '') : null;
|
return value ? value + ' ' + keys[i] + (value > 1 ? 's' : '') : '';
|
||||||
}).join(' ');
|
})).join(' ');
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
|
@ -450,7 +450,7 @@ Ox.formatDuration = function(/*sec, dec, format*/) {
|
||||||
str.shift();
|
str.shift();
|
||||||
pad.shift();
|
pad.shift();
|
||||||
}
|
}
|
||||||
return Ox.map(val, function(v, i) {
|
return Ox.filter(Ox.map(val, function(v, i) {
|
||||||
var ret;
|
var ret;
|
||||||
if (!format) {
|
if (!format) {
|
||||||
ret = Ox.pad(v, pad[i]);
|
ret = Ox.pad(v, pad[i]);
|
||||||
|
@ -458,10 +458,10 @@ Ox.formatDuration = function(/*sec, dec, format*/) {
|
||||||
ret = v + (format == 'long' ? ' ' : '') + str[i]
|
ret = v + (format == 'long' ? ' ' : '') + str[i]
|
||||||
+ (format == 'long' && v != 1 ? 's' : '');
|
+ (format == 'long' && v != 1 ? 's' : '');
|
||||||
} else {
|
} else {
|
||||||
ret = null;
|
ret = '';
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}).join(!format ? ':' : ' ');
|
})).join(!format ? ':' : ' ');
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
|
|
|
@ -356,11 +356,11 @@
|
||||||
ne: {lat: 90, lng: ret.sw.lng}
|
ne: {lat: 90, lng: ret.sw.lng}
|
||||||
}];
|
}];
|
||||||
function containsGaps(area) {
|
function containsGaps(area) {
|
||||||
return Ox.map(gaps, function(gap, i) {
|
return Ox.getIndices(gaps, function(gap) {
|
||||||
return Ox.containsArea({
|
return Ox.containsArea({
|
||||||
sw: {lat: -90, lng: area.sw.lng},
|
sw: {lat: -90, lng: area.sw.lng},
|
||||||
ne: {lat: 90, lng: area.ne.lng}
|
ne: {lat: 90, lng: area.ne.lng}
|
||||||
}, gap) ? i : null;
|
}, gap);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function intersectsWithGaps(area) {
|
function intersectsWithGaps(area) {
|
||||||
|
|
|
@ -42,7 +42,7 @@ Ox.doc <f> Generates documentation for annotated JavaScript
|
||||||
Ox.doc = (function() {
|
Ox.doc = (function() {
|
||||||
// fixme: dont require the trailing '@'
|
// fixme: dont require the trailing '@'
|
||||||
var re = {
|
var re = {
|
||||||
item: /^(.+?) <(.+?)> (.+)$/,
|
item: /^(.+?) <(.+?)>(.*?)$/,
|
||||||
multiline: /^\/\*\@.*?\n([\w\W]+)\n.*?\@\*\/$/,
|
multiline: /^\/\*\@.*?\n([\w\W]+)\n.*?\@\*\/$/,
|
||||||
script: /\n(\s*<script>s*\n[\w\W]+\n\s*<\/script>s*)/g,
|
script: /\n(\s*<script>s*\n[\w\W]+\n\s*<\/script>s*)/g,
|
||||||
singleline: /^\/\/@\s*(.*?)\s*$/,
|
singleline: /^\/\/@\s*(.*?)\s*$/,
|
||||||
|
@ -122,9 +122,10 @@ Ox.doc = (function() {
|
||||||
var lines = decodeLinebreaks(str).split('\n'),
|
var lines = decodeLinebreaks(str).split('\n'),
|
||||||
indent = getIndent(lines[1]);
|
indent = getIndent(lines[1]);
|
||||||
return {
|
return {
|
||||||
statement: Ox.map(lines, function(line, i) {
|
statement: Ox.filter(lines, function(line, i) {
|
||||||
return i && i < lines.length - 1 ?
|
return i && i < lines.length - 1;
|
||||||
line.substr(indent) : null;
|
}).map(lines, function(line, i) {
|
||||||
|
return line.substr(indent);
|
||||||
}).join('\n')
|
}).join('\n')
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -336,7 +337,7 @@ Ox.minify = function() {
|
||||||
'number', 'method', 'object', 'property'
|
'number', 'method', 'object', 'property'
|
||||||
].indexOf(token.type) > -1;
|
].indexOf(token.type) > -1;
|
||||||
}
|
}
|
||||||
return Ox.map(tokens, function(token, i) {
|
return Ox.filter(Ox.map(tokens, function(token, i) {
|
||||||
var ret = source.substr(token.offset, token.length);
|
var ret = source.substr(token.offset, token.length);
|
||||||
if (token.type == 'comment') {
|
if (token.type == 'comment') {
|
||||||
if (ret[1] == '/') {
|
if (ret[1] == '/') {
|
||||||
|
@ -348,8 +349,7 @@ Ox.minify = function() {
|
||||||
ret = i == length - 1 || tokens[i + 1].type == 'whitespace'
|
ret = i == length - 1 || tokens[i + 1].type == 'whitespace'
|
||||||
? null : ' ';
|
? null : ' ';
|
||||||
}
|
}
|
||||||
}
|
} else if (token.type == 'linebreak' || token.type == 'whitespace') {
|
||||||
if (token.type == 'linebreak' || token.type == 'whitespace') {
|
|
||||||
// remove consecutive linebreaks or whitespace
|
// remove consecutive linebreaks or whitespace
|
||||||
ret = ret[0];
|
ret = ret[0];
|
||||||
}
|
}
|
||||||
|
@ -392,7 +392,7 @@ Ox.minify = function() {
|
||||||
ret = null;
|
ret = null;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}).join('');
|
})).join('');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,9 @@ Ox.clean <f> Remove leading, trailing and double whitespace from a string
|
||||||
"foo bar"
|
"foo bar"
|
||||||
@*/
|
@*/
|
||||||
Ox.clean = function(str) {
|
Ox.clean = function(str) {
|
||||||
return Ox.map(str.split('\n'), function(str) {
|
return Ox.filter(Ox.map(str.split('\n'), function(str) {
|
||||||
return Ox.trim(str.replace(/\s+/g, ' ')) || null;
|
return Ox.trim(str.replace(/\s+/g, ' ')) || '';
|
||||||
}).join('\n');
|
})).join('\n');
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
|
@ -481,7 +481,7 @@ Ox.toTitleCase <f> Returns a string with capitalized words
|
||||||
'Apple Releases iPhone, IBM Stock Plummets'
|
'Apple Releases iPhone, IBM Stock Plummets'
|
||||||
@*/
|
@*/
|
||||||
Ox.toTitleCase = function(str) {
|
Ox.toTitleCase = function(str) {
|
||||||
return Ox.map(str.split(' '), function(val) {
|
return str.split(' ').map(function(val) {
|
||||||
var sub = val.substr(1),
|
var sub = val.substr(1),
|
||||||
low = sub.toLowerCase();
|
low = sub.toLowerCase();
|
||||||
if (sub == low) {
|
if (sub == low) {
|
||||||
|
@ -603,7 +603,7 @@ Ox.wordwrap = function(str, len, sep, bal, spa) {
|
||||||
if (lines.length > 1) {
|
if (lines.length > 1) {
|
||||||
// test shorter line, unless
|
// test shorter line, unless
|
||||||
// that means cutting a word
|
// that means cutting a word
|
||||||
var max = Ox.max(Ox.map(words, function(word) {
|
var max = Ox.max(words.map(function(word) {
|
||||||
return word.length;
|
return word.length;
|
||||||
}));
|
}));
|
||||||
while (len > max) {
|
while (len > max) {
|
||||||
|
@ -637,7 +637,7 @@ Ox.wordwrap = function(str, len, sep, bal, spa) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!spa) {
|
if (!spa) {
|
||||||
lines = Ox.map(lines, function(line) {
|
lines = lines.map(function(line) {
|
||||||
return Ox.trim(line);
|
return Ox.trim(line);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue