![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
The aim of this module is to completely partition the set of JS objects into a set of types T:
T = [Function, Object, Date, Number, String, Boolean, RegExp, Undefined, Arguments, Null, Array]
Prop. 1 For every JS object x, x has exactly one type in T where [typr] returns true for its typecheck.
Prop. 2 Whether or not an Object has keys and can be looped over is determined by t.hasKeys
and is completely independent of the type found in prop 1.
Prop. 3 Number types can be partitioned into 3 sub-types:
These properties are tested extensively.
Basic usage:
var typr = require('typr');
typr.isFunction(el); // true iff el is a function
Read the very short API.
The reason for prop 2 is that Objects can masquerade othes instances like Functions, Strings, RegExps, Dates. Object.keys() (and for-in) will actually work on some of these. This does not mean they will have interesting keys, but they sometimes do!
A common trick in node modules to export a function, but additionally attach properties to it. Such an object will only be a Function by our partitioning (as that was its original construction), but it is Object-like.
If you would rather test for enumerability of properties, use the extra test for Object-likeness: hasKeys
.
Note again that this may not be super intuitive:
var dualThing = new String("wee");
dualThing.prop = "hi";
Object.keys(dualThing); // [ '0', '1', '2', 'prop' ]
t.isObject(dualThing); // false
t.isString(dualThing); // true
t.hasKeys(dualThing); // true
$ npm install typr
Install development dependencies
$ npm install
Run the tests
$ npm test
MIT-Licensed. See LICENSE file for details.
FAQs
Mutually exclusive type testing
We found that typr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.