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

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.

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.4K
decreased by-18.51%
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)

export default function libEsm(options: {
  /**
   * lib name
   */
  lib: string;
  /**
   * export members
   */
  members?: string[];
  /**
   * Prevent naming 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";
}): {
  snippet: string;
  /** Only `export` snippets. */
  exports: string;
  /** Keywords alias */
  keywords: Record<string, string>;
}

Keywords

FAQs

Package last updated on 14 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