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

simport

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simport

import like require but async

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23K
increased by1.86%
Maintainers
1
Weekly downloads
 
Created
Source

Simport License NPM version Dependency Status Build Status Coverage Status

Use dynamic imports just like plain old require.

With simport you can:

  • get require
  • get __filename or __dirname
  • load json
  • avoid extensions
  • avoid destructuring default
  • pass simport into functions like tryCatch
  • use absolute path in windows

Install

npm i simport

API

createSimport

Commonjs:

const {createSimport} = require('simport');
const simport = createSimport(__filename);

ESM:

import {createSimport} from 'simport';
const simport = createSimport(import.meta.url);

// you can import json
await simport('./package.json');
// returns
({
    name: simport,
});

// you can avoid .js extension
await simport('./server');

// you can avoid destructure default
const validate = await simport('./validate');
// same as
const {default: validate2} = await import('./validate.js');

createCommons

import {createCommons} from 'simport';

const {
    __filename,
    __dirname,
    require,
} = createCommons(import.meta.url);

// now you have plain old CommonJS variables

License

MIT

Keywords

FAQs

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