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...
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 fromgithub.com
, and in turn import thesrc/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
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