npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pi0/unenv

v1.9.0-rc.2

Published

`unenv` is a framework-agnostic system that allows converting JavaScript code to be platform agnostic and work in any environment including Browsers, Workers, Node.js, or JavaScript runtime.

Downloads

5

Readme

unenv

unenv is a framework-agnostic system that allows converting JavaScript code to be platform agnostic and work in any environment including Browsers, Workers, Node.js, or JavaScript runtime.

Install

# Using npm
npm i -D unenv

# Using yarn
yarn add --dev unenv

# Using pnpm
pnpm add -D unenv

Usage

Using env utility and built-in presets, unenv will provide an abstract configuration that can be used in building pipelines (rollup.js, webpack, etc.).

import { env } from "unenv";

const { alias, inject, polyfill, external } = env({}, {}, {});

Note: You can provide as many presets as you want. unenv will merge them internally and the right-most preset has a higher priority.

node preset

Suitable to convert universal libraries working in Node.js.

  • Add supports for global fetch API
  • Set Node.js built-ins as externals
import { env, nodeless } from "unenv";

const envConfig = env(node, {});

(view node preset source)

nodeless preset

Suitable to transform libraries made for Node.js to run in other JavaScript runtimes.

import { env, nodeless } from "unenv";

const envConfig = env(nodeless, {});

(view nodeless preset source)

deno preset

Note: This preset is experimental and behavior can change!

This preset can be used to extend nodeless to use Deno's Node.js API Compatibility (docs, docs).

import { env, nodeless, deno } from "unenv";

const envConfig = env(nodeless, deno, {});

(view deno preset source)

Built-in Node.js modules

unenv provides a replacement for all Node.js built-ins for cross-platform compatibility.

| Module | Status | Source | | --------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------ | | node:assert | Mocked | - | | node:async_hooks | Polyfilled | unenv/node/async_hooks | | node:buffer | Polyfilled | unenv/node/buffer | | node:child_process | Mocked | - | | node:cluster | Mocked | - | | node:console | Mocked | - | | node:constants | Mocked | - | | node:crypto | Polyfilled | unenv/node/crypto | | node:dgram | Mocked | - | | node:diagnostics_channel | Mocked | - | | node:dns | Mocked | - | | node:domain | Mocked | - | | node:events | Polyfilled | unenv/node/events | | node:fs | Polyfilled | unenv/node/fs | | node:fs/promises | Polyfilled | unenv/node/fs/promises | | node:http2 | Mocked | - | | node:http | Polyfilled | unenv/node/http | | node:https | Polyfilled | unenv/node/https | | node:inspector | Mocked | - | | node:module | Polyfilled | unenv/node/module - | | node:net | Polyfilled | unenv/node/net | | node:os | Mocked | - | | node:path | Polyfilled | unenv/node/path | | node:perf_hooks | Mocked | - | | node:process | Polyfilled | unenv/node/process | | node:punycode | Mocked | - | | node:querystring | Mocked | - | | node:readline | Mocked | - | | node:repl | Mocked | - | | node:stream | Polyfilled | unenv/node/stream | | node:stream/consumers | Mocked | unenv/node/stream/consumers | | node:stream/promises | Mocked | unenv/node/stream/promises | | node:stream/web | Native | unenv/node/stream/web | | node:string_decoder | Polyfilled | unenv/node/string_decoder | | node:sys | Mocked | - | | node:timers | Mocked | - | | node:timers/promises | Mocked | - | | node:tls | Mocked | - | | node:trace_events | Mocked | - | | node:tty | Mocked | - | | node:url | Polyfilled | unenv/node/url | | node:util | Polyfilled | unenv/node/util | | node:util/types | Polyfilled | unenv/node/util/types | | node:v8 | Mocked | - | | node:vm | Mocked | - | | node:wasi | Mocked | - | | node:worker_threads | Mocked | - | | node:zlib | Mocked | - |

npm packages

unenv provides a replacement for common npm packages for cross platform compatibility.

| Package | Status | Source | | ----------------------------------------------------------- | --------------------------- | ----------------------------------------------------------------- | | npm/consola | Use native console | unenv/runtime/npm/consola | | npm/cross-fetch | Use native fetch | unenv/runtime/npm/cross-fetch | | npm/debug | Mocked with console.debug | unenv/runtime/npm/debug | | npm/fsevents | Mocked | unenv/runtime/npm/fsevents | | npm/inherits | Inlined | unenv/runtime/npm/inherits | | npm/mime-db | Minimized | unenv/runtime/npm/mime-db | | npm/mime | Minimized | unenv/runtime/npm/mime | | npm/node-fetch | Use native fetch | unenv/runtime/npm/node-fetch | | npm/whatwg-url | Use native URL | unenv/runtime/npm/whatwg-url |

Auto-mocking proxy

import MockProxy from "unenv/runtime/mock/proxy";

console.log(MockProxy().foo.bar()[0]);

The above package doesn't work outside of Node.js and neither we need any platform-specific logic! When aliasing os to mock/proxy-cjs, it will be auto-mocked using a Proxy Object which can be recursively traversed like an Object, called like a Function, Iterated like an Array, or instantiated like a Class.

We use this proxy for auto-mocking unimplemented internals. Imagine a package does this:

const os = require("os");
if (os.platform() === "windows") {
  /* do some fix */
}
module.exports = () => "Hello world";

By aliasing os to unenv/runtime/mock/proxy-cjs, the code will be compatible with other platforms.

Other polyfills

To discover other polyfills, please check ./src/runtime.

License

MIT