forked from elm/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Char.js
31 lines (28 loc) · 1.37 KB
/
Char.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Elm.Native.Char = {};
Elm.Native.Char.make = function(elm) {
elm.Native = elm.Native || {};
elm.Native.Char = elm.Native.Char || {};
if (elm.Native.Char.values) return elm.Native.Char.values;
var Utils = Elm.Native.Utils.make(elm);
function isBetween(lo,hi) { return function(chr) {
var c = chr.charCodeAt(0);
return lo <= c && c <= hi;
};
}
var isDigit = isBetween('0'.charCodeAt(0),'9'.charCodeAt(0));
var chk1 = isBetween('a'.charCodeAt(0),'f'.charCodeAt(0));
var chk2 = isBetween('A'.charCodeAt(0),'F'.charCodeAt(0));
return elm.Native.Char.values = {
fromCode : function(c) { return String.fromCharCode(c); },
toCode : function(c) { return c.toUpperCase().charCodeAt(0); },
toUpper : function(c) { return Utils.chr(c.toUpperCase()); },
toLower : function(c) { return Utils.chr(c.toLowerCase()); },
toLocaleUpper : function(c) { return Utils.chr(c.toLocaleUpperCase()); },
toLocaleLower : function(c) { return Utils.chr(c.toLocaleLowerCase()); },
isLower : isBetween('a'.charCodeAt(0),'z'.charCodeAt(0)),
isUpper : isBetween('A'.charCodeAt(0),'Z'.charCodeAt(0)),
isDigit : isDigit,
isOctDigit : isBetween('0'.charCodeAt(0),'7'.charCodeAt(0)),
isHexDigit : function(c) { return isDigit(c) || chk1(c) || chk2(c); }
};
};