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