update Ox.URL
This commit is contained in:
parent
b7100792c5
commit
2cb6d89a0a
3 changed files with 315 additions and 106 deletions
78
source/Ox.js
78
source/Ox.js
|
|
@ -698,6 +698,12 @@ Ox.isEmpty <f> Returns true if a collection is empty
|
|||
true
|
||||
> Ox.isEmpty(function() {})
|
||||
true
|
||||
> Ox.isEmpty(function(a) {})
|
||||
false
|
||||
> Ox.isEmpty(null)
|
||||
false
|
||||
> Ox.isEmpty()
|
||||
false
|
||||
@*/
|
||||
Ox.isEmpty = function(val) {
|
||||
// fixme: what about deep isEmpty?
|
||||
|
|
@ -771,8 +777,11 @@ Ox.len <f> Returns the length of an array, function, object or string
|
|||
> Ox.len('abc')
|
||||
3
|
||||
@*/
|
||||
Ox.len = function(obj) {
|
||||
return (Ox.isObject(obj) ? Ox.values(obj) : obj).length;
|
||||
Ox.len = function(col) {
|
||||
var type = Ox.typeOf(col);
|
||||
return ['array', 'function', 'string'].indexOf(type) > -1
|
||||
? col.length
|
||||
: type == 'object' ? Ox.values(col).length : void 0;
|
||||
};
|
||||
|
||||
/*@
|
||||
|
|
@ -1253,6 +1262,10 @@ Ox.rgb = function(hsl) {
|
|||
|
||||
//@ Ox.AMPM <[str]> ['AM', 'PM']
|
||||
Ox.AMPM = ['AM', 'PM'];
|
||||
//@ Ox.BASE_32_ALIASES <o> Base 32 aliases
|
||||
Ox.BASE_32_ALIASES = {'I': '1', 'L': '1', 'O': '0', 'U': 'V'},
|
||||
//@ Ox.BASE_32_DIGITS <o> Base 32 digits
|
||||
Ox.BASE_32_DIGITS = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
||||
//@ Ox.BCAD <[str]> ['BC', 'AD']
|
||||
Ox.BCAD = ['BC', 'AD'];
|
||||
// fixme: this is unused, and probably unneeded
|
||||
|
|
@ -1292,7 +1305,8 @@ Ox.KEYS = {
|
|||
108: 'enter.numpad', 110: 'dot.numpad', 111: 'slash.numpad',
|
||||
112: 'f1', 113: 'f2', 114: 'f3', 115: 'f4', 116: 'f5',
|
||||
117: 'f6', 118: 'f7', 119: 'f8', 120: 'f9', 121: 'f10',
|
||||
122: 'f11', 123: 'f12', 124: 'f13', 125: 'f14', 126: 'f15', 127: 'f16',
|
||||
122: 'f11', 123: 'f12', 124: 'f13', 125: 'f14', 126: 'f15',
|
||||
127: 'f16', 128: 'f17', 129: 'f18', 130: 'f19', 131: 'f20',
|
||||
144: 'numlock', 145: 'scrolllock',
|
||||
186: 'semicolon', 187: 'equal', 188: 'comma', 189: 'minus',
|
||||
190: 'dot', 191: 'slash', 192: 'backtick', 219: 'openbracket',
|
||||
|
|
@ -1938,9 +1952,6 @@ Ox.element = function(str) {
|
|||
|
||||
(function() {
|
||||
|
||||
var aliases = {'I': '1', 'L': '1', 'O': '0', 'U': 'V'},
|
||||
digits = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
||||
|
||||
function cap(width, height) {
|
||||
// returns maximum encoding capacity of an image
|
||||
return parseInt(width * height * 3/8) - 4;
|
||||
|
|
@ -1980,6 +1991,29 @@ Ox.element = function(str) {
|
|||
);
|
||||
}
|
||||
|
||||
/*@
|
||||
Ox.encodeBase26 <b> Encode a number as base26
|
||||
> Ox.encodeBase26(3758)
|
||||
'FOO'
|
||||
@*/
|
||||
Ox.encodeBase26 = function(num) {
|
||||
return Ox.map(num.toString(26), function(char) {
|
||||
return Ox.char(65 + parseInt(char, 26));
|
||||
}).join('');
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.decodeBase26 <f> Decodes a base26-encoded number
|
||||
See <a href="http://www.crockford.com/wrmg/base32.html">Base 32</a>.
|
||||
> Ox.decodeBase26('foo')
|
||||
3758
|
||||
@*/
|
||||
Ox.decodeBase26 = function(str) {
|
||||
return parseInt(Ox.map(str.toUpperCase(), function(char) {
|
||||
return (char.charCodeAt(0) - 65).toString(26);
|
||||
}).join(''), 26);
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.encodeBase32 <b> Encode a number as base32
|
||||
See <a href="http://www.crockford.com/wrmg/base32.html">Base 32</a>.
|
||||
|
|
@ -1990,9 +2024,9 @@ Ox.element = function(str) {
|
|||
@*/
|
||||
Ox.encodeBase32 = function(num) {
|
||||
return Ox.map(num.toString(32), function(char) {
|
||||
return digits[parseInt(char, 32)];
|
||||
return Ox.BASE_32_DIGITS[parseInt(char, 32)];
|
||||
}).join('');
|
||||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.decodeBase32 <f> Decodes a base32-encoded number
|
||||
|
|
@ -2006,10 +2040,10 @@ Ox.element = function(str) {
|
|||
@*/
|
||||
Ox.decodeBase32 = function(str) {
|
||||
return parseInt(Ox.map(str.toUpperCase(), function(char) {
|
||||
var index = digits.indexOf(aliases[char] || char);
|
||||
var index = Ox.BASE_32_DIGITS.indexOf(Ox.BASE_32_ALIASES[char] || char);
|
||||
return (index == -1 ? ' ' : index).toString(32);
|
||||
}).join(''), 32);
|
||||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.encodeBase64 <f> Encode a number as base64
|
||||
|
|
@ -2018,7 +2052,7 @@ Ox.element = function(str) {
|
|||
@*/
|
||||
Ox.encodeBase64 = function(num) {
|
||||
return btoa(Ox.encodeBase256(num)).replace(/=/g, '');
|
||||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.decodeBase64 <f> Decodes a base64-encoded number
|
||||
|
|
@ -2027,7 +2061,7 @@ Ox.element = function(str) {
|
|||
@*/
|
||||
Ox.decodeBase64 = function(str) {
|
||||
return Ox.decodeBase256(atob(str));
|
||||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.encodeBase128 <f> Encode a number as base128
|
||||
|
|
@ -2040,8 +2074,8 @@ Ox.element = function(str) {
|
|||
str = Ox.char(num & 127) + str;
|
||||
num >>= 7;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
return str || '0';
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.decodeBase128 <f> Decode a base128-encoded number
|
||||
|
|
@ -2054,7 +2088,7 @@ Ox.element = function(str) {
|
|||
num += char.charCodeAt(0) << (len - i - 1) * 7;
|
||||
});
|
||||
return num;
|
||||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.encodeBase256 <f> Encode a number as base256
|
||||
|
|
@ -2068,7 +2102,7 @@ Ox.element = function(str) {
|
|||
num >>= 8;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.decodeBase256 <f> Decode a base256-encoded number
|
||||
|
|
@ -2081,7 +2115,7 @@ Ox.element = function(str) {
|
|||
num += char.charCodeAt(0) << (len - i - 1) * 8;
|
||||
});
|
||||
return num;
|
||||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.encodeDeflate <f> Encodes a string, using deflate
|
||||
|
|
@ -2127,7 +2161,7 @@ Ox.element = function(str) {
|
|||
}
|
||||
callback && callback(data);
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.decodeDeflate <f> Decodes an deflate-encoded string
|
||||
|
|
@ -2179,7 +2213,7 @@ Ox.element = function(str) {
|
|||
}
|
||||
image.onerror = error;
|
||||
image.src = 'data:image/png;base64,' + btoa(data);
|
||||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.encodeHTML <f> HTML-encodes a string
|
||||
|
|
@ -2261,7 +2295,7 @@ Ox.element = function(str) {
|
|||
(and flip the second least significant bit, if at all)
|
||||
- write an extra png chunk containing some key
|
||||
*/
|
||||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.decodePNG <f> Decodes an image, returns a string
|
||||
|
|
@ -2306,7 +2340,7 @@ Ox.element = function(str) {
|
|||
} catch (e) {
|
||||
throw new RangeError('PNG codec can\'t decode image');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.encodeUTF8 <f> Encodes a string as UTF-8
|
||||
|
|
@ -2334,7 +2368,7 @@ Ox.element = function(str) {
|
|||
}
|
||||
return str;
|
||||
}).join('');
|
||||
}
|
||||
};
|
||||
|
||||
/*@
|
||||
Ox.decodeUTF8 <f> Decodes an UTF-8-encoded string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue