require.d.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. // Type definitions for RequireJS 2.1.8
  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. * AMD configurations, use module.config() to access in
  100. * define() functions
  101. **/
  102. config?: { [id: string]: {}; };
  103. /**
  104. * Configures loading modules from CommonJS packages.
  105. **/
  106. packages?: {};
  107. /**
  108. * The number of seconds to wait before giving up on loading
  109. * a script. The default is 7 seconds.
  110. **/
  111. waitSeconds?: number;
  112. /**
  113. * A name to give to a loading context. This allows require.js
  114. * to load multiple versions of modules in a page, as long as
  115. * each top-level require call specifies a unique context string.
  116. **/
  117. context?: string;
  118. /**
  119. * An array of dependencies to load.
  120. **/
  121. deps?: string[];
  122. /**
  123. * A function to pass to require that should be require after
  124. * deps have been loaded.
  125. * @param modules
  126. **/
  127. callback?: (...modules: any[]) => void;
  128. /**
  129. * If set to true, an error will be thrown if a script loads
  130. * that does not call define() or have shim exports string
  131. * value that can be checked.
  132. **/
  133. enforceDefine?: boolean;
  134. /**
  135. * If set to true, document.createElementNS() will be used
  136. * to create script elements.
  137. **/
  138. xhtml?: boolean;
  139. /**
  140. * Extra query string arguments appended to URLs that RequireJS
  141. * uses to fetch resources. Most useful to cachce bust when
  142. * the browser or server is not configured correcty.
  143. *
  144. * @example
  145. * urlArgs: "bust= + (new Date()).getTime()
  146. **/
  147. urlArgs?: string;
  148. /**
  149. * Specify the value for the type="" attribute used for script
  150. * tags inserted into the document by RequireJS. Default is
  151. * "text/javascript". To use Firefox's JavasScript 1.8
  152. * features, use "text/javascript;version=1.8".
  153. **/
  154. scriptType?: string;
  155. }
  156. // todo: not sure what to do with this guy
  157. interface RequireModule {
  158. /**
  159. *
  160. **/
  161. config(): {};
  162. }
  163. /**
  164. *
  165. **/
  166. interface RequireMap {
  167. /**
  168. *
  169. **/
  170. prefix: string;
  171. /**
  172. *
  173. **/
  174. name: string;
  175. /**
  176. *
  177. **/
  178. parentMap: RequireMap;
  179. /**
  180. *
  181. **/
  182. url: string;
  183. /**
  184. *
  185. **/
  186. originalName: string;
  187. /**
  188. *
  189. **/
  190. fullName: string;
  191. }
  192. interface Require {
  193. /**
  194. * Configure require.js
  195. **/
  196. config(config: RequireConfig): Require;
  197. /**
  198. * CommonJS require call
  199. * @param module Module to load
  200. * @return The loaded module
  201. */
  202. (module: string): any;
  203. /**
  204. * Start the main app logic.
  205. * Callback is optional.
  206. * Can alternatively use deps and callback.
  207. * @param modules Required modules to load.
  208. **/
  209. (modules: string[]): void;
  210. /**
  211. * @see Require()
  212. * @param ready Called when required modules are ready.
  213. **/
  214. (modules: string[], ready: Function): void;
  215. /**
  216. * @see http://requirejs.org/docs/api.html#errbacks
  217. * @param ready Called when required modules are ready.
  218. **/
  219. (modules: string[], ready: Function, errback: Function): void;
  220. /**
  221. * Generate URLs from require module
  222. * @param module Module to URL
  223. * @return URL string
  224. **/
  225. toUrl(module: string): string;
  226. /**
  227. * Returns true if the module has already been loaded and defined.
  228. * @param module Module to check
  229. **/
  230. defined(module: string): boolean;
  231. /**
  232. * Returns true if the module has already been requested or is in the process of loading and should be available at some point.
  233. * @param module Module to check
  234. **/
  235. specified(module: string): boolean;
  236. /**
  237. * On Error override
  238. * @param err
  239. **/
  240. onError(err: RequireError, errback?: (err: RequireError) => void): void;
  241. /**
  242. * Undefine a module
  243. * @param module Module to undefine.
  244. **/
  245. undef(module: string): void;
  246. /**
  247. * Semi-private function, overload in special instance of undef()
  248. **/
  249. onResourceLoad(context: Object, map: RequireMap, depArray: RequireMap[]): void;
  250. }
  251. interface RequireDefine {
  252. /**
  253. * Define Simple Name/Value Pairs
  254. * @param config Dictionary of Named/Value pairs for the config.
  255. **/
  256. (config: { [key: string]: any; }): void;
  257. /**
  258. * Define function.
  259. * @param func: The function module.
  260. **/
  261. (func: () => any): void;
  262. /**
  263. * Define function with dependencies.
  264. * @param deps List of dependencies module IDs.
  265. * @param ready Callback function when the dependencies are loaded.
  266. * callback param deps module dependencies
  267. * callback return module definition
  268. **/
  269. (deps: string[], ready: Function): void;
  270. /**
  271. * Define module with simplified CommonJS wrapper.
  272. * @param ready
  273. * callback require requirejs instance
  274. * callback exports exports object
  275. * callback module module
  276. * callback return module definition
  277. **/
  278. (ready: (require: Require, exports: { [key: string]: any; }, module: RequireModule) => any): void;
  279. /**
  280. * Define a module with a name and dependencies.
  281. * @param name The name of the module.
  282. * @param deps List of dependencies module IDs.
  283. * @param ready Callback function when the dependencies are loaded.
  284. * callback deps module dependencies
  285. * callback return module definition
  286. **/
  287. (name: string, deps: string[], ready: Function): void;
  288. /**
  289. * Define a module with a name.
  290. * @param name The name of the module.
  291. * @param ready Callback function when the dependencies are loaded.
  292. * callback return module definition
  293. **/
  294. (name: string, ready: Function): void;
  295. /**
  296. * Used to allow a clear indicator that a global define function (as needed for script src browser loading) conforms
  297. * to the AMD API, any global define function SHOULD have a property called "amd" whose value is an object.
  298. * This helps avoid conflict with any other existing JavaScript code that could have defined a define() function
  299. * that does not conform to the AMD API.
  300. * define.amd.jQuery is specific to jQuery and indicates that the loader is able to account for multiple version
  301. * of jQuery being loaded simultaneously.
  302. */
  303. amd: Object;
  304. }
  305. // Ambient declarations for 'require' and 'define'
  306. declare var requirejs: Require;
  307. declare var require: Require;
  308. declare var define: RequireDefine;