vanillajs-browser-helpers
Version:
Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser
31 lines (30 loc) • 906 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var selectorToHTML_1 = __importDefault(require("./selectorToHTML"));
/**
* Parses a string to see if it is already HTML otherwise it assumes
* is a selector and parses it to HTML
*
* @param htmlOrSelector - The string to parse
* @returns The HTML string
*
* @example
*
* ```ts
* // String is already HTML so it is returned as is
* ensureHTML('<div />');
*
* // String is a selector, to is is parsed before it is returned
* ensureHTML('.my-div');
* // -> <div class="my-div" />
* ```
*/
function ensureHTML(htmlOrSelector) {
return htmlOrSelector.includes('<')
? htmlOrSelector
: selectorToHTML_1.default(htmlOrSelector);
}
exports.default = ensureHTML;