1
0
Fork 0
forked from 0x2620/oxjs

less obscure Ox.map

This commit is contained in:
rolux 2012-05-22 16:29:37 +02:00
commit 12cf77cef5
21 changed files with 125 additions and 101 deletions

View file

@ -31,9 +31,9 @@ Ox.clean <f> Remove leading, trailing and double whitespace from a string
"foo bar"
@*/
Ox.clean = function(str) {
return Ox.map(str.split('\n'), function(str) {
return Ox.trim(str.replace(/\s+/g, ' ')) || null;
}).join('\n');
return Ox.filter(Ox.map(str.split('\n'), function(str) {
return Ox.trim(str.replace(/\s+/g, ' ')) || '';
})).join('\n');
};
/*@
@ -481,7 +481,7 @@ Ox.toTitleCase <f> Returns a string with capitalized words
'Apple Releases iPhone, IBM Stock Plummets'
@*/
Ox.toTitleCase = function(str) {
return Ox.map(str.split(' '), function(val) {
return str.split(' ').map(function(val) {
var sub = val.substr(1),
low = sub.toLowerCase();
if (sub == low) {
@ -603,7 +603,7 @@ Ox.wordwrap = function(str, len, sep, bal, spa) {
if (lines.length > 1) {
// test shorter line, unless
// 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;
}));
while (len > max) {
@ -637,7 +637,7 @@ Ox.wordwrap = function(str, len, sep, bal, spa) {
}
});
if (!spa) {
lines = Ox.map(lines, function(line) {
lines = lines.map(function(line) {
return Ox.trim(line);
});
}