@@ -19,67 +19,36 @@ const checkURL = url => {
1919 }
2020} ;
2121
22- const importDependency = { } ;
22+ const dependency = { } ;
2323
2424/**
2525 * @param {string } url
2626 * @template T
2727 * @returns {Promise<T> }
2828 */
29- importDependency . asModule = url => {
29+ dependency . import = url => {
3030 checkURL ( url ) ;
3131 // Need to specify webpackIgnore so that webpack compiles this directly to a call to import()
32- // instead of trying making it try to use the webpack dependency system.
32+ // instead of trying making it try to use the webpack import system.
3333 return import ( /* webpackIgnore: true */ url ) ;
3434} ;
3535
3636/**
3737 * @param {string } url
38- * @returns {Promise<Response>|Response }
38+ * @returns {Promise<Response> }
3939 */
40- importDependency . asFetch = url => {
40+ dependency . fetch = url => {
4141 checkURL ( url ) ;
4242 return fetch ( url ) ;
4343} ;
4444
45- /**
46- * @param {string } url
47- * @returns {Promise<string>|string }
48- */
49- importDependency . asDataURL = async url => {
50- checkURL ( url ) ;
51- const res = await fetch ( url ) ;
52- const blob = await res . blob ( ) ;
53- return new Promise ( ( resolve , reject ) => {
54- const fr = new FileReader ( ) ;
55- fr . onload = ( ) => resolve ( fr . result ) ;
56- fr . onerror = ( ) => reject ( fr . error ) ;
57- fr . readAsDataURL ( blob ) ;
58- } ) ;
59- } ;
60-
61- /**
62- * @param {string } url
63- * @returns {Promise<void> }
64- */
65- importDependency . asScriptTag = url => {
66- checkURL ( url ) ;
67- return new Promise ( ( resolve , reject ) => {
68- const script = document . createElement ( 'script' ) ;
69- script . onload = ( ) => resolve ( ) ;
70- script . onerror = ( ) => reject ( new Error ( 'Script error' ) ) ;
71- script . src = url ;
72- return script ;
73- } ) ;
74- } ;
75-
7645/**
7746 * @param {string } url
7847 * @param {string } returnExpression
7948 * @template T
80- * @returns {Promise<T>|T }
49+ * @returns {Promise<T> }
8150 */
82- importDependency . asEval = async ( url , returnExpression ) => {
51+ dependency . evalAndReturn = async ( url , returnExpression ) => {
8352 checkURL ( url ) ;
8453
8554 const res = await fetch ( url ) ;
@@ -93,4 +62,4 @@ importDependency.asEval = async (url, returnExpression) => {
9362 return fn ( ) ;
9463} ;
9564
96- module . exports = importDependency ;
65+ module . exports = dependency ;
0 commit comments