UNPKG

html-squircle

Version:

Utilities for generating superellipse squircles in the form of SVG strings, to be used in clip-path and background inline styles.

12 lines 744 B
import { isObject } from "./isObject.js"; const handleStringTuple = input => input.join(":"); const handleEntry = ([key, value]) => value === true ? ` ${key}` : ` ${key}='${isObject(value) ? Object.entries(value).map(handleStringTuple).join(";") : value}'`; /** * @param tagName A HTML or SVG element tag name. * @param attributes A `string`-keyed record of `string`, `number`, `true`, or * `string`-keyed record of strings (like CSS properties). * @param children Any number of strings to add as children between the tag open * and close. * @returns XML tag as string. */ export const tag = (tagName, attributes, ...children) => `<${tagName}${Object.entries(attributes).map(handleEntry).join("")}>${children.join("")}</${tagName}>`;