hikari-es-extensions

Helper functions and classes aimed to reduce the routine code. Build-in TypeScript type safety.

Usage no npm install needed!

<script type="module">
  import hikariEsExtensions from 'https://cdn.skypack.dev/hikari-es-extensions';
</script>

README

hikari-es-extensions

  • Logging

    • BasicFrontEndLogger Provides the formatting for browser console that is commonly enough for early phase of web application development. Could be extended for adding of output destinations, limitations or formatting customization.
    • ConsoleApplicationLogger Provides the formatting for NodeJS terminal. Could be extended for upgrading to backend application logger with, for example, additional logging to data base.

Classes

Stopwatch
Quick example
const stopwatch: Stopwatch = new Stopwatch();
stopwatch.start();

Or shortly:

const stopwatch: Stopwatch = new Stopwatch().start();

It's possible to stop the stopwatch and get the elapsed time data in one line, too:

const ellaplesTime__seconds = stopwatch.stop().getElapsedTimeData().seconds;
UML-like schema
Stopwatch {
  +start(): Stopwatch
  +stop(): Stopwatch
  +getElapsedTimeData(): Stopwatch.ElapsedTimeData;
  +reset(): void
}

Here ElapsedTimeData is:

type ElapsedTimeData = {
  readonly seconds: number;
  readonly milliseconds: number;
};

Random values generators

Get random string

getRandomString(
  parametersObject: {
    fixedSymbolsCount?: number;
    minimalSymbolsCount?: number;
    maximalSymbolsCount?: number;
    prefix?: string;
  } = {}
): string
  • If fixedSymbolsCount specified, minimalSymbolsCount and maximalSymbolsCount will be ignored.
  • If maximalSymbolsCount and minimalSymbolsCount specified, maximalSymbolsCount must be greater than minimalSymbolsCount.
  • If prefix specified, it must be smaller than maximalSymbolsCount and fixedSymbolsCount.

Browser JavaScript functionality

Create element

createElement(HTML_Code: string): Element

Creates single Element. If HTML code which first parameter contains has more than one root Element, ImproperUsageError will be thrown. If are want to support the scenario for multiple root elements, user createElements function instead.

Create elements

createElements(HTML_Code: string): HTMLCollection

Allows to create the HTMLCollection from HTML code by one line of code instead of below routine:

const container: Document = document.implementation.createHTMLDocument();

container.body.innerHTML = HTML_Code;

return container.body.children;

Implementation for the front-end application

Implementation for the back-end application

Implementation for the console application

NodeJS functionality

Improved path

Theory
Path separators

Parse path

Retrieving of file name without extension ImprovedPath.filenameWithoutExtension

For /home/user/dir/file, Path.parse() will return Path.ParsedPath object with empty string value of name property. In ImprovedPath.ParsedPath, filenameWithoutExtension will be undefined.

If you are expecting that filenameWithoutExtension must be defined, use getFilenameWithoutExtensionWhichExpectedToBeDefined getter instead, but if actually filenameWithoutExtension will be undefined, UnexpectedEventError will be thrown.

  • When filename has single extension only (e. g. .gitignore), Path.parse() will consider it as base and ext will be empty.
  • When filename has multiple extensions, all of them except last one will be included to filenameWithoutExtension.

Roadmap

Future ecosystem

@yamato-daiwa/es-extensions is being used and will be used by everythig that written in TypeScript by Tokugawa Takesi and Yamato Daiwa, his future startup.

Libraries

  • @yamato-daiwa/automation
  • @yamato-daiwa/frontend
  • @yamato-daiwa/backend
  • @yamato-daiwa/data