UNPKG

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