ts-cliche-unions
TypeScript icon, indicating that this package has built-in type declarations

1.3.2 • Public • Published

Open in Visual Studio Code ts-cliche-unions_MIT ts-cliche-unions_npm_v

ts-cliche-unions

A module for writing JavaScript cliché strings safely in TypeScript.
It provides string constants for key, event, HTML element, and HTML attributes.
This module does not use enums, so unnecessary code is reduced by treeshaking when compiled.

Install

npm install ts-cliche-unions --save

Usage

Import this module into your TypeScript file.

import { KEY } from 'ts-cliche-unions';

This module can be used to replace key name strings, etc., with constants.

// if(ev.key === 'Enter') { ... }
if(ev.key === KEY.Enter) { ... }
// document.addEventListener('copy', (e) => { ... }  
document.addEventListener(EVENT.Copy, (e) => { ... }  
// const link = document.createElement("a");  
const link = document.createElement(ELEMENT.A);
// element.setAttribute('class','test');
element.setAttribute(ATTRIBUTE.Class, 'test');

Remarks

Supported Browsers

This module does not support the following versions of browsers.

  • Windows
    Chrome (version 48 or lower)

  • Mac
    Chrome (version 52 or lower)
    FireFox (version 48 or lower)

  • Linux
    Chrome (version 52 or lower)

Specification Notes

The library provides not only constants but also union types for constants, but the types support only alphabetic characters.
Be careful when using the library's union type for variables that may contain any character.

If you just want to use constants, don't worry about the above.

Contributing

If you find a bug or data that has not been updated, please send a pull request with the fix or open an issue!

Inspiration

ts-cliche-unions was inspired by Nathan Friend's ts-key-enum.

License

MIT

Dependents (0)

Package Sidebar

Install

npm i ts-cliche-unions

Weekly Downloads

20

Version

1.3.2

License

MIT

Unpacked Size

61.1 kB

Total Files

5

Last publish

Collaborators

  • kawaken555