noliter
v1.1.0
Published
Write code with no literal
Downloads
19
Readme
Noliter
Write code with no literal
Install
npm i -D noliter
API
createTagName
Create html element with builder.
Type
declare type HTMLElementTagNames = keyof HTMLElementTagNameMap;
declare type Builder<H extends HTMLElementTagNames> = (element: HTMLElementTagNameMap[H]) => void;
declare function createAnchor(builder?: Builder<"a">): HTMLAnchorElement;
declare function createInput(builder?: Builder<"input">): HTMLElement;
declare function createSpan(builder?: Builder<"span">): HTMLElement;
...
Example
createAnchor((anchor) => {
anchor.href = 'https://www.google.com/';
anchor.appendChild(createSpan((span) => {
span.textContent = 'Google';
}));
});
createInput((input) => {
input.value = 'This is example!';
});
joinClassNames
Joins multiple classNames into a single string.
Type
declare function joinClassNames(...classNames: (undefined | null | boolean | number | string)[]): string;
Example
element.className = joinClassNames('header', isOpen && 'open');
removeChildren
Remove all of children from element.
Type
declare function removeChildren<N extends Node>(parent: N): void;
Example
removeChildren(element);
isEmail
Returns true if parameter is form of email, otherwise returns false.
Type
declare function isEmail(str: string): any;
Example
isEmail("[email protected]") === true;
isEmail("A@b@[email protected]") === false;
matchNumber
Filter only numbers from string.
Type
declare function matchNumber(str: string): RegExpMatchArray;
Example
matchNumber("1a39b02c8") === ["1", "39", "2", "8"];
removeWhitespace
Remove all of whitespace from string.
Type
declare function removeWhitespace(str: string): string;
Example
removeWhitespace(" t es t ") === "test";
removeXmlTag
Remove all of xml tag from string.
Type
declare function removeXmlTag(str: string): string;
Example
removeXmlTag("<p>test</p>") === "test";
removeCharacterReference
Remove all of character reference from string.
Type
declare function removeCharacterReference(str: string): string;
Example
removeCharacterReference("&nsbp;tes&nsbp;t") === "test";