Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dekkai/env

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dekkai/env

Utility methods to detect runtimes and load modules dynamically.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@dekkai/env
browser node deno opinion

@dekkai/env

Utility methods to detect runtimes and load modules dynamically.

Check out the full API Documentation

Installation

Browser/NodeJS

$ yarn add @dekkai/env

Deno

// import from directly from a CDN, like unpkg.com
import {isDeno, isBrowser, isNodeJS, loadModule} from 'https://unpkg.com/@dekkai/env';

Usage

// import the desired methods
import {isDeno, isBrowser, isNodeJS, loadModule} from '@dekkai/env';

// test for deno
const deno = isDeno();

// test for node
const node = isNodeJS();

// test for browser
const browser = isBrowser();

// import a module at runtime, this is generally the same as calling `await import(module)` but it is safe for all 
// platforms and should be able to survive bundlers, also wraps `require` for node environments where needed.
// The main advantage is to import modules needed for a specific platform at runtime, think importing `fs` for node
// at runtime but still being able to compile for all platforms.
let fs;
if (node) {
    fs = await loadModule('fs');
} else if (deno) {
    fs = await loadModule('https://deno.land/std/fs/mod.ts');
} else {
    fs = await loadModule('https://unpkg.com/browserfs');
}
// ...

Check out the full API Documentation

Keywords

FAQs

Package last updated on 12 Jul 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc