UNPKG

@pilotlab/lux-attributes

Version:

A luxurious user experience framework, developed by your friends at Pilot.

88 lines 4.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var lux_is_1 = require("@pilotlab/lux-is"); var lux_strings_1 = require("@pilotlab/lux-strings"); var attributeEnums_1 = require("./attributeEnums"); var attributesBase_1 = require("./attributesBase"); var AttributeTools = (function () { function AttributeTools() { } AttributeTools.getBaseDataType = function (dataType) { if (dataType === undefined) return attributeEnums_1.DataType.UNDEFINED; if (lux_is_1.default.empty(dataType)) return attributeEnums_1.DataType.NULL; switch (dataType) { case attributeEnums_1.DataType.STRING_HEX_VALUE: case attributeEnums_1.DataType.STRING_HTML: case attributeEnums_1.DataType.STRING_JAVASCRIPT: case attributeEnums_1.DataType.STRING_JSON: case attributeEnums_1.DataType.STRING_REG_EXP: case attributeEnums_1.DataType.STRING_SVG: case attributeEnums_1.DataType.STRING_URI: case attributeEnums_1.DataType.STRING_XML: case attributeEnums_1.DataType.STRING: return attributeEnums_1.DataType.STRING; case attributeEnums_1.DataType.NUMBER_DOUBLE: case attributeEnums_1.DataType.NUMBER_INT: case attributeEnums_1.DataType.NUMBER: return attributeEnums_1.DataType.NUMBER; default: return dataType; } }; AttributeTools.getDataType = function (value) { var dataType = attributeEnums_1.DataType.ANY; if (value === undefined) return attributeEnums_1.DataType.UNDEFINED; else if (lux_is_1.default.empty(value, true)) return attributeEnums_1.DataType.NULL; else if (value instanceof attributesBase_1.default) dataType = attributeEnums_1.DataType.COLLECTION; else if (Array.isArray(value)) dataType = attributeEnums_1.DataType.ARRAY; else if (value instanceof Date) dataType = attributeEnums_1.DataType.DATE_TIME; else if (value instanceof RegExp) dataType = attributeEnums_1.DataType.REG_EXP; else { switch (typeof value) { case 'boolean': dataType = attributeEnums_1.DataType.BOOLEAN; break; case 'number': attributeEnums_1.DataType.NUMBER; break; case 'function': dataType = attributeEnums_1.DataType.FUNCTION; break; case 'string': if (lux_strings_1.Strings.isValidHexString(value)) dataType = attributeEnums_1.DataType.STRING_HEX_VALUE; else if (value.toLowerCase().indexOf('<html>') > -1) dataType = attributeEnums_1.DataType.STRING_HTML; else if (lux_strings_1.Strings.isSvg(lux_strings_1.Strings.stringToXmlDocument(value))) dataType = attributeEnums_1.DataType.STRING_SVG; else if (lux_strings_1.Strings.isXml(lux_strings_1.Strings.stringToXmlDocument(value))) dataType = attributeEnums_1.DataType.STRING_XML; else if (lux_strings_1.Strings.isDataUrl(value)) dataType = attributeEnums_1.DataType.DATA_URL; else if (lux_strings_1.Strings.isBase64(value)) dataType = attributeEnums_1.DataType.BASE64; else if (lux_strings_1.Strings.isValidUri(value)) dataType = attributeEnums_1.DataType.STRING_URI; else dataType = attributeEnums_1.DataType.STRING; break; case 'object': default: dataType = attributeEnums_1.DataType.OBJECT; } } return dataType; }; return AttributeTools; }()); exports.AttributeTools = AttributeTools; exports.default = AttributeTools; //# sourceMappingURL=attributeTools.js.map