import-string
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

import-string logo

import-string

This package allow us to import code from simple string, with support to:

🚀 Getting started

This is a lightweight and simple package, you can install it using your favorite node package manager:

npm i import-string
pnpm add import-string
yarn add import-string
bun add import-string

📖 Usage

In your file you can declare the module, functionality or variable in a string like the following example:

const stringSrc = `export const example = (): string => {
  return {
    foo: 'baz'
  }
}`;

From the package you can import the importModule function that receive string and returns the module:

import { importModule } from 'import-string';

async function main() {
  const mod = await importModule(stringSrc);

  console.log(mod.example().foo); // output -> baz
}

🔧 Options

The importModule function accepts an options object as its second parameter:

import { importModule } from 'import-string';

const mod = await importModule(stringSrc, {
  target: 'es2018',
  loader: 'ts',
});

💻 Development

  1. Clone this repository
  2. Install dependencies using pnpm install

Send a PR with the feat|fix|refactor etc

🛟 Support

  • BTC: 1Bwo1Htd47rLRM4PZhydWtoC5ZAR4Fv9KZ
  • USDT: binance-qr

Author

David Arenas 🇻🇪

License

This project is licensed under MIT

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.13latest

Version History

VersionDownloads (Last 7 Days)Published
0.2.13
0.1.21,993
0.1.10
0.1.060
0.0.12

Package Sidebar

Install

npm i import-string

Weekly Downloads

2,058

Version

0.2.1

License

MIT

Unpacked Size

6.56 kB

Total Files

7

Last publish

Collaborators

  • dave136