upgrade.d.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /**
  2. * @license Angular v8.1.0
  3. * (c) 2010-2019 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import { HashLocationStrategy } from '@angular/common';
  7. import { InjectionToken } from '@angular/core';
  8. import { Location } from '@angular/common';
  9. import { LocationStrategy } from '@angular/common';
  10. import { ModuleWithProviders } from '@angular/core';
  11. import { PathLocationStrategy } from '@angular/common';
  12. import { PlatformLocation } from '@angular/common';
  13. import { UpgradeModule } from '@angular/upgrade/static';
  14. /**
  15. * Location service that provides a drop-in replacement for the $location service
  16. * provided in AngularJS.
  17. *
  18. * @see [Using the Angular Unified Location Service](guide/upgrade#using-the-unified-angular-location-service)
  19. *
  20. * @publicApi
  21. */
  22. export declare class $locationShim {
  23. private location;
  24. private platformLocation;
  25. private urlCodec;
  26. private locationStrategy;
  27. private initalizing;
  28. private updateBrowser;
  29. private $$absUrl;
  30. private $$url;
  31. private $$protocol;
  32. private $$host;
  33. private $$port;
  34. private $$replace;
  35. private $$path;
  36. private $$search;
  37. private $$hash;
  38. private $$state;
  39. private $$changeListeners;
  40. private cachedState;
  41. constructor($injector: any, location: Location, platformLocation: PlatformLocation, urlCodec: UrlCodec, locationStrategy: LocationStrategy);
  42. private initialize;
  43. private resetBrowserUpdate;
  44. private lastHistoryState;
  45. private lastBrowserUrl;
  46. private browserUrl;
  47. private lastCachedState;
  48. private cacheState;
  49. /**
  50. * This function emulates the $browser.state() function from AngularJS. It will cause
  51. * history.state to be cached unless changed with deep equality check.
  52. */
  53. private browserState;
  54. private stripBaseUrl;
  55. private getServerBase;
  56. private parseAppUrl;
  57. /**
  58. * Registers listeners for URL changes. This API is used to catch updates performed by the
  59. * AngularJS framework. These changes are a subset of the `$locationChangeStart` and
  60. * `$locationChangeSuccess` events which fire when AngularJS updates its internally-referenced
  61. * version of the browser URL.
  62. *
  63. * It's possible for `$locationChange` events to happen, but for the browser URL
  64. * (window.location) to remain unchanged. This `onChange` callback will fire only when AngularJS
  65. * actually updates the browser URL (window.location).
  66. *
  67. * @param fn The callback function that is triggered for the listener when the URL changes.
  68. * @param err The callback function that is triggered when an error occurs.
  69. */
  70. onChange(fn: (url: string, state: unknown, oldUrl: string, oldState: unknown) => void, err?: (e: Error) => void): void;
  71. /**
  72. * Parses the provided URL, and sets the current URL to the parsed result.
  73. *
  74. * @param url The URL string.
  75. */
  76. $$parse(url: string): void;
  77. /**
  78. * Parses the provided URL and its relative URL.
  79. *
  80. * @param url The full URL string.
  81. * @param relHref A URL string relative to the full URL string.
  82. */
  83. $$parseLinkUrl(url: string, relHref?: string | null): boolean;
  84. private setBrowserUrlWithFallback;
  85. private composeUrls;
  86. /**
  87. * Retrieves the full URL representation with all segments encoded according to
  88. * rules specified in
  89. * [RFC 3986](http://www.ietf.org/rfc/rfc3986.txt).
  90. *
  91. *
  92. * ```js
  93. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
  94. * let absUrl = $location.absUrl();
  95. * // => "http://example.com/#/some/path?foo=bar&baz=xoxo"
  96. * ```
  97. */
  98. absUrl(): string;
  99. /**
  100. * Retrieves the current URL, or sets a new URL. When setting a URL,
  101. * changes the path, search, and hash, and returns a reference to its own instance.
  102. *
  103. * ```js
  104. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
  105. * let url = $location.url();
  106. * // => "/some/path?foo=bar&baz=xoxo"
  107. * ```
  108. */
  109. url(): string;
  110. url(url: string): this;
  111. /**
  112. * Retrieves the protocol of the current URL.
  113. *
  114. * ```js
  115. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
  116. * let protocol = $location.protocol();
  117. * // => "http"
  118. * ```
  119. */
  120. protocol(): string;
  121. /**
  122. * Retrieves the protocol of the current URL.
  123. *
  124. * In contrast to the non-AngularJS version `location.host` which returns `hostname:port`, this
  125. * returns the `hostname` portion only.
  126. *
  127. *
  128. * ```js
  129. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
  130. * let host = $location.host();
  131. * // => "example.com"
  132. *
  133. * // given URL http://user:password@example.com:8080/#/some/path?foo=bar&baz=xoxo
  134. * host = $location.host();
  135. * // => "example.com"
  136. * host = location.host;
  137. * // => "example.com:8080"
  138. * ```
  139. */
  140. host(): string;
  141. /**
  142. * Retrieves the port of the current URL.
  143. *
  144. * ```js
  145. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
  146. * let port = $location.port();
  147. * // => 80
  148. * ```
  149. */
  150. port(): number | null;
  151. /**
  152. * Retrieves the path of the current URL, or changes the path and returns a reference to its own
  153. * instance.
  154. *
  155. * Paths should always begin with forward slash (/). This method adds the forward slash
  156. * if it is missing.
  157. *
  158. * ```js
  159. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
  160. * let path = $location.path();
  161. * // => "/some/path"
  162. * ```
  163. */
  164. path(): string;
  165. path(path: string | number | null): this;
  166. /**
  167. * Retrieves a map of the search parameters of the current URL, or changes a search
  168. * part and returns a reference to its own instance.
  169. *
  170. *
  171. * ```js
  172. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
  173. * let searchObject = $location.search();
  174. * // => {foo: 'bar', baz: 'xoxo'}
  175. *
  176. * // set foo to 'yipee'
  177. * $location.search('foo', 'yipee');
  178. * // $location.search() => {foo: 'yipee', baz: 'xoxo'}
  179. * ```
  180. *
  181. * @param {string|Object.<string>|Object.<Array.<string>>} search New search params - string or
  182. * hash object.
  183. *
  184. * When called with a single argument the method acts as a setter, setting the `search` component
  185. * of `$location` to the specified value.
  186. *
  187. * If the argument is a hash object containing an array of values, these values will be encoded
  188. * as duplicate search parameters in the URL.
  189. *
  190. * @param {(string|Number|Array<string>|boolean)=} paramValue If `search` is a string or number, then `paramValue`
  191. * will override only a single search property.
  192. *
  193. * If `paramValue` is an array, it will override the property of the `search` component of
  194. * `$location` specified via the first argument.
  195. *
  196. * If `paramValue` is `null`, the property specified via the first argument will be deleted.
  197. *
  198. * If `paramValue` is `true`, the property specified via the first argument will be added with no
  199. * value nor trailing equal sign.
  200. *
  201. * @return {Object} The parsed `search` object of the current URL, or the changed `search` object.
  202. */
  203. search(): {
  204. [key: string]: unknown;
  205. };
  206. search(search: string | number | {
  207. [key: string]: unknown;
  208. }): this;
  209. search(search: string | number | {
  210. [key: string]: unknown;
  211. }, paramValue: null | undefined | string | number | boolean | string[]): this;
  212. /**
  213. * Retrieves the current hash fragment, or changes the hash fragment and returns a reference to
  214. * its own instance.
  215. *
  216. * ```js
  217. * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue
  218. * let hash = $location.hash();
  219. * // => "hashValue"
  220. * ```
  221. */
  222. hash(): string;
  223. hash(hash: string | number | null): this;
  224. /**
  225. * Changes to `$location` during the current `$digest` will replace the current
  226. * history record, instead of adding a new one.
  227. */
  228. replace(): this;
  229. /**
  230. * Retrieves the history state object when called without any parameter.
  231. *
  232. * Change the history state object when called with one parameter and return `$location`.
  233. * The state object is later passed to `pushState` or `replaceState`.
  234. *
  235. * This method is supported only in HTML5 mode and only in browsers supporting
  236. * the HTML5 History API methods such as `pushState` and `replaceState`. If you need to support
  237. * older browsers (like IE9 or Android < 4.0), don't use this method.
  238. *
  239. */
  240. state(): unknown;
  241. state(state: unknown): this;
  242. }
  243. /**
  244. * The factory function used to create an instance of the `$locationShim` in Angular,
  245. * and provides an API-compatiable `$locationProvider` for AngularJS.
  246. *
  247. * @publicApi
  248. */
  249. export declare class $locationShimProvider {
  250. private ngUpgrade;
  251. private location;
  252. private platformLocation;
  253. private urlCodec;
  254. private locationStrategy;
  255. constructor(ngUpgrade: UpgradeModule, location: Location, platformLocation: PlatformLocation, urlCodec: UrlCodec, locationStrategy: LocationStrategy);
  256. /**
  257. * Factory method that returns an instance of the $locationShim
  258. */
  259. $get(): $locationShim;
  260. /**
  261. * Stub method used to keep API compatible with AngularJS. This setting is configured through
  262. * the LocationUpgradeModule's `config` method in your Angular app.
  263. */
  264. hashPrefix(prefix?: string): void;
  265. /**
  266. * Stub method used to keep API compatible with AngularJS. This setting is configured through
  267. * the LocationUpgradeModule's `config` method in your Angular app.
  268. */
  269. html5Mode(mode?: any): void;
  270. }
  271. /**
  272. * A `UrlCodec` that uses logic from AngularJS to serialize and parse URLs
  273. * and URL parameters.
  274. *
  275. * @publicApi
  276. */
  277. export declare class AngularJSUrlCodec implements UrlCodec {
  278. encodePath(path: string): string;
  279. encodeSearch(search: string | {
  280. [k: string]: unknown;
  281. }): string;
  282. encodeHash(hash: string): string;
  283. decodePath(path: string, html5Mode?: boolean): string;
  284. decodeSearch(search: string): {
  285. [k: string]: unknown;
  286. };
  287. decodeHash(hash: string): string;
  288. normalize(href: string): string;
  289. normalize(path: string, search: {
  290. [k: string]: unknown;
  291. }, hash: string, baseUrl?: string): string;
  292. areEqual(valA: string, valB: string): boolean;
  293. parse(url: string, base?: string): {
  294. href: string;
  295. protocol: string;
  296. host: string;
  297. search: string;
  298. hash: string;
  299. hostname: string;
  300. port: string;
  301. pathname: string;
  302. };
  303. }
  304. /**
  305. * A provider token used to configure the location upgrade module.
  306. *
  307. * @publicApi
  308. */
  309. export declare const LOCATION_UPGRADE_CONFIGURATION: InjectionToken<LocationUpgradeConfig>;
  310. /**
  311. * Configuration options for LocationUpgrade.
  312. *
  313. * @publicApi
  314. */
  315. export declare interface LocationUpgradeConfig {
  316. /**
  317. * Configures whether the location upgrade module should use the `HashLocationStrategy`
  318. * or the `PathLocationStrategy`
  319. */
  320. useHash?: boolean;
  321. /**
  322. * Configures the hash prefix used in the URL when using the `HashLocationStrategy`
  323. */
  324. hashPrefix?: string;
  325. /**
  326. * Configures the URL codec for encoding and decoding URLs. Default is the `AngularJSCodec`
  327. */
  328. urlCodec?: typeof UrlCodec;
  329. /**
  330. * Configures the base href when used in server-side rendered applications
  331. */
  332. serverBaseHref?: string;
  333. /**
  334. * Configures the base href when used in client-side rendered applications
  335. */
  336. appBaseHref?: string;
  337. }
  338. /**
  339. * `NgModule` used for providing and configuring Angular's Unified Location Service for upgrading.
  340. *
  341. * @see [Using the Unified Angular Location Service](guide/upgrade#using-the-unified-angular-location-service)
  342. *
  343. * @publicApi
  344. */
  345. export declare class LocationUpgradeModule {
  346. static config(config?: LocationUpgradeConfig): ModuleWithProviders<LocationUpgradeModule>;
  347. }
  348. /**
  349. * A codec for encoding and decoding URL parts.
  350. *
  351. * @publicApi
  352. **/
  353. export declare abstract class UrlCodec {
  354. /**
  355. * Encodes the path from the provided string
  356. *
  357. * @param path The path string
  358. */
  359. abstract encodePath(path: string): string;
  360. /**
  361. * Decodes the path from the provided string
  362. *
  363. * @param path The path string
  364. */
  365. abstract decodePath(path: string): string;
  366. /**
  367. * Encodes the search string from the provided string or object
  368. *
  369. * @param path The path string or object
  370. */
  371. abstract encodeSearch(search: string | {
  372. [k: string]: unknown;
  373. }): string;
  374. /**
  375. * Decodes the search objects from the provided string
  376. *
  377. * @param path The path string
  378. */
  379. abstract decodeSearch(search: string): {
  380. [k: string]: unknown;
  381. };
  382. /**
  383. * Encodes the hash from the provided string
  384. *
  385. * @param path The hash string
  386. */
  387. abstract encodeHash(hash: string): string;
  388. /**
  389. * Decodes the hash from the provided string
  390. *
  391. * @param path The hash string
  392. */
  393. abstract decodeHash(hash: string): string;
  394. /**
  395. * Normalizes the URL from the provided string
  396. *
  397. * @param path The URL string
  398. */
  399. abstract normalize(href: string): string;
  400. /**
  401. * Normalizes the URL from the provided string, search, hash, and base URL parameters
  402. *
  403. * @param path The URL path
  404. * @param search The search object
  405. * @param hash The has string
  406. * @param baseUrl The base URL for the URL
  407. */
  408. abstract normalize(path: string, search: {
  409. [k: string]: unknown;
  410. }, hash: string, baseUrl?: string): string;
  411. /**
  412. * Checks whether the two strings are equal
  413. * @param valA First string for comparison
  414. * @param valB Second string for comparison
  415. */
  416. abstract areEqual(valA: string, valB: string): boolean;
  417. /**
  418. * Parses the URL string based on the base URL
  419. *
  420. * @param url The full URL string
  421. * @param base The base for the URL
  422. */
  423. abstract parse(url: string, base?: string): {
  424. href: string;
  425. protocol: string;
  426. host: string;
  427. search: string;
  428. hash: string;
  429. hostname: string;
  430. port: string;
  431. pathname: string;
  432. };
  433. }
  434. export declare function ɵangular_packages_common_upgrade_upgrade_a(config: LocationUpgradeConfig, appBaseHref?: string): string;
  435. export declare function ɵangular_packages_common_upgrade_upgrade_b(config: LocationUpgradeConfig): any;
  436. export declare function ɵangular_packages_common_upgrade_upgrade_c(platformLocation: PlatformLocation, baseHref: string, options?: LocationUpgradeConfig): HashLocationStrategy | PathLocationStrategy;
  437. export declare function ɵangular_packages_common_upgrade_upgrade_d(ngUpgrade: UpgradeModule, location: Location, platformLocation: PlatformLocation, urlCodec: UrlCodec, locationStrategy: LocationStrategy): $locationShim;
  438. export { }