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

Lib to ESM code snippet.


Version published
Weekly downloads
8.5K
decreased by-13.31%
Maintainers
1
Weekly downloads
 
Created
Source

lib-esm

Lib to ESM code snippet.

NPM version NPM Downloads

Install

npm i lib-esm

Usage

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

const result = libEsm({
  lib: 'lib-name',
  members: [
    'foo',
    'bar',
  ],
});

console.log(result.snippet);
Output

CommonJs format

import { createRequire } from "node:module";
const cjs_require = createRequire(import.meta.url);
const _M_ = cjs_require("lib-name");
export const foo = _M_.foo;
export const bar = _M_.bar;
export const keyword_default = _M_.default || _M_;
export {
  keyword_default as default,
};

IIFE format

const _M_ = window["lib-name"];
export const foo = _M_.foo;
export const bar = _M_.bar;
export const keyword_default = _M_.default || _M_;
export {
  keyword_default as default,
};

API (Define)

/** Lib to ESM code snippet. */
function libEsm(options: {
  /**
   * require id
   */
  require?: string;
  /**
   * export members
   */
  exports?: string[];
  /**
   * Prevent name conflicts
   */
  conflictId?: string;
  /**
   * Generate code snippet format
   * 
   * 🌰 e.g.
   * ```js
   * const _M_ = require("lib") // cjs
   * const _M_ = window["lib"] // iife
   * ```
   * 
   * @default "cjs"
   */
  format?: "cjs" | "iife";
}): {
  /** `require` snippets. */
  require: string;
  /** `export` snippets. */
  exports: string;
  /** Keywords alias */
  keywords: Record<string, string>;
}

Keywords

FAQs

Package last updated on 17 Oct 2022

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