@daeinc/dom
Advanced tools
Comparing version 0.3.1 to 0.4.0
@@ -8,7 +8,15 @@ /** | ||
/** | ||
* convert selector (string) to DOM Element. if already typeof Element, return as is. | ||
* convert selector (string) to Element. if already typeof Element, return as is. | ||
* | ||
* @param selector | ||
* @returns | ||
*/ | ||
export declare const toDomElement: (selector: string | Element) => Element; | ||
export declare const toElement: (selector: string | Element) => Element; | ||
/** | ||
* convert selector (string) to HTMLElement. if already typeof HTMLElement, return as is. | ||
* | ||
* @param selector | ||
* @returns | ||
*/ | ||
export declare const toHTMLElement: (selector: string | HTMLElement) => HTMLElement; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toDomElement = exports.appendChild = void 0; | ||
/** | ||
@@ -9,6 +7,8 @@ * append child to parent. if parent is undefined, append child to body | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toHTMLElement = exports.toElement = exports.appendChild = void 0; | ||
const appendChild = (parent, child) => { | ||
child = (0, exports.toDomElement)(child); | ||
child = (0, exports.toElement)(child); | ||
if (parent !== undefined) { | ||
parent = (0, exports.toDomElement)(parent); | ||
parent = (0, exports.toElement)(parent); | ||
parent.appendChild(child); | ||
@@ -22,7 +22,8 @@ } | ||
/** | ||
* convert selector (string) to DOM Element. if already typeof Element, return as is. | ||
* convert selector (string) to Element. if already typeof Element, return as is. | ||
* | ||
* @param selector | ||
* @returns | ||
*/ | ||
const toDomElement = (selector) => { | ||
const toElement = (selector) => { | ||
if (typeof selector === "string") { | ||
@@ -37,3 +38,20 @@ const element = document.querySelector(selector); | ||
}; | ||
exports.toDomElement = toDomElement; | ||
exports.toElement = toElement; | ||
/** | ||
* convert selector (string) to HTMLElement. if already typeof HTMLElement, return as is. | ||
* | ||
* @param selector | ||
* @returns | ||
*/ | ||
const toHTMLElement = (selector) => { | ||
if (typeof selector === "string") { | ||
const element = document.querySelector(selector); | ||
if (!element) { | ||
throw new Error(`could not find the element with the selector: ${selector}`); | ||
} | ||
return element; | ||
} | ||
return selector; | ||
}; | ||
exports.toHTMLElement = toHTMLElement; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@daeinc/dom", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "DOM utilities", | ||
@@ -14,3 +14,3 @@ "types": "./dist/index.d.ts", | ||
"demo": "parcel ./demo/demo.html --no-cache --dist-dir ./demo/build/", | ||
"build": "npx tsc --build --clean && npx tsc --build" | ||
"build": "tsc --build --clean && tsc --build" | ||
}, | ||
@@ -17,0 +17,0 @@ "author": "Daeinc", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
5977
73