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 * @example
193 * urlArgs: "bust= + (new Date()).getTime()
194 *
195 * As of RequireJS 2.2.0, urlArgs can be a function. If a
196 * function, it will receive the module ID and the URL as
197 * parameters, and it should return a string that will be added
198 * to the end of the URL. Return an empty string if no args.
199 * Be sure to take care of adding the '?' or '&' depending on
200 * the existing state of the URL.
201 *
202 * @example
203
204 * requirejs.config({
205 * urlArgs: function(id, url) {
206 * var args = 'v=1';
207 * if (url.indexOf('view.html') !== -1) {
208 * args = 'v=2'
209 * }
210 *
211 * return (url.indexOf('?') === -1 ? '?' : '&') + args;
212 * }
213 * });
214 **/
215 urlArgs?: string | ((id: string, url: string) => string) | undefined;
216
217 /**
218 * Specify the value for the type="" attribute used for script
219 * tags inserted into the document by RequireJS. Default is
220 * "text/javascript". To use Firefox's JavasScript 1.8
221 * features, use "text/javascript;version=1.8".
222 **/
223 scriptType?: string | undefined;
224
225 /**
226 * If set to true, skips the data-main attribute scanning done
227 * to start module loading. Useful if RequireJS is embedded in
228 * a utility library that may interact with other RequireJS
229 * library on the page, and the embedded version should not do
230 * data-main loading.
231 **/
232 skipDataMain?: boolean | undefined;
233
234 /**
235 * Allow extending requirejs to support Subresource Integrity
236 * (SRI).
237 **/
238 onNodeCreated?: ((node: HTMLScriptElement, config: RequireConfig, moduleName: string, url: string) => void) | undefined;
239}
240
241// todo: not sure what to do with this guy
242interface RequireModule {
243
244 /**
245 *
246 **/
247 config(): {};
248
249}
250
251/**
252*
253**/
254interface RequireMap {
255
256 /**
257 *
258 **/
259 prefix: string;
260
261 /**
262 *
263 **/
264 name: string;
265
266 /**
267 *
268 **/
269 parentMap: RequireMap;
270
271 /**
272 *
273 **/
274 url: string;
275
276 /**
277 *
278 **/
279 originalName: string;
280
281 /**
282 *
283 **/
284 fullName: string;
285}
286
287interface Require {
288
289 /**
290 * Configure require.js
291 **/
292 config(config: RequireConfig): Require;
293
294 /**
295 * CommonJS require call
296 * @param module Module to load
297 * @return The loaded module
298 */
299 (module: string): any;
300
301 /**
302 * Start the main app logic.
303 * Callback is optional.
304 * Can alternatively use deps and callback.
305 * @param modules Required modules to load.
306 **/
307 (modules: string[]): void;
308
309 /**
310 * @see Require()
311 * @param ready Called when required modules are ready.
312 **/
313 (modules: string[], ready: Function): void;
314
315 /**
316 * @see http://requirejs.org/docs/api.html#errbacks
317 * @param ready Called when required modules are ready.
318 **/
319 (modules: string[], ready: Function, errback: Function): void;
320
321 /**
322 * Generate URLs from require module
323 * @param module Module to URL
324 * @return URL string
325 **/
326 toUrl(module: string): string;
327
328 /**
329 * Returns true if the module has already been loaded and defined.
330 * @param module Module to check
331 **/
332 defined(module: string): boolean;
333
334 /**
335 * Returns true if the module has already been requested or is in the process of loading and should be available at some point.
336 * @param module Module to check
337 **/
338 specified(module: string): boolean;
339
340 /**
341 * On Error override
342 * @param err
343 **/
344 onError(err: RequireError, errback?: (err: RequireError) => void): void;
345
346 /**
347 * Undefine a module
348 * @param module Module to undefine.
349 **/
350 undef(module: string): void;
351
352 /**
353 * Semi-private function, overload in special instance of undef()
354 **/
355 onResourceLoad(context: Object, map: RequireMap, depArray: RequireMap[]): void;
356}
357
358interface RequireDefine {
359
360 /**
361 * Define Simple Name/Value Pairs
362 * @param config Dictionary of Named/Value pairs for the config.
363 **/
364 (config: { [key: string]: any; }): void;
365
366 /**
367 * Define function.
368 * @param func: The function module.
369 **/
370 (func: () => any): void;
371
372 /**
373 * Define function with dependencies.
374 * @param deps List of dependencies module IDs.
375 * @param ready Callback function when the dependencies are loaded.
376 * callback param deps module dependencies
377 * callback return module definition
378 **/
379 (deps: string[], ready: Function): void;
380
381 /**
382 * Define module with simplified CommonJS wrapper.
383 * @param ready
384 * callback require requirejs instance
385 * callback exports exports object
386 * callback module module
387 * callback return module definition
388 **/
389 (ready: (require: Require, exports: { [key: string]: any; }, module: RequireModule) => any): void;
390
391 /**
392 * Define a module with a name and dependencies.
393 * @param name The name of the module.
394 * @param deps List of dependencies module IDs.
395 * @param ready Callback function when the dependencies are loaded.
396 * callback deps module dependencies
397 * callback return module definition
398 **/
399 (name: string, deps: string[], ready: Function): void;
400
401 /**
402 * Define a module with a name.
403 * @param name The name of the module.
404 * @param ready Callback function when the dependencies are loaded.
405 * callback return module definition
406 **/
407 (name: string, ready: Function): void;
408
409 /**
410 * Used to allow a clear indicator that a global define function (as needed for script src browser loading) conforms
411 * to the AMD API, any global define function SHOULD have a property called "amd" whose value is an object.
412 * This helps avoid conflict with any other existing JavaScript code that could have defined a define() function
413 * that does not conform to the AMD API.
414 * define.amd.jQuery is specific to jQuery and indicates that the loader is able to account for multiple version
415 * of jQuery being loaded simultaneously.
416 */
417 amd: Object;
418}
419
420// Ambient declarations for 'require' and 'define'
421declare var requirejs: Require;
422declare var require: Require;
423declare var define: RequireDefine;
424
\No newline at end of file