@@ -80,6 +80,43 @@ This is the only import attribute type currently supported in Deno. Support for
80
80
currently waiting on the
81
81
[ Module Harmony proposal] ( https://github.com/whatwg/html/issues/9444 ) .
82
82
83
+ ## Data URL imports
84
+
85
+ Deno supports importing of data URLs, which allows you to import content that
86
+ isn't in a separate file. This is useful for testing, prototyping, or when you
87
+ need to programmatically generate modules.
88
+
89
+ You can create modules on the fly using the ` data: ` URL scheme:
90
+
91
+ ``` ts
92
+ // Import a simple JavaScript module from a data URL
93
+ import * as module from " data:application/javascript;base64,ZXhwb3J0IGNvbnN0IG1lc3NhZ2UgPSAiSGVsbG8gZnJvbSBkYXRhIFVSTCI7" ;
94
+ console .log (module .message ); // Outputs: Hello from data URL
95
+
96
+ // You can also use the non-base64 format
97
+ const plainModule = await import (
98
+ " data:application/javascript,export function greet() { return 'Hi there!'; }"
99
+ );
100
+ console .log (plainModule .greet ()); // Outputs: Hi there!
101
+
102
+ // A simpler example with text content
103
+ const textModule = await import (
104
+ " data:text/plain,export default 'This is plain text'"
105
+ );
106
+ console .log (textModule .default ); // Outputs: This is plain text
107
+ ```
108
+
109
+ The data URL format follows this pattern:
110
+
111
+ ``` sh
112
+ data:[< media type> ][; base64],< data>
113
+ ```
114
+
115
+ For JavaScript modules, use ` application/javascript ` as the media type.
116
+ TypeScript is also supported with ` application/typescript ` . This feature is
117
+ particularly useful for testing modules in isolation and creeating mock modules
118
+ during tests.
119
+
83
120
## Importing third party modules and libraries
84
121
85
122
When working with third-party modules in Deno, use the same ` import ` syntax as
0 commit comments