Skip to content

projektorius96/typed-getters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Project name: typed-getters (2025 edition)

MOTIVATION

Unlike default EcmaScript (hereinafter as JavaScript) constructors such as: String() defaults to '' | Number() defaults to 0 | Symbol() defaults to Symbol() | Boolean() defaults to false . Instead, using typed-getters we can maintain consistency among JavaScript primitives by simply returning a graceful undefined if any of type mismatch within arbitrarily-defined interface have been detected...

HOW TO USE

Installation

DISCLAIMER ALERT: UNLESS STATED OTHERWISE, current version found on npmjs registry, and scoped under @gloch96/typed-getters may be outdated: the current solution is to download it from github.com, and in turn import the src/index.mjs part of the code for further use !

To install util, run the following command:
npm i @gloch96/typed-getters

Before using, common sense, you have to import it. Depending on your use case, you can import it in one of the following ways:

A. You need to instantiate it

/**
 * @see For the full implementation details of `construct` (i.e. wrapper for `Reflect.constructor`), refer to `src/index.mjs`.
*/
import { construct } from '@gloch96/typed-getters/src/index.mjs'; // ./src/tests/instance.mjs

B. You need to factorise it

import '@gloch96/typed-getters/src/index.mjs'; // ./src/tests/factor.mjs

Test examples

Please refer to ./src/tests/<test_name>.mjs where <test_name> := {instance | factor};
Each test example is ESM-friendly script that can be evaluated in both run-times, i.e. browser of choice and Node.js runtime.


Made with ♥ projektorius96

About

duck typing for vanilla javascript primitives

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published