blob: 0d69d104fb7c4443893c335933a160c52922cbb5 [file] [log] [blame]
Matteo Scandolo5461a7c2017-08-08 13:05:24 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandolofc4b37b2017-02-02 12:18:47 -080019// Generated by typings
20// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/56295f5058cac7ae458540423c50ac2dcf9fc711/requirejs/require.d.ts
21declare module 'module' {
22 var mod: {
23 config: () => any;
24 id: string;
25 uri: string;
26 }
27 export = mod;
28}
29
30interface RequireError extends Error {
31
32 /**
33 * The error ID that maps to an ID on a web page.
34 **/
35 requireType: string;
36
37 /**
38 * Required modules.
39 **/
40 requireModules: string[];
41
42 /**
43 * The original error, if there is one (might be null).
44 **/
45 originalError: Error;
46}
47
48interface RequireShim {
49
50 /**
51 * List of dependencies.
52 **/
53 deps?: string[];
54
55 /**
56 * Name the module will be exported as.
57 **/
58 exports?: string;
59
60 /**
61 * Initialize function with all dependcies passed in,
62 * if the function returns a value then that value is used
63 * as the module export value instead of the object
64 * found via the 'exports' string.
65 * @param dependencies
66 * @return
67 **/
68 init?: (...dependencies: any[]) => any;
69}
70
71interface RequireConfig {
72
73 // The root path to use for all module lookups.
74 baseUrl?: string;
75
76 // Path mappings for module names not found directly under
77 // baseUrl.
78 paths?: { [key: string]: any; };
79
80
81 // Dictionary of Shim's.
82 // does not cover case of key->string[]
83 shim?: { [key: string]: RequireShim; };
84
85 /**
86 * For the given module prefix, instead of loading the
87 * module with the given ID, substitude a different
88 * module ID.
89 *
90 * @example
91 * requirejs.config({
92 * map: {
93 * 'some/newmodule': {
94 * 'foo': 'foo1.2'
95 * },
96 * 'some/oldmodule': {
97 * 'foo': 'foo1.0'
98 * }
99 * }
100 * });
101 **/
102 map?: {
103 [id: string]: {
104 [id: string]: string;
105 };
106 };
107
108 /**
109 * Allows pointing multiple module IDs to a module ID that contains a bundle of modules.
110 *
111 * @example
112 * requirejs.config({
113 * bundles: {
114 * 'primary': ['main', 'util', 'text', 'text!template.html'],
115 * 'secondary': ['text!secondary.html']
116 * }
117 * });
118 **/
119 bundles?: { [key: string]: string[]; };
120
121 /**
122 * AMD configurations, use module.config() to access in
123 * define() functions
124 **/
125 config?: { [id: string]: {}; };
126
127 /**
128 * Configures loading modules from CommonJS packages.
129 **/
130 packages?: {};
131
132 /**
133 * The number of seconds to wait before giving up on loading
134 * a script. The default is 7 seconds.
135 **/
136 waitSeconds?: number;
137
138 /**
139 * A name to give to a loading context. This allows require.js
140 * to load multiple versions of modules in a page, as long as
141 * each top-level require call specifies a unique context string.
142 **/
143 context?: string;
144
145 /**
146 * An array of dependencies to load.
147 **/
148 deps?: string[];
149
150 /**
151 * A function to pass to require that should be require after
152 * deps have been loaded.
153 * @param modules
154 **/
155 callback?: (...modules: any[]) => void;
156
157 /**
158 * If set to true, an error will be thrown if a script loads
159 * that does not call define() or have shim exports string
160 * value that can be checked.
161 **/
162 enforceDefine?: boolean;
163
164 /**
165 * If set to true, document.createElementNS() will be used
166 * to create script elements.
167 **/
168 xhtml?: boolean;
169
170 /**
171 * Extra query string arguments appended to URLs that RequireJS
172 * uses to fetch resources. Most useful to cache bust when
173 * the browser or server is not configured correctly.
174 *
175 * @example
176 * urlArgs: "bust= + (new Date()).getTime()
177 **/
178 urlArgs?: string;
179
180 /**
181 * Specify the value for the type="" attribute used for script
182 * tags inserted into the document by RequireJS. Default is
183 * "text/javascript". To use Firefox's JavasScript 1.8
184 * features, use "text/javascript;version=1.8".
185 **/
186 scriptType?: string;
187
188 /**
189 * If set to true, skips the data-main attribute scanning done
190 * to start module loading. Useful if RequireJS is embedded in
191 * a utility library that may interact with other RequireJS
192 * library on the page, and the embedded version should not do
193 * data-main loading.
194 **/
195 skipDataMain?: boolean;
196
197 /**
198 * Allow extending requirejs to support Subresource Integrity
199 * (SRI).
200 **/
201 onNodeCreated?: (node: HTMLScriptElement, config: RequireConfig, moduleName: string, url: string) => void;
202}
203
204// todo: not sure what to do with this guy
205interface RequireModule {
206
207 /**
208 *
209 **/
210 config(): {};
211
212}
213
214/**
215*
216**/
217interface RequireMap {
218
219 /**
220 *
221 **/
222 prefix: string;
223
224 /**
225 *
226 **/
227 name: string;
228
229 /**
230 *
231 **/
232 parentMap: RequireMap;
233
234 /**
235 *
236 **/
237 url: string;
238
239 /**
240 *
241 **/
242 originalName: string;
243
244 /**
245 *
246 **/
247 fullName: string;
248}
249
250interface Require {
251
252 /**
253 * Configure require.js
254 **/
255 config(config: RequireConfig): Require;
256
257 /**
258 * CommonJS require call
259 * @param module Module to load
260 * @return The loaded module
261 */
262 (module: string): any;
263
264 /**
265 * Start the main app logic.
266 * Callback is optional.
267 * Can alternatively use deps and callback.
268 * @param modules Required modules to load.
269 **/
270 (modules: string[]): void;
271
272 /**
273 * @see Require()
274 * @param ready Called when required modules are ready.
275 **/
276 (modules: string[], ready: Function): void;
277
278 /**
279 * @see http://requirejs.org/docs/api.html#errbacks
280 * @param ready Called when required modules are ready.
281 **/
282 (modules: string[], ready: Function, errback: Function): void;
283
284 /**
285 * Generate URLs from require module
286 * @param module Module to URL
287 * @return URL string
288 **/
289 toUrl(module: string): string;
290
291 /**
292 * Returns true if the module has already been loaded and defined.
293 * @param module Module to check
294 **/
295 defined(module: string): boolean;
296
297 /**
298 * Returns true if the module has already been requested or is in the process of loading and should be available at some point.
299 * @param module Module to check
300 **/
301 specified(module: string): boolean;
302
303 /**
304 * On Error override
305 * @param err
306 **/
307 onError(err: RequireError, errback?: (err: RequireError) => void): void;
308
309 /**
310 * Undefine a module
311 * @param module Module to undefine.
312 **/
313 undef(module: string): void;
314
315 /**
316 * Semi-private function, overload in special instance of undef()
317 **/
318 onResourceLoad(context: Object, map: RequireMap, depArray: RequireMap[]): void;
319}
320
321interface RequireDefine {
322
323 /**
324 * Define Simple Name/Value Pairs
325 * @param config Dictionary of Named/Value pairs for the config.
326 **/
327 (config: { [key: string]: any; }): void;
328
329 /**
330 * Define function.
331 * @param func: The function module.
332 **/
333 (func: () => any): void;
334
335 /**
336 * Define function with dependencies.
337 * @param deps List of dependencies module IDs.
338 * @param ready Callback function when the dependencies are loaded.
339 * callback param deps module dependencies
340 * callback return module definition
341 **/
342 (deps: string[], ready: Function): void;
343
344 /**
345 * Define module with simplified CommonJS wrapper.
346 * @param ready
347 * callback require requirejs instance
348 * callback exports exports object
349 * callback module module
350 * callback return module definition
351 **/
352 (ready: (require: Require, exports: { [key: string]: any; }, module: RequireModule) => any): void;
353
354 /**
355 * Define a module with a name and dependencies.
356 * @param name The name of the module.
357 * @param deps List of dependencies module IDs.
358 * @param ready Callback function when the dependencies are loaded.
359 * callback deps module dependencies
360 * callback return module definition
361 **/
362 (name: string, deps: string[], ready: Function): void;
363
364 /**
365 * Define a module with a name.
366 * @param name The name of the module.
367 * @param ready Callback function when the dependencies are loaded.
368 * callback return module definition
369 **/
370 (name: string, ready: Function): void;
371
372 /**
373 * Used to allow a clear indicator that a global define function (as needed for script src browser loading) conforms
374 * to the AMD API, any global define function SHOULD have a property called "amd" whose value is an object.
375 * This helps avoid conflict with any other existing JavaScript code that could have defined a define() function
376 * that does not conform to the AMD API.
377 * define.amd.jQuery is specific to jQuery and indicates that the loader is able to account for multiple version
378 * of jQuery being loaded simultaneously.
379 */
380 amd: Object;
381}
382
383// Ambient declarations for 'require' and 'define'
384declare var requirejs: Require;
385declare var require: Require;
386declare var define: RequireDefine;