load-module
Advanced tools
Comparing version 4.0.0-2 to 4.0.0
{ | ||
"name": "load-module", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "4.0.0-2", | ||
"description": "Node's `require` with a few extra features", | ||
"version": "4.0.0", | ||
"description": "Standard dynamic imports with a few extra features", | ||
"repository": "https://github.com/75lb/load-module.git", | ||
@@ -12,3 +12,5 @@ "license": "MIT", | ||
"module", | ||
"package" | ||
"package", | ||
"import", | ||
"esm" | ||
], | ||
@@ -24,10 +26,8 @@ "main": "index.mjs", | ||
"test": "test-runner test/*.mjs", | ||
"docs": "jsdoc2md -c jsdoc.conf -t README.hbs index.mjs > README.md; echo", | ||
"cover": "nyc --reporter=text-lcov npm test | coveralls" | ||
"cover": "c8 --reporter=text-lcov npm test | coveralls" | ||
}, | ||
"devDependencies": { | ||
"c8": "^7.7.1", | ||
"coveralls": "^3.1.0", | ||
"current-module-paths": "^0.1.0", | ||
"jsdoc-to-markdown": "^7.0.1", | ||
"nyc": "^15.1.0", | ||
"test-runner": "^0.9.1" | ||
@@ -34,0 +34,0 @@ }, |
@@ -11,53 +11,66 @@ [![view on npm](https://badgen.net/npm/v/load-module)](https://www.npmjs.org/package/load-module) | ||
Standard [dynamic imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports) but with a few additional features: | ||
Standard [dynamic imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports) intended for runtime loading of user-defined modules (e.g. plugins). | ||
- You can supply specific folders in which to search for modules (e.g. any local directory). | ||
- You can specify a base folder from which to resolve from (e.g. the current working directory). | ||
- Search for modules in one or more specific folders. | ||
- Specify a base folder from which to resolve from (e.g. the current working directory). | ||
## Synopsis | ||
```js | ||
import { loadModule } from 'load-module' | ||
const ViewClass = await loadModule('default-view', { paths: '~/my-view-folder'}) | ||
const view = new ViewClass() | ||
``` | ||
> const loadModule = require('load-module') | ||
> loadModule('react-dom') | ||
> loadModule('something.mjs', { paths: process.cwd() }) | ||
> loadModule('something.mjs', { paths: [process.cwd(), '~/my-modules'] }) | ||
``` | ||
<a name="module_load-module"></a> | ||
## load-module | ||
* [load-module](#module_load-module) | ||
* [.loadModuleSpecifier(specifier)](#module_load-module.loadModuleSpecifier) | ||
* [.loadModuleResolvedFrom(specifier, paths)](#module_load-module.loadModuleResolvedFrom) | ||
* [.loadModulePathRelativeTo(specifier, paths)](#module_load-module.loadModulePathRelativeTo) | ||
* [loadModule(specifier, options)](#module_load-module.loadModule) | ||
* [loadModuleSpecifier(specifier)](#module_load-module.loadModuleSpecifier) | ||
* [loadModuleResolvedFrom(specifier, paths)](#module_load-module.loadModuleResolvedFrom) | ||
* [loadModuleRelativeTo(specifier, paths)](#module_load-module.loadModuleRelativeTo) | ||
### <a name="module_load-module.loadModule">loadModule(specifier, options)</a> | ||
**Kind**: exported function | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| specifier | `string` | A valid Node.js module specifier. | | ||
| options.paths | `string[]` | One or more directories to pass to both `loadModuleResolvedFrom` and `loadModuleRelativeTo`. | | ||
| options.resolvedFromPaths | `string[]` | Specific directories to pass to `loadModuleResolvedFrom`. | | ||
| options.relativeToPaths | `string[]` | Specific directories to pass to `loadModuleRelativeTo`. | | ||
<a name="module_load-module.loadModuleSpecifier"></a> | ||
### loadModule.loadModuleSpecifier(specifier) | ||
**Kind**: static method of [<code>load-module</code>](#module_load-module) | ||
### loadModuleSpecifier(specifier) | ||
**Kind**: exported function | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| specifier | <code>string</code> | A valid Node.js module specifier. | | ||
| specifier | `string` | A valid Node.js module specifier. | | ||
<a name="module_load-module.loadModuleResolvedFrom"></a> | ||
### loadModule.loadModuleResolvedFrom(specifier, paths) | ||
**Kind**: static method of [<code>load-module</code>](#module_load-module) | ||
### loadModuleResolvedFrom(specifier, paths) | ||
**Kind**: exported function | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| specifier | <code>string</code> | A valid Node.js module specifier. | | ||
| paths | <code>string</code> \| <code>Array.<string></code> | One or more additional directories from which to resolve the supplied specifier from. | | ||
| specifier | `string` | A valid Node.js module specifier. | | ||
| paths | `string` \| `Array.<string>` | One or more additional directories from which to resolve the supplied specifier from. | | ||
<a name="module_load-module.loadModulePathRelativeTo"></a> | ||
<a name="module_load-module.loadModuleRelativeTo"></a> | ||
### loadModule.loadModulePathRelativeTo(specifier, paths) | ||
**Kind**: static method of [<code>load-module</code>](#module_load-module) | ||
### loadModuleRelativeTo(specifier, paths) | ||
**Kind**: exported function | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| specifier | <code>string</code> | A valid module path. | | ||
| paths | <code>string</code> \| <code>Array.<string></code> | One or more additional directories in which to search for the supplied module path. | | ||
| specifier | `string` | A valid module path. | | ||
| paths | `string` \| `Array.<string>` | One or more additional directories in which to search for the supplied module path. | | ||
@@ -64,0 +77,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4
1
82
7911
4