UNPKG

11.2 kBTypeScriptView Raw
1/*
2require-2.1.8.d.ts may be freely distributed under the MIT license.
3
4Copyright (c) 2013 Josh Baldwin https://github.com/jbaldwin/require.d.ts
5
6Permission is hereby granted, free of charge, to any person
7obtaining a copy of this software and associated documentation
8files (the "Software"), to deal in the Software without
9restriction, including without limitation the rights to use,
10copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the
12Software is furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be
15included in all copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24OTHER DEALINGS IN THE SOFTWARE.
25*/
26
27declare module "module" {
28 var mod: {
29 config: () => any;
30 id: string;
31 uri: string;
32 };
33 export = mod;
34}
35
36interface RequireError extends Error {
37 /**
38 * The error ID that maps to an ID on a web page.
39 */
40 requireType: string;
41
42 /**
43 * Required modules.
44 */
45 requireModules: string[] | null;
46
47 /**
48 * The original error, if there is one (might be null).
49 */
50 originalError: Error;
51}
52
53interface RequireShim {
54 /**
55 * List of dependencies.
56 */
57 deps?: string[] | undefined;
58
59 /**
60 * Name the module will be exported as.
61 */
62 exports?: string | undefined;
63
64 /**
65 * Initialize function with all dependcies passed in,
66 * if the function returns a value then that value is used
67 * as the module export value instead of the object
68 * found via the 'exports' string.
69 * @param dependencies
70 * @return
71 */
72 init?: ((...dependencies: any[]) => any) | undefined;
73}
74
75interface RequireConfig {
76 /**
77 * The root path to use for all module lookups.
78 */
79 baseUrl?: string | undefined;
80
81 /**
82 * Path mappings for module names not found directly under
83 * baseUrl.
84 */
85 paths?: { [key: string]: any } | undefined;
86
87 /**
88 * Dictionary of Shim's.
89 * Can be of type RequireShim or string[] of dependencies
90 */
91 shim?: { [key: string]: RequireShim | string[] } | undefined;
92
93 /**
94 * For the given module prefix, instead of loading the
95 * module with the given ID, substitude a different
96 * module ID.
97 *
98 * @example
99 * requirejs.config({
100 * map: {
101 * 'some/newmodule': {
102 * 'foo': 'foo1.2'
103 * },
104 * 'some/oldmodule': {
105 * 'foo': 'foo1.0'
106 * }
107 * }
108 * });
109 */
110 map?: {
111 [id: string]: {
112 [id: string]: string;
113 };
114 } | undefined;
115
116 /**
117 * Allows pointing multiple module IDs to a module ID that contains a bundle of modules.
118 *
119 * @example
120 * requirejs.config({
121 * bundles: {
122 * 'primary': ['main', 'util', 'text', 'text!template.html'],
123 * 'secondary': ['text!secondary.html']
124 * }
125 * });
126 */
127 bundles?: { [key: string]: string[] } | undefined;
128
129 /**
130 * AMD configurations, use module.config() to access in
131 * define() functions
132 */
133 config?: { [id: string]: {} } | undefined;
134
135 /**
136 * Configures loading modules from CommonJS packages.
137 */
138 packages?: {} | undefined;
139
140 /**
141 * The number of seconds to wait before giving up on loading
142 * a script. The default is 7 seconds.
143 */
144 waitSeconds?: number | undefined;
145
146 /**
147 * A name to give to a loading context. This allows require.js
148 * to load multiple versions of modules in a page, as long as
149 * each top-level require call specifies a unique context string.
150 */
151 context?: string | undefined;
152
153 /**
154 * An array of dependencies to load.
155 */
156 deps?: string[] | undefined;
157
158 /**
159 * A function to pass to require that should be require after
160 * deps have been loaded.
161 * @param modules
162 */
163 callback?: ((...modules: any[]) => void) | undefined;
164
165 /**
166 * If set to true, an error will be thrown if a script loads
167 * that does not call define() or have shim exports string
168 * value that can be checked.
169 */
170 enforceDefine?: boolean | undefined;
171
172 /**
173 * If set to true, document.createElementNS() will be used
174 * to create script elements.
175 */
176 xhtml?: boolean | undefined;
177
178 /**
179 * Extra query string arguments appended to URLs that RequireJS
180 * uses to fetch resources. Most useful to cache bust when
181 * the browser or server is not configured correctly.
182 *
183 * As of RequireJS 2.2.0, urlArgs can be a function. If a
184 * function, it will receive the module ID and the URL as
185 * parameters, and it should return a string that will be added
186 * to the end of the URL. Return an empty string if no args.
187 * Be sure to take care of adding the '?' or '&' depending on
188 * the existing state of the URL.
189 *
190 * @example
191 *
192 * urlArgs: "bust=" + (new Date()).getTime()
193 *
194 * @example
195 *
196 * requirejs.config({
197 * urlArgs: function(id, url) {
198 * var args = 'v=1';
199 * if (url.indexOf('view.html') !== -1) {
200 * args = 'v=2'
201 * }
202 *
203 * return (url.indexOf('?') === -1 ? '?' : '&') + args;
204 * }
205 * });
206 */
207 urlArgs?: string | ((id: string, url: string) => string) | undefined;
208
209 /**
210 * Specify the value for the type="" attribute used for script
211 * tags inserted into the document by RequireJS. Default is
212 * "text/javascript". To use Firefox's JavasScript 1.8
213 * features, use "text/javascript;version=1.8".
214 */
215 scriptType?: string | undefined;
216
217 /**
218 * If set to true, skips the data-main attribute scanning done
219 * to start module loading. Useful if RequireJS is embedded in
220 * a utility library that may interact with other RequireJS
221 * library on the page, and the embedded version should not do
222 * data-main loading.
223 */
224 skipDataMain?: boolean | undefined;
225
226 /**
227 * Allow extending requirejs to support Subresource Integrity
228 * (SRI).
229 */
230 onNodeCreated?:
231 | ((node: HTMLScriptElement, config: RequireConfig, moduleName: string, url: string) => void)
232 | undefined;
233}
234
235// todo: not sure what to do with this guy
236interface RequireModule {
237 /** */
238 config(): {};
239}
240
241/** */
242interface RequireMap {
243 /** */
244 prefix: string;
245
246 /** */
247 name: string;
248
249 /** */
250 parentMap: RequireMap;
251
252 /** */
253 url: string;
254
255 /** */
256 originalName: string;
257
258 /** */
259 fullName: string;
260}
261
262interface Require {
263 /**
264 * Configure require.js
265 */
266 config(config: RequireConfig): Require;
267
268 /**
269 * CommonJS require call
270 * @param module Module to load
271 * @return The loaded module
272 */
273 (module: string): any;
274
275 /**
276 * Start the main app logic.
277 * Callback is optional.
278 * Can alternatively use deps and callback.
279 * @param modules Required modules to load.
280 */
281 (modules: string[]): void;
282
283 /**
284 * @see Require()
285 * @param ready Called when required modules are ready.
286 */
287 (modules: string[], ready: Function): void;
288
289 /**
290 * @see http://requirejs.org/docs/api.html#errbacks
291 * @param ready Called when required modules are ready.
292 */
293 (modules: string[], ready: Function, errback: Function): void;
294
295 /**
296 * Generate URLs from require module
297 * @param module Module to URL
298 * @return URL string
299 */
300 toUrl(module: string): string;
301
302 /**
303 * Returns true if the module has already been loaded and defined.
304 * @param module Module to check
305 */
306 defined(module: string): boolean;
307
308 /**
309 * Returns true if the module has already been requested or is in the process of loading and should be available at some point.
310 * @param module Module to check
311 */
312 specified(module: string): boolean;
313
314 /**
315 * On Error override
316 * @param err
317 */
318 onError(err: RequireError, errback?: (err: RequireError) => void): void;
319
320 /**
321 * Undefine a module
322 * @param module Module to undefine.
323 */
324 undef(module: string): void;
325
326 /**
327 * Semi-private function, overload in special instance of undef()
328 */
329 onResourceLoad(context: Object, map: RequireMap, depArray: RequireMap[]): void;
330}
331
332interface RequireDefine {
333 /**
334 * Define Simple Name/Value Pairs
335 * @param config Dictionary of Named/Value pairs for the config.
336 */
337 (config: { [key: string]: any }): void;
338
339 /**
340 * Define function.
341 * @param func: The function module.
342 */
343 (func: () => any): void;
344
345 /**
346 * Define function with dependencies.
347 * @param deps List of dependencies module IDs.
348 * @param ready Callback function when the dependencies are loaded.
349 * callback param deps module dependencies
350 * callback return module definition
351 */
352 (deps: string[], ready: Function): void;
353
354 /**
355 * Define module with simplified CommonJS wrapper.
356 * @param ready
357 * callback require requirejs instance
358 * callback exports exports object
359 * callback module module
360 * callback return module definition
361 */
362 (ready: (require: Require, exports: { [key: string]: any }, module: RequireModule) => any): void;
363
364 /**
365 * Define a module with a name and dependencies.
366 * @param name The name of the module.
367 * @param deps List of dependencies module IDs.
368 * @param ready Callback function when the dependencies are loaded.
369 * callback deps module dependencies
370 * callback return module definition
371 */
372 (name: string, deps: string[], ready: Function): void;
373
374 /**
375 * Define a module with a name.
376 * @param name The name of the module.
377 * @param ready Callback function when the dependencies are loaded.
378 * callback return module definition
379 */
380 (name: string, ready: Function): void;
381
382 /**
383 * Used to allow a clear indicator that a global define function (as needed for script src browser loading) conforms
384 * to the AMD API, any global define function SHOULD have a property called "amd" whose value is an object.
385 * This helps avoid conflict with any other existing JavaScript code that could have defined a define() function
386 * that does not conform to the AMD API.
387 * define.amd.jQuery is specific to jQuery and indicates that the loader is able to account for multiple version
388 * of jQuery being loaded simultaneously.
389 */
390 amd: Object;
391}
392
393// Ambient declarations for 'require' and 'define'
394declare var requirejs: Require;
395declare var require: Require;
396declare var define: RequireDefine;
397
\No newline at end of file