@popcornjs/import
TypeScript icon, indicating that this package has built-in type declarations

2.4.1 • Public • Published

@popcornjs/import

A fast & efficient import manager for Node

Maybe you have a library written in TypeScript with default exports.

If so, this is the library for you.

Example in TS & JS

// Type.ts
export default (name: string) => name[0].toUpperCase() + name.slice(1); 

... Compile into dist/Type.js

// index.js
const { Import } = require('@popcornjs/import');
// or
import { Import } from "@popcornjs/import";
const myLib = Import('./dist/Type.js'); // could be a package name as well!
// everything below is optional except for exec
// this feature is only useful for apis returning numbers / bigints & wanting to convert to strings.
myLib.expectType('string');
// should it defaulty import the default function? call the function if so
myLib.importDefault();
// when calling the exec method, should it run a function?
// myLib.runFunction(FUNCTION_NAME, ...FUNCTION_PARAMS);
// example:
myLib.runFunction('default', 'hi');
// run it
const lib = myLib.exec();
lib // 'Hi' as this is what our function does. 
//

Simple example

const { Import } = require('@popcornjs/import');
// or
import { Import } from "@popcornjs/import";
const myLib = Import('./dist/Type.js'); // could be a package name as well!
myLib.importDefault();
const lib = myLib.exec();
lib // returns the default function

Thanks :)

Readme

Keywords

Package Sidebar

Install

npm i @popcornjs/import

Weekly Downloads

0

Version

2.4.1

License

ISC

Unpacked Size

7.79 kB

Total Files

9

Last publish

Collaborators

  • tnt_man1671
  • salvage_dev