Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joutvhu/import-by
Import a module using a string reference
https://github.com/joutvhu/import-by
import module nodejs parent-dirname string-ref
Last synced: 16 days ago
JSON representation
Import a module using a string reference
- Host: GitHub
- URL: https://github.com/joutvhu/import-by
- Owner: joutvhu
- License: mit
- Created: 2021-03-13T19:37:10.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-03-20T04:33:55.000Z (almost 4 years ago)
- Last Synced: 2024-12-09T00:38:04.671Z (about 1 month ago)
- Topics: import, module, nodejs, parent-dirname, string-ref
- Language: TypeScript
- Homepage:
- Size: 30.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# import-by
Import a module using a string reference
## Installation
Install using `pnpm`:
```shell
pnpm add import-by
```Or `yarn`:
```shell
yarn add import-by
```Or `npm`:
```shell
npm i import-by
```## Usage
See the following example to understand how to use it:
- Create a file called is `detail.js`.
```js
// detail.js
module.exports.beverage = {
id: 12,
name: 'coffee'
};
```- And now, you can use `importBy` method to import the property from the `detail.js` file.
```js
const {importBy} = require('import-by');const beverage = importBy('./detail#beverage');
const beverageName = importBy('./detail#beverage.name', __dirname);
```