47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
import isValidTag from "./isValidTag";
|
|
|
|
/**
|
|
* @param {HTMLElement} element
|
|
* @param {string[]} classlist
|
|
*/
|
|
export function addClasslist(element, ...classlist) {
|
|
element.classList.add(...classlist);
|
|
}
|
|
|
|
export function isArray(value) {
|
|
return value instanceof Array;
|
|
}
|
|
|
|
export function isObject(value) {
|
|
return value instanceof Object;
|
|
}
|
|
|
|
export function selectId(selector) {
|
|
return document.querySelector(selector.startsWith('#') ? selector : `#${selector}`);
|
|
}
|
|
|
|
export function selectClass(selector) {
|
|
return document.querySelector(selector.startsWith('.') ? selector : `.${selector}`);
|
|
}
|
|
|
|
export function selectTag(selector) {
|
|
return isValidTag(selector) ? document.querySelector(selector) : null;
|
|
}
|
|
|
|
export function pushStyles(element, styles) {
|
|
for (const [key, value] of Object.entries(styles)) {
|
|
element.style[key] = value;
|
|
}
|
|
}
|
|
|
|
export function elementHasIdOrClass(element) {
|
|
return isValidTag(selector) ? (element.id !== "" && element.className !== "") : false;
|
|
}
|
|
|
|
export function hexToRGB(hex) {
|
|
const hexValue = hex.replace('#', '');
|
|
const r = parseInt(hexValue.substring(0, 2), 16);
|
|
const g = parseInt(hexValue.substring(2, 4), 16);
|
|
const b = parseInt(hexValue.substring(4, 6), 16);
|
|
return `rgb(${r}, ${g}, ${b})`;
|
|
} |