@popcornjs/import
v2.4.1
Published
Fast & efficient import manager
Downloads
2
Readme
@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 :)