path.ts 18 KB

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