1.1.0 • Published 2 years ago

noliter v1.1.0

Weekly downloads
15
License
MIT
Repository
-
Last release
2 years ago

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("simple@example.com") === true;
isEmail("A@b@c@example.com") === 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";
1.1.0

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.9.8

3 years ago

0.9.7

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.6

3 years ago

0.9.5

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.8.5

3 years ago

0.8.4

3 years ago

0.8.6

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.8.1

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.6.1

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.3.1

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.1.1

4 years ago