2.0.7 • Published 4 years ago

import-esm-directory v2.0.7

Weekly downloads
15
License
ISC
Repository
github
Last release
4 years ago

import-esm-directory

import es-module directory conveniently when export es-module in an environment that support es-module.

  note that the env need to meet two conditions:

  1. node

  2. support es-module (such as ts)

  • if useful, could you please give me a ⭐️star⭐ on github.

history versions

fast use

Notice: this takes typescript as an example.

  • directory eg:
root
|——main.ts
└——router
    |———index.ts
    |———list
    |    |——— listInter
    |    |      └———newList.ts
    |    |——— userList.ts
    |    └——— news.ts
    |———main
    |     └——— mainInter
    |            └——— domain.ts
    └———user
         └——— priority.ts

use default function

  • router/index.ts
import importEsmDirectory from 'import-esm-directory';
export default importEsmDirectory(module);
  • import the directory in main.ts
import routerDirectoryPromise from './router';
routerDirectoryPromise.then((esmDirectory) => {
    console.log(esmDirectory);
})
/* output
{
	list: {
		listInter: {
			newlist: [Object]
		},
		news: {},
		userList: {
			index: [Object]
		}
	},
	main: {
		mainInter: {
			domain: [Object]
		}
	},
	user: {
		priority: [Function]
	}
}
*/

use parse function

  • router/index.ts
import {importParseDirectory} from 'import-esm-directory';
export default importParseDirectory(module);
  • import the directory in main.ts
import routerDirectoryPromise from './router';
routerDirectoryPromise.then((esmDirectory) => {
    console.log(esmDirectory)
})
/*  output
{
	deepModule: {
		list: {
			listInter: [Object],
			news: {},
			userList: [Object]
		},
		main: {
			mainInter: [Object]
		},
		user: {
			priority: [Function]
		}
	},
	layerModule: {
		'list/listInter/newlist': {
			name: 'newslist'
		},
		'list/news': {},
		'list/userList': {
			index: [Object]
		},
		'main/mainInter/domain': {
			name: 'domain'
		},
		'user/priority': [Function]
	}
}
*/

description

  • for specific example: koa-ts-node
  • the separator of path may be different on windows.
  • because that this use dynamic import of es6, so the package returns a promise object
2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago