Socket
Socket
Sign inDemoInstall

lib-esm

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lib-esm

A tiny `esm` snippets interop lib


Version published
Weekly downloads
10K
increased by20.47%
Maintainers
1
Weekly downloads
 
Created

Readme

Source

lib-esm

A tiny esm snippets interop lib.

NPM version NPM Downloads

Install

npm i lib-esm

Usage

import libEsm from 'lib-esm'
// or
// const libEsm = require('lib-esm').default

const snippets = libEsm({
  window: 'lib-name',
  require: 'lib-name',
  exports: [
    'foo',
    'bar',
  ],
})

console.log(`${snippets.window}\n${snippets.exports}`)
console.log(`${snippets.require}\n${snippets.exports}`)

snippets.window

const _M_ = window["lib-name"];

snippets.require

import _M_node_module from "node:module";
const _M_ = _M_node_module.createRequire(import.meta.url)("lib-name");

snippets.exports

export const foo = _M_.foo;
export const bar = _M_.bar;
const keyword_default = _M_.default || _M_;
export {
  keyword_default as default,
};

API (Define)

/** Lib to ESM code snippets */
function libEsm(options: {
  /**
   * IIFE name
   */
  window?: string;
  /**
   * require id
   */
  require?: string;
  /**
   * export members
   */
  exports?: string[];
  /**
   * Prevent name conflicts
   */
  conflict?: string;
}): {
  /** `window[iife-name]` snippets */
  window: string;
  /** `require(id)` snippets */
  require: string;
  /** `export` snippets */
  exports: string;
  /** Keywords alias */
  keywords: Record<string, string>;
}

Keywords

FAQs

Package last updated on 06 Jan 2024

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc