Gathering detailed insights and metrics for @nodefill/primordials
Gathering detailed insights and metrics for @nodefill/primordials
Gathering detailed insights and metrics for @nodefill/primordials
Gathering detailed insights and metrics for @nodefill/primordials
npm install @nodefill/primordials
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
8
primordials
object🧊 The native primordials object from Node.js for anywhere
🤩 Great for authors who want safe intrinsics
📦 Works in Node.js, Deno, Bun and the browser
🍰 Comes with individual files to allow deep imports
🧱 Based on the internal primordials.js
from Node.js core
Install this package using npm, Yarn, or pnpm!
1npm install @nodefill/primordials
This package is also compatible with Deno via their compatibility layer. You can
import the package directly using the new npm:
specifier, or a
Deno-compatible ESM CDN like esm.sh or jsDelivr.
1import {} from "npm:@nodefill/primordials"; 2import {} from "https://esm.sh/@nodefill/primordials";
If you're using not using a build tool and you just want to use the package in your browser, you can use an npm CDN like esm.sh or jsDelivr.
1import {} from "https://esm.sh/@nodefill/primordials"; 2import {} from "https://esm.run/@nodefill/primordials";
This package provides the primordials
object from Node.js. Each primordial is
also exposed as a separate *.js
file if you feel like manually tree-shaking.
1import { ArrayIsArray } from "@nodefill/primordials"; 2import ArrayPrototypeReduce from "@nodefill/primordials/ArrayPrototypeReduce.js"; 3 4const sum = (array) => { 5 if (!Array.isArray(array)) { 6 throw new TypeError(`${array} is not an array`); 7 } 8 return array.reduce((n, x) => n + x, 0); 9}; 10const safeSum = (array) => { 11 if (!ArrayIsArray(array)) { 12 throw new TypeError(`${array} is not an array`); 13 } 14 return ArrayPrototypeReduce(array, (n, x) => n + x, 0); 15}; 16 17Array.prototype.reduce = () => 100; 18 19console.log(sum([1, 2, 3])); 20//=> 100 21console.log(safeSum([1, 2, 3])); 22//=> 6
We also offer a polyfill.js
export for to emulate the Node.js primordials
global object.
1import "@nodefill/primordials/polyfill.js"; 2 3console.log(primordials.ArrayIsArray([])); 4//=> true
💾 If you want to be frugal with bundle size, you can explicitly deep-import
only specific primordials that you use. This means we won't import the massive
700 item index.js
file which can be huge size savings if you're willing to
type a few extra words.
1import StringPrototypeSlice from "@nodefill/primordials/StringPrototypeSlice.js"; 2import ArrayBufferIsView from "@nodefill/primordials/ArrayBufferIsView.js";
⚠️ If you import ArrayPrototypeFindLast
on Node.js 16, there is no
.findLast()
function. So what happens? The export will just be undefined
.
It's on you to ArrayPrototypeFindLast?.(array, ...)
if you want to
conditionally use it. Just note that it will always be exported but
sometimes could be undefined
.
1import ArrayPrototypeFindLast from "@nodefill/primordials/ArrayPrototypeFindLast.js"; 2 3console.log(process.version); 4//=> v16.0.0 OR v20.0.0 5 6console.log(ArrayPrototypeFindLast); 7//=> undefined OR function findLast() { [native code] }
ℹ Files like RegExpGet$&.js
are named RegExpGet$amp.js
(replaced with HTML
entity names) to avoid issues with restrictive file systems like Windows. 😉
processCwd()
and friends. See also import { cwd } from "node:process"
.polyfill.js
export to shim the global primordials
object.SafePromise*
exports.Safe*
exports yet. See isaacs/node-primordials#9.primordials
object, but similar goal.getIntrinsic("%Math.pow%")
instead of import MathPow from "..."
.eval()
-like magic instead of an explicit list.polyfill.js
export to shim the global primordials
object..mjs
and .js
files, not TypeScript.polyfill.js
export to shim the global primordials
object.SafePromise*
exports.Safe*
exports.💡 You can always just not use bound primordials like ArrayPrototypePush()
and just use plain prototype lookup .push()
if you want to save bundle size
and general tooling complexity. 🤷♀️ The tradeoff is that you are susceptible to
users monkey-patching said global primordials. 😜
This project embraces TypeScript! At the scale of 700+ files, you really just can't with normal JavaScript. 😆 To get started, just run:
1npm run build 2npm test
To regenerate the latest primordials.json
list, just make sure you're on the
latest Node.js version and run:
1node --expose-internals \ 2 -r internal/test/binding \ 3 -p "JSON.stringify(Object.getOwnPropertyNames(primordials).sort())" \ 4 > test/primordials.json
No vulnerabilities found.
No security vulnerabilities found.