path.cjs 22 KB

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