This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const kebabCase = (camelCased: string) => | |
| camelCased.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(); | |
| export const toCssText = (styles: object) => | |
| Object.keys(styles) | |
| // @ts-ignore: trust input is a CSSStyleDeclaration | |
| .flatMap(prop => [kebabCase(prop), ":", styles[prop], ";"]) | |
| .join(""); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const htmlSpecialChars = [ | |
| ["&", "&"], | |
| [">", ">"], | |
| ["<", "<"], | |
| ]; | |
| const encode = (data: string) => | |
| htmlSpecialChars.reduce( | |
| (data, [char, entity]) => data.replaceAll(char, entity), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function onNode(root, selector, handler) { | |
| const target = root.querySelector(selector); | |
| if (target) return handler(target); | |
| new MutationObserver((records, observer) => { | |
| const target = records | |
| .filter(record => record.type === "childList") | |
| .flatMap(record => record.addedNodes) | |
| .find(node => node.nodeType === 1 && node.matches(selector)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isObject(obj: any) { | |
| return typeof obj === "object" && obj !== null; | |
| } | |
| function isPlainObject(obj: any) { | |
| return Object.getPrototypeOf(obj).constructor === Object; | |
| } | |
| /** | |
| * used to deep merge json serializable objects. |
OlderNewer