simport
import like require but async
Last updated 5 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install simport 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.2.0                                ...           latest (5 years ago)

13 Versions

  • 1.2.0                                ...           5 years ago
  • 1.1.3                                ...           5 years ago
  • 1.1.2                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.7                                ...           5 years ago
  • 1.0.6                                ...           5 years ago
  • 1.0.5                                ...           5 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (10)

Copyright 2013 - present © cnpmjs.org | Home |