Skip to content

Commit

Permalink
feat(util): defaultExport
Browse files Browse the repository at this point in the history
  • Loading branch information
AliMD committed Jun 26, 2023
1 parent 1ffa9e8 commit 82cc24e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/util/src/default-export.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Get default export from dynamic es-module import without resolve promise.
*
* Example:
*
* ```ts
* const starIcon = defaultExport(import('@alwatr/icon/svg/star-outline.svg'));
*
* render(`<div class="icon">${await starIcon}</div>`)
* ```
*/
export const defaultExport = <K extends string, T extends {default: K}>(m: Promise<T>): Promise<K> =>
m.then((_m) => _m.default);
1 change: 1 addition & 0 deletions core/util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './polyfill.js';
export * from './flat-str.js';
export * from './string.js';
export * from './render-state.js';
export * from './default-export.js';

0 comments on commit 82cc24e

Please sign in to comment.