kaguranana-birthday-project/node_modules/import-from
ameyoyo 9a8113aca4 initial 2021-12-12 18:49:32 -08:00
..
node_modules/resolve-from initial 2021-12-12 18:49:32 -08:00
index.d.ts initial 2021-12-12 18:49:32 -08:00
index.js initial 2021-12-12 18:49:32 -08:00
license initial 2021-12-12 18:49:32 -08:00
package.json initial 2021-12-12 18:49:32 -08:00
readme.md initial 2021-12-12 18:49:32 -08:00

readme.md

import-from Build Status

Import a module like with require() but from a given path

Install

$ npm install import-from

Usage

const importFrom = require('import-from');

// There is a file at `./foo/bar.js`

importFrom('foo', './bar');

API

importFrom(fromDirectory, moduleId)

Like require(), throws when the module can't be found.

importFrom.silent(fromDirectory, moduleId)

Returns undefined instead of throwing when the module can't be found.

fromDirectory

Type: string

Directory to import from.

moduleId

Type: string

What you would use in require().

Tip

Create a partial using a bound function if you want to import from the same fromDir multiple times:

const importFromFoo = importFrom.bind(null, 'foo');

importFromFoo('./bar');
importFromFoo('./baz');
  • import-cwd - Import a module from the current working directory
  • resolve-from - Resolve the path of a module from a given path
  • resolve-cwd - Resolve the path of a module from the current working directory
  • resolve-pkg - Resolve the path of a package regardless of it having an entry point
  • import-lazy - Import modules lazily
  • import-global - Import a globally installed module

License

MIT © Sindre Sorhus