path.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. // Copyright 2019-2024 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. /**
  5. * The path module provides utilities for working with file and directory paths.
  6. *
  7. * This package is also accessible with `window.__TAURI__.path` when [`app.withGlobalTauri`](https://tauri.app/v1/api/config/#appconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
  8. *
  9. * It is recommended to allowlist only the APIs you use for optimal bundle size and security.
  10. * @module
  11. */
  12. import { invoke } from './core'
  13. /**
  14. * @since 2.0.0
  15. */
  16. enum BaseDirectory {
  17. Audio = 1,
  18. Cache,
  19. Config,
  20. Data,
  21. LocalData,
  22. Document,
  23. Download,
  24. Picture,
  25. Public,
  26. Video,
  27. Resource,
  28. Temp,
  29. AppConfig,
  30. AppData,
  31. AppLocalData,
  32. AppCache,
  33. AppLog,
  34. Desktop,
  35. Executable,
  36. Font,
  37. Home,
  38. Runtime,
  39. Template
  40. }
  41. /**
  42. * Returns the path to the suggested directory for your app's config files.
  43. * 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`.
  44. * @example
  45. * ```typescript
  46. * import { appConfigDir } from '@tauri-apps/api/path';
  47. * const appConfigDirPath = await appConfigDir();
  48. * ```
  49. *
  50. * @since 1.2.0
  51. */
  52. async function appConfigDir(): Promise<string> {
  53. return invoke('plugin:path|resolve_directory', {
  54. directory: BaseDirectory.AppConfig
  55. })
  56. }
  57. /**
  58. * Returns the path to the suggested directory for your app's data files.
  59. * 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`.
  60. * @example
  61. * ```typescript
  62. * import { appDataDir } from '@tauri-apps/api/path';
  63. * const appDataDirPath = await appDataDir();
  64. * ```
  65. *
  66. * @since 1.2.0
  67. */
  68. async function appDataDir(): Promise<string> {
  69. return invoke('plugin:path|resolve_directory', {
  70. directory: BaseDirectory.AppData
  71. })
  72. }
  73. /**
  74. * Returns the path to the suggested directory for your app's local data files.
  75. * 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`.
  76. * @example
  77. * ```typescript
  78. * import { appLocalDataDir } from '@tauri-apps/api/path';
  79. * const appLocalDataDirPath = await appLocalDataDir();
  80. * ```
  81. *
  82. * @since 1.2.0
  83. */
  84. async function appLocalDataDir(): Promise<string> {
  85. return invoke('plugin:path|resolve_directory', {
  86. directory: BaseDirectory.AppLocalData
  87. })
  88. }
  89. /**
  90. * Returns the path to the suggested directory for your app's cache files.
  91. * 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`.
  92. * @example
  93. * ```typescript
  94. * import { appCacheDir } from '@tauri-apps/api/path';
  95. * const appCacheDirPath = await appCacheDir();
  96. * ```
  97. *
  98. * @since 1.2.0
  99. */
  100. async function appCacheDir(): Promise<string> {
  101. return invoke('plugin:path|resolve_directory', {
  102. directory: BaseDirectory.AppCache
  103. })
  104. }
  105. /**
  106. * Returns the path to the user's audio directory.
  107. *
  108. * #### Platform-specific
  109. *
  110. * - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_MUSIC_DIR`.
  111. * - **macOS:** Resolves to `$HOME/Music`.
  112. * - **Windows:** Resolves to `{FOLDERID_Music}`.
  113. * @example
  114. * ```typescript
  115. * import { audioDir } from '@tauri-apps/api/path';
  116. * const audioDirPath = await audioDir();
  117. * ```
  118. *
  119. * @since 1.0.0
  120. */
  121. async function audioDir(): Promise<string> {
  122. return invoke('plugin:path|resolve_directory', {
  123. directory: BaseDirectory.Audio
  124. })
  125. }
  126. /**
  127. * Returns the path to the user's cache directory.
  128. *
  129. * #### Platform-specific
  130. *
  131. * - **Linux:** Resolves to `$XDG_CACHE_HOME` or `$HOME/.cache`.
  132. * - **macOS:** Resolves to `$HOME/Library/Caches`.
  133. * - **Windows:** Resolves to `{FOLDERID_LocalAppData}`.
  134. * @example
  135. * ```typescript
  136. * import { cacheDir } from '@tauri-apps/api/path';
  137. * const cacheDirPath = await cacheDir();
  138. * ```
  139. *
  140. * @since 1.0.0
  141. */
  142. async function cacheDir(): Promise<string> {
  143. return invoke('plugin:path|resolve_directory', {
  144. directory: BaseDirectory.Cache
  145. })
  146. }
  147. /**
  148. * Returns the path to the user's config directory.
  149. *
  150. * #### Platform-specific
  151. *
  152. * - **Linux:** Resolves to `$XDG_CONFIG_HOME` or `$HOME/.config`.
  153. * - **macOS:** Resolves to `$HOME/Library/Application Support`.
  154. * - **Windows:** Resolves to `{FOLDERID_RoamingAppData}`.
  155. * @example
  156. * ```typescript
  157. * import { configDir } from '@tauri-apps/api/path';
  158. * const configDirPath = await configDir();
  159. * ```
  160. *
  161. * @since 1.0.0
  162. */
  163. async function configDir(): Promise<string> {
  164. return invoke('plugin:path|resolve_directory', {
  165. directory: BaseDirectory.Config
  166. })
  167. }
  168. /**
  169. * Returns the path to the user's data directory.
  170. *
  171. * #### Platform-specific
  172. *
  173. * - **Linux:** Resolves to `$XDG_DATA_HOME` or `$HOME/.local/share`.
  174. * - **macOS:** Resolves to `$HOME/Library/Application Support`.
  175. * - **Windows:** Resolves to `{FOLDERID_RoamingAppData}`.
  176. * @example
  177. * ```typescript
  178. * import { dataDir } from '@tauri-apps/api/path';
  179. * const dataDirPath = await dataDir();
  180. * ```
  181. *
  182. * @since 1.0.0
  183. */
  184. async function dataDir(): Promise<string> {
  185. return invoke('plugin:path|resolve_directory', {
  186. directory: BaseDirectory.Data
  187. })
  188. }
  189. /**
  190. * Returns the path to the user's desktop directory.
  191. *
  192. * #### Platform-specific
  193. *
  194. * - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DESKTOP_DIR`.
  195. * - **macOS:** Resolves to `$HOME/Desktop`.
  196. * - **Windows:** Resolves to `{FOLDERID_Desktop}`.
  197. * @example
  198. * ```typescript
  199. * import { desktopDir } from '@tauri-apps/api/path';
  200. * const desktopPath = await desktopDir();
  201. * ```
  202. *
  203. * @since 1.0.0
  204. */
  205. async function desktopDir(): Promise<string> {
  206. return invoke('plugin:path|resolve_directory', {
  207. directory: BaseDirectory.Desktop
  208. })
  209. }
  210. /**
  211. * Returns the path to the user's document directory.
  212. * @example
  213. * ```typescript
  214. * import { documentDir } from '@tauri-apps/api/path';
  215. * const documentDirPath = await documentDir();
  216. * ```
  217. *
  218. * #### Platform-specific
  219. *
  220. * - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DOCUMENTS_DIR`.
  221. * - **macOS:** Resolves to `$HOME/Documents`.
  222. * - **Windows:** Resolves to `{FOLDERID_Documents}`.
  223. *
  224. * @since 1.0.0
  225. */
  226. async function documentDir(): Promise<string> {
  227. return invoke('plugin:path|resolve_directory', {
  228. directory: BaseDirectory.Document
  229. })
  230. }
  231. /**
  232. * Returns the path to the user's download directory.
  233. *
  234. * #### Platform-specific
  235. *
  236. * - **Linux**: Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DOWNLOAD_DIR`.
  237. * - **macOS**: Resolves to `$HOME/Downloads`.
  238. * - **Windows**: Resolves to `{FOLDERID_Downloads}`.
  239. * @example
  240. * ```typescript
  241. * import { downloadDir } from '@tauri-apps/api/path';
  242. * const downloadDirPath = await downloadDir();
  243. * ```
  244. *
  245. * @since 1.0.0
  246. */
  247. async function downloadDir(): Promise<string> {
  248. return invoke('plugin:path|resolve_directory', {
  249. directory: BaseDirectory.Download
  250. })
  251. }
  252. /**
  253. * Returns the path to the user's executable directory.
  254. *
  255. * #### Platform-specific
  256. *
  257. * - **Linux:** Resolves to `$XDG_BIN_HOME/../bin` or `$XDG_DATA_HOME/../bin` or `$HOME/.local/bin`.
  258. * - **macOS:** Not supported.
  259. * - **Windows:** Not supported.
  260. * @example
  261. * ```typescript
  262. * import { executableDir } from '@tauri-apps/api/path';
  263. * const executableDirPath = await executableDir();
  264. * ```
  265. *
  266. * @since 1.0.0
  267. */
  268. async function executableDir(): Promise<string> {
  269. return invoke('plugin:path|resolve_directory', {
  270. directory: BaseDirectory.Executable
  271. })
  272. }
  273. /**
  274. * Returns the path to the user's font directory.
  275. *
  276. * #### Platform-specific
  277. *
  278. * - **Linux:** Resolves to `$XDG_DATA_HOME/fonts` or `$HOME/.local/share/fonts`.
  279. * - **macOS:** Resolves to `$HOME/Library/Fonts`.
  280. * - **Windows:** Not supported.
  281. * @example
  282. * ```typescript
  283. * import { fontDir } from '@tauri-apps/api/path';
  284. * const fontDirPath = await fontDir();
  285. * ```
  286. *
  287. * @since 1.0.0
  288. */
  289. async function fontDir(): Promise<string> {
  290. return invoke('plugin:path|resolve_directory', {
  291. directory: BaseDirectory.Font
  292. })
  293. }
  294. /**
  295. * Returns the path to the user's home directory.
  296. *
  297. * #### Platform-specific
  298. *
  299. * - **Linux:** Resolves to `$HOME`.
  300. * - **macOS:** Resolves to `$HOME`.
  301. * - **Windows:** Resolves to `{FOLDERID_Profile}`.
  302. * @example
  303. * ```typescript
  304. * import { homeDir } from '@tauri-apps/api/path';
  305. * const homeDirPath = await homeDir();
  306. * ```
  307. *
  308. * @since 1.0.0
  309. */
  310. async function homeDir(): Promise<string> {
  311. return invoke('plugin:path|resolve_directory', {
  312. directory: BaseDirectory.Home
  313. })
  314. }
  315. /**
  316. * Returns the path to the user's local data directory.
  317. *
  318. * #### Platform-specific
  319. *
  320. * - **Linux:** Resolves to `$XDG_DATA_HOME` or `$HOME/.local/share`.
  321. * - **macOS:** Resolves to `$HOME/Library/Application Support`.
  322. * - **Windows:** Resolves to `{FOLDERID_LocalAppData}`.
  323. * @example
  324. * ```typescript
  325. * import { localDataDir } from '@tauri-apps/api/path';
  326. * const localDataDirPath = await localDataDir();
  327. * ```
  328. *
  329. * @since 1.0.0
  330. */
  331. async function localDataDir(): Promise<string> {
  332. return invoke('plugin:path|resolve_directory', {
  333. directory: BaseDirectory.LocalData
  334. })
  335. }
  336. /**
  337. * Returns the path to the user's picture directory.
  338. *
  339. * #### Platform-specific
  340. *
  341. * - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_PICTURES_DIR`.
  342. * - **macOS:** Resolves to `$HOME/Pictures`.
  343. * - **Windows:** Resolves to `{FOLDERID_Pictures}`.
  344. * @example
  345. * ```typescript
  346. * import { pictureDir } from '@tauri-apps/api/path';
  347. * const pictureDirPath = await pictureDir();
  348. * ```
  349. *
  350. * @since 1.0.0
  351. */
  352. async function pictureDir(): Promise<string> {
  353. return invoke('plugin:path|resolve_directory', {
  354. directory: BaseDirectory.Picture
  355. })
  356. }
  357. /**
  358. * Returns the path to the user's public directory.
  359. *
  360. * #### Platform-specific
  361. *
  362. * - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_PUBLICSHARE_DIR`.
  363. * - **macOS:** Resolves to `$HOME/Public`.
  364. * - **Windows:** Resolves to `{FOLDERID_Public}`.
  365. * @example
  366. * ```typescript
  367. * import { publicDir } from '@tauri-apps/api/path';
  368. * const publicDirPath = await publicDir();
  369. * ```
  370. *
  371. * @since 1.0.0
  372. */
  373. async function publicDir(): Promise<string> {
  374. return invoke('plugin:path|resolve_directory', {
  375. directory: BaseDirectory.Public
  376. })
  377. }
  378. /**
  379. * Returns the path to the application's resource directory.
  380. * To resolve a resource path, see the [[resolveResource | `resolveResource API`]].
  381. * @example
  382. * ```typescript
  383. * import { resourceDir } from '@tauri-apps/api/path';
  384. * const resourceDirPath = await resourceDir();
  385. * ```
  386. *
  387. * @since 1.0.0
  388. */
  389. async function resourceDir(): Promise<string> {
  390. return invoke('plugin:path|resolve_directory', {
  391. directory: BaseDirectory.Resource
  392. })
  393. }
  394. /**
  395. * Resolve the path to a resource file.
  396. * @example
  397. * ```typescript
  398. * import { resolveResource } from '@tauri-apps/api/path';
  399. * const resourcePath = await resolveResource('script.sh');
  400. * ```
  401. *
  402. * @param resourcePath The path to the resource.
  403. * Must follow the same syntax as defined in `tauri.conf.json > bundle > resources`, i.e. keeping subfolders and parent dir components (`../`).
  404. * @returns The full path to the resource.
  405. *
  406. * @since 1.0.0
  407. */
  408. async function resolveResource(resourcePath: string): Promise<string> {
  409. return invoke('plugin:path|resolve_directory', {
  410. directory: BaseDirectory.Resource,
  411. path: resourcePath
  412. })
  413. }
  414. /**
  415. * Returns the path to the user's runtime directory.
  416. *
  417. * #### Platform-specific
  418. *
  419. * - **Linux:** Resolves to `$XDG_RUNTIME_DIR`.
  420. * - **macOS:** Not supported.
  421. * - **Windows:** Not supported.
  422. * @example
  423. * ```typescript
  424. * import { runtimeDir } from '@tauri-apps/api/path';
  425. * const runtimeDirPath = await runtimeDir();
  426. * ```
  427. *
  428. * @since 1.0.0
  429. */
  430. async function runtimeDir(): Promise<string> {
  431. return invoke('plugin:path|resolve_directory', {
  432. directory: BaseDirectory.Runtime
  433. })
  434. }
  435. /**
  436. * Returns the path to the user's template directory.
  437. *
  438. * #### Platform-specific
  439. *
  440. * - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_TEMPLATES_DIR`.
  441. * - **macOS:** Not supported.
  442. * - **Windows:** Resolves to `{FOLDERID_Templates}`.
  443. * @example
  444. * ```typescript
  445. * import { templateDir } from '@tauri-apps/api/path';
  446. * const templateDirPath = await templateDir();
  447. * ```
  448. *
  449. * @since 1.0.0
  450. */
  451. async function templateDir(): Promise<string> {
  452. return invoke('plugin:path|resolve_directory', {
  453. directory: BaseDirectory.Template
  454. })
  455. }
  456. /**
  457. * Returns the path to the user's video directory.
  458. *
  459. * #### Platform-specific
  460. *
  461. * - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_VIDEOS_DIR`.
  462. * - **macOS:** Resolves to `$HOME/Movies`.
  463. * - **Windows:** Resolves to `{FOLDERID_Videos}`.
  464. * @example
  465. * ```typescript
  466. * import { videoDir } from '@tauri-apps/api/path';
  467. * const videoDirPath = await videoDir();
  468. * ```
  469. *
  470. * @since 1.0.0
  471. */
  472. async function videoDir(): Promise<string> {
  473. return invoke('plugin:path|resolve_directory', {
  474. directory: BaseDirectory.Video
  475. })
  476. }
  477. /**
  478. * Returns the path to the suggested directory for your app's log files.
  479. *
  480. * #### Platform-specific
  481. *
  482. * - **Linux:** Resolves to `${configDir}/${bundleIdentifier}/logs`.
  483. * - **macOS:** Resolves to `${homeDir}/Library/Logs/{bundleIdentifier}`
  484. * - **Windows:** Resolves to `${configDir}/${bundleIdentifier}/logs`.
  485. * @example
  486. * ```typescript
  487. * import { appLogDir } from '@tauri-apps/api/path';
  488. * const appLogDirPath = await appLogDir();
  489. * ```
  490. *
  491. * @since 1.2.0
  492. */
  493. async function appLogDir(): Promise<string> {
  494. return invoke('plugin:path|resolve_directory', {
  495. directory: BaseDirectory.AppLog
  496. })
  497. }
  498. /**
  499. * Returns a temporary directory.
  500. * @example
  501. * ```typescript
  502. * import { tempDir } from '@tauri-apps/api/path';
  503. * const temp = await tempDir();
  504. * ```
  505. *
  506. * @since 2.0.0
  507. */
  508. async function tempDir(): Promise<string> {
  509. return invoke('plugin:path|resolve_directory', {
  510. directory: BaseDirectory.Temp
  511. })
  512. }
  513. /**
  514. * Returns the platform-specific path segment separator:
  515. * - `\` on Windows
  516. * - `/` on POSIX
  517. *
  518. * @since 2.0.0
  519. */
  520. function sep(): string {
  521. return window.__TAURI_INTERNALS__.plugins.path.sep
  522. }
  523. /**
  524. * Returns the platform-specific path segment delimiter:
  525. * - `;` on Windows
  526. * - `:` on POSIX
  527. *
  528. * @since 2.0.0
  529. */
  530. function delimiter(): string {
  531. return window.__TAURI_INTERNALS__.plugins.path.delimiter
  532. }
  533. /**
  534. * Resolves a sequence of `paths` or `path` segments into an absolute path.
  535. * @example
  536. * ```typescript
  537. * import { resolve, appDataDir } from '@tauri-apps/api/path';
  538. * const appDataDirPath = await appDataDir();
  539. * const path = await resolve(appDataDirPath, '..', 'users', 'tauri', 'avatar.png');
  540. * ```
  541. *
  542. * @since 1.0.0
  543. */
  544. async function resolve(...paths: string[]): Promise<string> {
  545. return invoke('plugin:path|resolve', { paths })
  546. }
  547. /**
  548. * Normalizes the given `path`, resolving `'..'` and `'.'` segments and resolve symbolic links.
  549. * @example
  550. * ```typescript
  551. * import { normalize, appDataDir } from '@tauri-apps/api/path';
  552. * const appDataDirPath = await appDataDir();
  553. * const path = await normalize(`${appDataDirPath}/../users/tauri/avatar.png`);
  554. * ```
  555. *
  556. * @since 1.0.0
  557. */
  558. async function normalize(path: string): Promise<string> {
  559. return invoke('plugin:path|normalize', { path })
  560. }
  561. /**
  562. * Joins all given `path` segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.
  563. * @example
  564. * ```typescript
  565. * import { join, appDataDir } from '@tauri-apps/api/path';
  566. * const appDataDirPath = await appDataDir();
  567. * const path = await join(appDataDirPath, 'users', 'tauri', 'avatar.png');
  568. * ```
  569. *
  570. * @since 1.0.0
  571. */
  572. async function join(...paths: string[]): Promise<string> {
  573. return invoke('plugin:path|join', { paths })
  574. }
  575. /**
  576. * Returns the directory name of a `path`. Trailing directory separators are ignored.
  577. * @example
  578. * ```typescript
  579. * import { dirname } from '@tauri-apps/api/path';
  580. * const dir = await dirname('/path/to/somedir/');
  581. * assert(dir === 'somedir');
  582. * ```
  583. *
  584. * @since 1.0.0
  585. */
  586. async function dirname(path: string): Promise<string> {
  587. return invoke('plugin:path|dirname', { path })
  588. }
  589. /**
  590. * Returns the extension of the `path`.
  591. * @example
  592. * ```typescript
  593. * import { extname } from '@tauri-apps/api/path';
  594. * const ext = await extname('/path/to/file.html');
  595. * assert(ext === 'html');
  596. * ```
  597. *
  598. * @since 1.0.0
  599. */
  600. async function extname(path: string): Promise<string> {
  601. return invoke('plugin:path|extname', { path })
  602. }
  603. /**
  604. * Returns the last portion of a `path`. Trailing directory separators are ignored.
  605. * @example
  606. * ```typescript
  607. * import { basename } from '@tauri-apps/api/path';
  608. * const base = await basename('path/to/app.conf');
  609. * assert(base === 'app.conf');
  610. * ```
  611. * @param ext An optional file extension to be removed from the returned path.
  612. *
  613. * @since 1.0.0
  614. */
  615. async function basename(path: string, ext?: string): Promise<string> {
  616. return invoke('plugin:path|basename', { path, ext })
  617. }
  618. /**
  619. * Returns whether the path is absolute or not.
  620. * @example
  621. * ```typescript
  622. * import { isAbsolute } from '@tauri-apps/api/path';
  623. * assert(await isAbsolute('/home/tauri'));
  624. * ```
  625. *
  626. * @since 1.0.0
  627. */
  628. async function isAbsolute(path: string): Promise<boolean> {
  629. return invoke('plugin:path|isAbsolute', { path })
  630. }
  631. export {
  632. BaseDirectory,
  633. appConfigDir,
  634. appDataDir,
  635. appLocalDataDir,
  636. appCacheDir,
  637. appLogDir,
  638. audioDir,
  639. cacheDir,
  640. configDir,
  641. dataDir,
  642. desktopDir,
  643. documentDir,
  644. downloadDir,
  645. executableDir,
  646. fontDir,
  647. homeDir,
  648. localDataDir,
  649. pictureDir,
  650. publicDir,
  651. resourceDir,
  652. resolveResource,
  653. runtimeDir,
  654. templateDir,
  655. videoDir,
  656. sep,
  657. delimiter,
  658. resolve,
  659. normalize,
  660. join,
  661. dirname,
  662. extname,
  663. basename,
  664. isAbsolute,
  665. tempDir
  666. }