UNPKG

@prabink/react-node-cli

Version:

React Node Application Generator & Helpers To Serve React Build, Push to github & Export industry level react project structure

69 lines (63 loc) 1.73 kB
/** * This will check if the given object has any children * @param {object} item * @returns */ export function hasChildren(item) { const { children } = item; if (children === undefined) { return false; } if (children.constructor !== Array) { return false; } if (children.length === 0) { return false; } return true; } /** * Check if given date is expired from today's date * @param {Date|string} date * @returns */ export function isExpired(date){ return new Date(date).getTime() < new Date().getTime() } // ############################## // // // Function that converts from hex color to rgb color // // // Example: input = #9c27b0 => output = 156, 39, 176 // // // Example: input = 9c27b0 => output = 156, 39, 176 // // // Example: input = #999 => output = 153, 153, 153 // // // Example: input = 999 => output = 153, 153, 153 // ############################# /** * Convert HEX color to RGB color * @param {string} input * @returns */ export const hexToRgb = (input) => { input = input + ""; input = input.replace("#", ""); let hexRegex = /[0-9A-Fa-f]/g; if (!hexRegex.test(input) || (input.length !== 3 && input.length !== 6)) { throw new Error("input is not a valid hex color."); } if (input.length === 3) { let first = input[0]; let second = input[1]; let last = input[2]; input = first + first + second + second + last + last; } input = input.toUpperCase(); let first = input[0] + input[1]; let second = input[2] + input[3]; let last = input[4] + input[5]; return ( parseInt(first, 16) + ", " + parseInt(second, 16) + ", " + parseInt(last, 16) ); };