path.d.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. import { BaseDirectory } from './fs';
  2. /**
  3. * Returns the path to the suggested directory for your app config files.
  4. *
  5. * @deprecated since 1.2.0: Will be removed in 2.0.0. Use {@link appConfigDir} or {@link appDataDir} instead.
  6. * @since 1.0.0
  7. */
  8. declare function appDir(): Promise<string>;
  9. /**
  10. * Returns the path to the suggested directory for your app's config files.
  11. * Resolves to `${configDir}/${bundleIdentifier}`, where `bundleIdentifier` is the value [`tauri.bundle.identifier`](https://tauri.app/v1/api/config/#bundleconfig.identifier) is configured in `tauri.conf.json`.
  12. * @example
  13. * ```typescript
  14. * import { appConfigDir } from '@tauri-apps/api/path';
  15. * const appConfigDirPath = await appConfigDir();
  16. * ```
  17. *
  18. * @since 1.2.0
  19. */
  20. declare function appConfigDir(): Promise<string>;
  21. /**
  22. * Returns the path to the suggested directory for your app's data files.
  23. * Resolves to `${dataDir}/${bundleIdentifier}`, where `bundleIdentifier` is the value [`tauri.bundle.identifier`](https://tauri.app/v1/api/config/#bundleconfig.identifier) is configured in `tauri.conf.json`.
  24. * @example
  25. * ```typescript
  26. * import { appDataDir } from '@tauri-apps/api/path';
  27. * const appDataDirPath = await appDataDir();
  28. * ```
  29. *
  30. * @since 1.2.0
  31. */
  32. declare function appDataDir(): Promise<string>;
  33. /**
  34. * Returns the path to the suggested directory for your app's local data files.
  35. * Resolves to `${localDataDir}/${bundleIdentifier}`, where `bundleIdentifier` is the value [`tauri.bundle.identifier`](https://tauri.app/v1/api/config/#bundleconfig.identifier) is configured in `tauri.conf.json`.
  36. * @example
  37. * ```typescript
  38. * import { appLocalDataDir } from '@tauri-apps/api/path';
  39. * const appLocalDataDirPath = await appLocalDataDir();
  40. * ```
  41. *
  42. * @since 1.2.0
  43. */
  44. declare function appLocalDataDir(): Promise<string>;
  45. /**
  46. * Returns the path to the suggested directory for your app's cache files.
  47. * Resolves to `${cacheDir}/${bundleIdentifier}`, where `bundleIdentifier` is the value [`tauri.bundle.identifier`](https://tauri.app/v1/api/config/#bundleconfig.identifier) is configured in `tauri.conf.json`.
  48. * @example
  49. * ```typescript
  50. * import { appCacheDir } from '@tauri-apps/api/path';
  51. * const appCacheDirPath = await appCacheDir();
  52. * ```
  53. *
  54. * @since 1.2.0
  55. */
  56. declare function appCacheDir(): Promise<string>;
  57. /**
  58. * Returns the path to the user's audio directory.
  59. *
  60. * #### Platform-specific
  61. *
  62. * - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_MUSIC_DIR`.
  63. * - **macOS:** Resolves to `$HOME/Music`.
  64. * - **Windows:** Resolves to `{FOLDERID_Music}`.
  65. * @example
  66. * ```typescript
  67. * import { audioDir } from '@tauri-apps/api/path';
  68. * const audioDirPath = await audioDir();
  69. * ```
  70. *
  71. * @since 1.0.0
  72. */
  73. declare function audioDir(): Promise<string>;
  74. /**
  75. * Returns the path to the user's cache directory.
  76. *
  77. * #### Platform-specific
  78. *
  79. * - **Linux:** Resolves to `$XDG_CACHE_HOME` or `$HOME/.cache`.
  80. * - **macOS:** Resolves to `$HOME/Library/Caches`.
  81. * - **Windows:** Resolves to `{FOLDERID_LocalAppData}`.
  82. * @example
  83. * ```typescript
  84. * import { cacheDir } from '@tauri-apps/api/path';
  85. * const cacheDirPath = await cacheDir();
  86. * ```
  87. *
  88. * @since 1.0.0
  89. */
  90. declare function cacheDir(): Promise<string>;
  91. /**
  92. * Returns the path to the user's config directory.
  93. *
  94. * #### Platform-specific
  95. *
  96. * - **Linux:** Resolves to `$XDG_CONFIG_HOME` or `$HOME/.config`.
  97. * - **macOS:** Resolves to `$HOME/Library/Application Support`.
  98. * - **Windows:** Resolves to `{FOLDERID_RoamingAppData}`.
  99. * @example
  100. * ```typescript
  101. * import { configDir } from '@tauri-apps/api/path';
  102. * const configDirPath = await configDir();
  103. * ```
  104. *
  105. * @since 1.0.0
  106. */
  107. declare function configDir(): Promise<string>;
  108. /**
  109. * Returns the path to the user's data directory.
  110. *
  111. * #### Platform-specific
  112. *
  113. * - **Linux:** Resolves to `$XDG_DATA_HOME` or `$HOME/.local/share`.
  114. * - **macOS:** Resolves to `$HOME/Library/Application Support`.
  115. * - **Windows:** Resolves to `{FOLDERID_RoamingAppData}`.
  116. * @example
  117. * ```typescript
  118. * import { dataDir } from '@tauri-apps/api/path';
  119. * const dataDirPath = await dataDir();
  120. * ```
  121. *
  122. * @since 1.0.0
  123. */
  124. declare function dataDir(): Promise<string>;
  125. /**
  126. * Returns the path to the user's desktop directory.
  127. *
  128. * #### Platform-specific
  129. *
  130. * - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DESKTOP_DIR`.
  131. * - **macOS:** Resolves to `$HOME/Desktop`.
  132. * - **Windows:** Resolves to `{FOLDERID_Desktop}`.
  133. * @example
  134. * ```typescript
  135. * import { desktopDir } from '@tauri-apps/api/path';
  136. * const desktopPath = await desktopDir();
  137. * ```
  138. *
  139. * @since 1.0.0
  140. */
  141. declare function desktopDir(): Promise<string>;
  142. /**
  143. * Returns the path to the user's document directory.
  144. * @example
  145. * ```typescript
  146. * import { documentDir } from '@tauri-apps/api/path';
  147. * const documentDirPath = await documentDir();
  148. * ```
  149. *
  150. * #### Platform-specific
  151. *
  152. * - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DOCUMENTS_DIR`.
  153. * - **macOS:** Resolves to `$HOME/Documents`.
  154. * - **Windows:** Resolves to `{FOLDERID_Documents}`.
  155. *
  156. * @since 1.0.0
  157. */
  158. declare function documentDir(): Promise<string>;
  159. /**
  160. * Returns the path to the user's download directory.
  161. *
  162. * #### Platform-specific
  163. *
  164. * - **Linux**: Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DOWNLOAD_DIR`.
  165. * - **macOS**: Resolves to `$HOME/Downloads`.
  166. * - **Windows**: Resolves to `{FOLDERID_Downloads}`.
  167. * @example
  168. * ```typescript
  169. * import { downloadDir } from '@tauri-apps/api/path';
  170. * const downloadDirPath = await downloadDir();
  171. * ```
  172. *
  173. * @since 1.0.0
  174. */
  175. declare function downloadDir(): Promise<string>;
  176. /**
  177. * Returns the path to the user's executable directory.
  178. *
  179. * #### Platform-specific
  180. *
  181. * - **Linux:** Resolves to `$XDG_BIN_HOME/../bin` or `$XDG_DATA_HOME/../bin` or `$HOME/.local/bin`.
  182. * - **macOS:** Not supported.
  183. * - **Windows:** Not supported.
  184. * @example
  185. * ```typescript
  186. * import { executableDir } from '@tauri-apps/api/path';
  187. * const executableDirPath = await executableDir();
  188. * ```
  189. *
  190. * @since 1.0.0
  191. */
  192. declare function executableDir(): Promise<string>;
  193. /**
  194. * Returns the path to the user's font directory.
  195. *
  196. * #### Platform-specific
  197. *
  198. * - **Linux:** Resolves to `$XDG_DATA_HOME/fonts` or `$HOME/.local/share/fonts`.
  199. * - **macOS:** Resolves to `$HOME/Library/Fonts`.
  200. * - **Windows:** Not supported.
  201. * @example
  202. * ```typescript
  203. * import { fontDir } from '@tauri-apps/api/path';
  204. * const fontDirPath = await fontDir();
  205. * ```
  206. *
  207. * @since 1.0.0
  208. */
  209. declare function fontDir(): Promise<string>;
  210. /**
  211. * Returns the path to the user's home directory.
  212. *
  213. * #### Platform-specific
  214. *
  215. * - **Linux:** Resolves to `$HOME`.
  216. * - **macOS:** Resolves to `$HOME`.
  217. * - **Windows:** Resolves to `{FOLDERID_Profile}`.
  218. * @example
  219. * ```typescript
  220. * import { homeDir } from '@tauri-apps/api/path';
  221. * const homeDirPath = await homeDir();
  222. * ```
  223. *
  224. * @since 1.0.0
  225. */
  226. declare function homeDir(): Promise<string>;
  227. /**
  228. * Returns the path to the user's local data directory.
  229. *
  230. * #### Platform-specific
  231. *
  232. * - **Linux:** Resolves to `$XDG_DATA_HOME` or `$HOME/.local/share`.
  233. * - **macOS:** Resolves to `$HOME/Library/Application Support`.
  234. * - **Windows:** Resolves to `{FOLDERID_LocalAppData}`.
  235. * @example
  236. * ```typescript
  237. * import { localDataDir } from '@tauri-apps/api/path';
  238. * const localDataDirPath = await localDataDir();
  239. * ```
  240. *
  241. * @since 1.0.0
  242. */
  243. declare function localDataDir(): Promise<string>;
  244. /**
  245. * Returns the path to the user's picture directory.
  246. *
  247. * #### Platform-specific
  248. *
  249. * - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_PICTURES_DIR`.
  250. * - **macOS:** Resolves to `$HOME/Pictures`.
  251. * - **Windows:** Resolves to `{FOLDERID_Pictures}`.
  252. * @example
  253. * ```typescript
  254. * import { pictureDir } from '@tauri-apps/api/path';
  255. * const pictureDirPath = await pictureDir();
  256. * ```
  257. *
  258. * @since 1.0.0
  259. */
  260. declare function pictureDir(): Promise<string>;
  261. /**
  262. * Returns the path to the user's public directory.
  263. *
  264. * #### Platform-specific
  265. *
  266. * - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_PUBLICSHARE_DIR`.
  267. * - **macOS:** Resolves to `$HOME/Public`.
  268. * - **Windows:** Resolves to `{FOLDERID_Public}`.
  269. * @example
  270. * ```typescript
  271. * import { publicDir } from '@tauri-apps/api/path';
  272. * const publicDirPath = await publicDir();
  273. * ```
  274. *
  275. * @since 1.0.0
  276. */
  277. declare function publicDir(): Promise<string>;
  278. /**
  279. * Returns the path to the application's resource directory.
  280. * To resolve a resource path, see the [[resolveResource | `resolveResource API`]].
  281. * @example
  282. * ```typescript
  283. * import { resourceDir } from '@tauri-apps/api/path';
  284. * const resourceDirPath = await resourceDir();
  285. * ```
  286. *
  287. * @since 1.0.0
  288. */
  289. declare function resourceDir(): Promise<string>;
  290. /**
  291. * Resolve the path to a resource file.
  292. * @example
  293. * ```typescript
  294. * import { resolveResource } from '@tauri-apps/api/path';
  295. * const resourcePath = await resolveResource('script.sh');
  296. * ```
  297. *
  298. * @param resourcePath The path to the resource.
  299. * Must follow the same syntax as defined in `tauri.conf.json > tauri > bundle > resources`, i.e. keeping subfolders and parent dir components (`../`).
  300. * @returns The full path to the resource.
  301. *
  302. * @since 1.0.0
  303. */
  304. declare function resolveResource(resourcePath: string): Promise<string>;
  305. /**
  306. * Returns the path to the user's runtime directory.
  307. *
  308. * #### Platform-specific
  309. *
  310. * - **Linux:** Resolves to `$XDG_RUNTIME_DIR`.
  311. * - **macOS:** Not supported.
  312. * - **Windows:** Not supported.
  313. * @example
  314. * ```typescript
  315. * import { runtimeDir } from '@tauri-apps/api/path';
  316. * const runtimeDirPath = await runtimeDir();
  317. * ```
  318. *
  319. * @since 1.0.0
  320. */
  321. declare function runtimeDir(): Promise<string>;
  322. /**
  323. * Returns the path to the user's template directory.
  324. *
  325. * #### Platform-specific
  326. *
  327. * - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_TEMPLATES_DIR`.
  328. * - **macOS:** Not supported.
  329. * - **Windows:** Resolves to `{FOLDERID_Templates}`.
  330. * @example
  331. * ```typescript
  332. * import { templateDir } from '@tauri-apps/api/path';
  333. * const templateDirPath = await templateDir();
  334. * ```
  335. *
  336. * @since 1.0.0
  337. */
  338. declare function templateDir(): Promise<string>;
  339. /**
  340. * Returns the path to the user's video directory.
  341. *
  342. * #### Platform-specific
  343. *
  344. * - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_VIDEOS_DIR`.
  345. * - **macOS:** Resolves to `$HOME/Movies`.
  346. * - **Windows:** Resolves to `{FOLDERID_Videos}`.
  347. * @example
  348. * ```typescript
  349. * import { videoDir } from '@tauri-apps/api/path';
  350. * const videoDirPath = await videoDir();
  351. * ```
  352. *
  353. * @since 1.0.0
  354. */
  355. declare function videoDir(): Promise<string>;
  356. /**
  357. * Returns the path to the suggested log directory.
  358. *
  359. * @deprecated since 1.2.0: Will be removed in 2.0.0. Use {@link appLogDir} instead.
  360. * @since 1.0.0
  361. */
  362. declare function logDir(): Promise<string>;
  363. /**
  364. * Returns the path to the suggested directory for your app's log files.
  365. *
  366. * #### Platform-specific
  367. *
  368. * - **Linux:** Resolves to `${configDir}/${bundleIdentifier}/logs`.
  369. * - **macOS:** Resolves to `${homeDir}/Library/Logs/{bundleIdentifier}`
  370. * - **Windows:** Resolves to `${configDir}/${bundleIdentifier}/logs`.
  371. * @example
  372. * ```typescript
  373. * import { appLogDir } from '@tauri-apps/api/path';
  374. * const appLogDirPath = await appLogDir();
  375. * ```
  376. *
  377. * @since 1.2.0
  378. */
  379. declare function appLogDir(): Promise<string>;
  380. /**
  381. * Provides the platform-specific path segment separator:
  382. * - `\` on Windows
  383. * - `/` on POSIX
  384. *
  385. * @since 1.0.0
  386. */
  387. declare const sep: string;
  388. /**
  389. * Provides the platform-specific path segment delimiter:
  390. * - `;` on Windows
  391. * - `:` on POSIX
  392. *
  393. * @since 1.0.0
  394. */
  395. declare const delimiter: string;
  396. /**
  397. * Resolves a sequence of `paths` or `path` segments into an absolute path.
  398. * @example
  399. * ```typescript
  400. * import { resolve, appDataDir } from '@tauri-apps/api/path';
  401. * const appDataDirPath = await appDataDir();
  402. * const path = await resolve(appDataDirPath, '..', 'users', 'tauri', 'avatar.png');
  403. * ```
  404. *
  405. * @since 1.0.0
  406. */
  407. declare function resolve(...paths: string[]): Promise<string>;
  408. /**
  409. * Normalizes the given `path`, resolving `'..'` and `'.'` segments and resolve symbolic links.
  410. * @example
  411. * ```typescript
  412. * import { normalize, appDataDir } from '@tauri-apps/api/path';
  413. * const appDataDirPath = await appDataDir();
  414. * const path = await normalize(appDataDirPath, '..', 'users', 'tauri', 'avatar.png');
  415. * ```
  416. *
  417. * @since 1.0.0
  418. */
  419. declare function normalize(path: string): Promise<string>;
  420. /**
  421. * Joins all given `path` segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.
  422. * @example
  423. * ```typescript
  424. * import { join, appDataDir } from '@tauri-apps/api/path';
  425. * const appDataDirPath = await appDataDir();
  426. * const path = await join(appDataDirPath, 'users', 'tauri', 'avatar.png');
  427. * ```
  428. *
  429. * @since 1.0.0
  430. */
  431. declare function join(...paths: string[]): Promise<string>;
  432. /**
  433. * Returns the directory name of a `path`. Trailing directory separators are ignored.
  434. * @example
  435. * ```typescript
  436. * import { dirname } from '@tauri-apps/api/path';
  437. * const dir = await dirname('/path/to/somedir/');
  438. * assert(dir === 'somedir');
  439. * ```
  440. *
  441. * @since 1.0.0
  442. */
  443. declare function dirname(path: string): Promise<string>;
  444. /**
  445. * Returns the extension of the `path`.
  446. * @example
  447. * ```typescript
  448. * import { extname } from '@tauri-apps/api/path';
  449. * const ext = await extname('/path/to/file.html');
  450. * assert(ext === 'html');
  451. * ```
  452. *
  453. * @since 1.0.0
  454. */
  455. declare function extname(path: string): Promise<string>;
  456. /**
  457. * Returns the last portion of a `path`. Trailing directory separators are ignored.
  458. * @example
  459. * ```typescript
  460. * import { basename } from '@tauri-apps/api/path';
  461. * const base = await basename('path/to/app.conf');
  462. * assert(base === 'app.conf');
  463. * ```
  464. *
  465. * @param ext An optional file extension to be removed from the returned path.
  466. *
  467. * @since 1.0.0
  468. */
  469. declare function basename(path: string, ext?: string): Promise<string>;
  470. /**
  471. * Returns whether the path is absolute or not.
  472. * @example
  473. * ```typescript
  474. * import { isAbsolute } from '@tauri-apps/api/path';
  475. * assert(await isAbsolute('/home/tauri'));
  476. * ```
  477. *
  478. * @since 1.0.0
  479. */
  480. declare function isAbsolute(path: string): Promise<boolean>;
  481. export { appDir, appConfigDir, appDataDir, appLocalDataDir, appCacheDir, appLogDir, audioDir, cacheDir, configDir, dataDir, desktopDir, documentDir, downloadDir, executableDir, fontDir, homeDir, localDataDir, pictureDir, publicDir, resourceDir, resolveResource, runtimeDir, templateDir, videoDir, logDir, BaseDirectory, sep, delimiter, resolve, normalize, join, dirname, extname, basename, isAbsolute };