requirejs.d.ts 10 KB

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