@popcornjs/import

Fast & efficient import manager

Usage no npm install needed!

<script type="module">
  import popcornjsImport from 'https://cdn.skypack.dev/@popcornjs/import';
</script>

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 :)