UNPKG

@hv-kit/hexpress

Version:

facilitates typescript backend development with express

147 lines 4.96 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConvertToType = exports.ShowCoverPost = exports.ShowImageProfilePicture = exports.ShowImage = exports.GetSocialNetworkIcon = exports.GetTreeList = exports.ElementsToOptionsElement = void 0; const hexpress_config_json_1 = __importDefault(require("../../../../hexpress.config.json")); const date_1 = require("./date"); const file_sub_1 = require("./file.sub"); const string_1 = require("./string"); function ElementsToOptionsElement(datas, mapFunct = (data) => ({ value: data.code, label: (0, string_1.UcFirst)(data.title), })) { return [ ...[ { value: undefined, label: '-----', }, ], ...datas.map(mapFunct), ]; } exports.ElementsToOptionsElement = ElementsToOptionsElement; function GetTreeList(datas, id = 'code', defaultVal = null, parent = 'parent_code', childrenLabel = 'children') { let res = datas.filter((value, index) => value[parent] === defaultVal); if (res.length > 0) { res = res.map((value, index) => { value[childrenLabel] = datas.filter((value2, index) => value2[parent] === value[id]); value[childrenLabel] = value[childrenLabel].map((value3, index) => { value3[childrenLabel] = GetTreeList(datas, id, value3[id], parent, childrenLabel); return value3; }); return value; }); } if (hexpress_config_json_1.default.debug) { console.log('----> utils.ts > GetTreeList - parent:: ', parent); console.log('----> utils.ts > GetTreeList - defaultVal:: ', defaultVal); console.log('----> utils.ts > GetTreeList - res:: ', res); } return res; } exports.GetTreeList = GetTreeList; function GetSocialNetworkIcon(sn, choice) { const choices = ['icon', 'class']; choice = (choices.includes(choice)) ? choice : 'icon'; const icons = { facebook: { icon: 'fab fa-facebook-f', class: 'sn-facebook-hover', }, twitter: { icon: 'fab fa-twitter', class: 'sn-twitter-hover', }, linkedin: { icon: 'fab fa-linkedin-in', class: 'sn-linkedin-hover', }, youtube: { icon: 'fab fa-youtube-in', class: 'sn-youtube-hover', }, instagram: { icon: 'fab fa-instagram-in', class: 'sn-instagram-hover', }, googleplus: { icon: 'fab fa-googleplus-in', class: 'sn-googleplus-hover', }, snapchat: { icon: 'fab fa-snapchat-in', class: 'sn-snapchat-hover', }, pinterest: { icon: 'fab fa-pinterest-in', class: 'sn-pinterest-hover', }, whatsapp: { icon: 'fab fa-whatsapp-in', class: 'sn-whatsapp-hover', }, }; return (Object.keys(icons).includes(sn)) ? icons[sn][choice] : 'warning_amber'; } exports.GetSocialNetworkIcon = GetSocialNetworkIcon; function ShowImage(data, initial = 'icons/image_black_24dp.svg') { let res; if ((typeof data === 'object' && Array.isArray(data) === true && data.length > 0) || (typeof data === 'string' && data.length > 0)) { res = (0, file_sub_1.ReadBase64)(data); } else { res = initial; } return res; } exports.ShowImage = ShowImage; function ShowImageProfilePicture(data) { return ShowImage(data, 'icons/no-profile-picture.svg'); } exports.ShowImageProfilePicture = ShowImageProfilePicture; function ShowCoverPost(data) { return ShowImage(data, 'images/img-post1.jpg'); } exports.ShowCoverPost = ShowCoverPost; function ConvertToType(data, type) { const types = ['str', 'float', 'int', 'boolean', 'object', 'datetime']; type = (types.includes(type)) ? type : types[0]; let res = data; if (type === 'str') { res = String(data); } else if (type === 'float') { res = parseFloat(data); } else if (type === 'int') { res = parseInt(data); } else if (type === 'boolean') { res = Boolean(data); } else if (type === 'object') { res = Object(data); } else if (type === 'datetime') { res = (0, date_1.StringToDate)(data); } return res; } exports.ConvertToType = ConvertToType; exports.default = { ElementsToOptionsElement, GetTreeList, GetSocialNetworkIcon, ShowImage, ShowImageProfilePicture, ShowCoverPost, ConvertToType, }; //# sourceMappingURL=utils.js.map