elm/libraries/Native/Char.js
Evan Czaplicki b40f2958d4 New convention for storing module values, fixes bug
Before it was not possible to add values to anything except leafs of
the namespace structure.
2013-09-30 01:32:27 -07:00

29 lines
1.3 KiB
JavaScript

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;
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 c.toUpperCase(); },
toLower : function(c) { return c.toLowerCase(); },
toLocaleUpper : function(c) { return c.toLocaleUpperCase(); },
toLocaleLower : function(c) { return 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); }
};
};