init
This commit is contained in:
commit
42ef2f9674
468 files changed
+645161
No files matched your search
+589
@@ -0,0 +1,589 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
declare enum BaseDirectory {
|
||||
/**
|
||||
* @see {@link audioDir} for more information.
|
||||
*/
|
||||
Audio = 1,
|
||||
/**
|
||||
* @see {@link cacheDir} for more information.
|
||||
*/
|
||||
Cache = 2,
|
||||
/**
|
||||
* @see {@link configDir} for more information.
|
||||
*/
|
||||
Config = 3,
|
||||
/**
|
||||
* @see {@link dataDir} for more information.
|
||||
*/
|
||||
Data = 4,
|
||||
/**
|
||||
* @see {@link localDataDir} for more information.
|
||||
*/
|
||||
LocalData = 5,
|
||||
/**
|
||||
* @see {@link documentDir} for more information.
|
||||
*/
|
||||
Document = 6,
|
||||
/**
|
||||
* @see {@link downloadDir} for more information.
|
||||
*/
|
||||
Download = 7,
|
||||
/**
|
||||
* @see {@link pictureDir} for more information.
|
||||
*/
|
||||
Picture = 8,
|
||||
/**
|
||||
* @see {@link publicDir} for more information.
|
||||
*/
|
||||
Public = 9,
|
||||
/**
|
||||
* @see {@link videoDir} for more information.
|
||||
*/
|
||||
Video = 10,
|
||||
/**
|
||||
* @see {@link resourceDir} for more information.
|
||||
*/
|
||||
Resource = 11,
|
||||
/**
|
||||
* @see {@link tempDir} for more information.
|
||||
*/
|
||||
Temp = 12,
|
||||
/**
|
||||
* @see {@link appConfigDir} for more information.
|
||||
*/
|
||||
AppConfig = 13,
|
||||
/**
|
||||
* @see {@link appDataDir} for more information.
|
||||
*/
|
||||
AppData = 14,
|
||||
/**
|
||||
* @see {@link appLocalDataDir} for more information.
|
||||
*/
|
||||
AppLocalData = 15,
|
||||
/**
|
||||
* @see {@link appCacheDir} for more information.
|
||||
*/
|
||||
AppCache = 16,
|
||||
/**
|
||||
* @see {@link appLogDir} for more information.
|
||||
*/
|
||||
AppLog = 17,
|
||||
/**
|
||||
* @see {@link desktopDir} for more information.
|
||||
*/
|
||||
Desktop = 18,
|
||||
/**
|
||||
* @see {@link executableDir} for more information.
|
||||
*/
|
||||
Executable = 19,
|
||||
/**
|
||||
* @see {@link fontDir} for more information.
|
||||
*/
|
||||
Font = 20,
|
||||
/**
|
||||
* @see {@link homeDir} for more information.
|
||||
*/
|
||||
Home = 21,
|
||||
/**
|
||||
* @see {@link runtimeDir} for more information.
|
||||
*/
|
||||
Runtime = 22,
|
||||
/**
|
||||
* @see {@link templateDir} for more information.
|
||||
*/
|
||||
Template = 23
|
||||
}
|
||||
/**
|
||||
* Returns the path to the suggested directory for your app's config files.
|
||||
* Resolves to `${configDir}/${bundleIdentifier}`, where `bundleIdentifier` is the [`identifier`](https://v2.tauri.app/reference/config/#identifier) value configured in `tauri.conf.json`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { appConfigDir } from '@tauri-apps/api/path';
|
||||
* const appConfigDirPath = await appConfigDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.2.0
|
||||
*/
|
||||
declare function appConfigDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the suggested directory for your app's data files.
|
||||
* Resolves to `${dataDir}/${bundleIdentifier}`, where `bundleIdentifier` is the [`identifier`](https://v2.tauri.app/reference/config/#identifier) value configured in `tauri.conf.json`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { appDataDir } from '@tauri-apps/api/path';
|
||||
* const appDataDirPath = await appDataDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.2.0
|
||||
*/
|
||||
declare function appDataDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the suggested directory for your app's local data files.
|
||||
* Resolves to `${localDataDir}/${bundleIdentifier}`, where `bundleIdentifier` is the [`identifier`](https://v2.tauri.app/reference/config/#identifier) value configured in `tauri.conf.json`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { appLocalDataDir } from '@tauri-apps/api/path';
|
||||
* const appLocalDataDirPath = await appLocalDataDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.2.0
|
||||
*/
|
||||
declare function appLocalDataDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the suggested directory for your app's cache files.
|
||||
* Resolves to `${cacheDir}/${bundleIdentifier}`, where `bundleIdentifier` is the [`identifier`](https://v2.tauri.app/reference/config/#identifier) value configured in `tauri.conf.json`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { appCacheDir } from '@tauri-apps/api/path';
|
||||
* const appCacheDirPath = await appCacheDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.2.0
|
||||
*/
|
||||
declare function appCacheDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's audio directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_MUSIC_DIR`.
|
||||
* - **macOS:** Resolves to `$HOME/Music`.
|
||||
* - **Windows:** Resolves to `{FOLDERID_Music}`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { audioDir } from '@tauri-apps/api/path';
|
||||
* const audioDirPath = await audioDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function audioDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's cache directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to `$XDG_CACHE_HOME` or `$HOME/.cache`.
|
||||
* - **macOS:** Resolves to `$HOME/Library/Caches`.
|
||||
* - **Windows:** Resolves to `{FOLDERID_LocalAppData}`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { cacheDir } from '@tauri-apps/api/path';
|
||||
* const cacheDirPath = await cacheDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function cacheDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's config directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to `$XDG_CONFIG_HOME` or `$HOME/.config`.
|
||||
* - **macOS:** Resolves to `$HOME/Library/Application Support`.
|
||||
* - **Windows:** Resolves to `{FOLDERID_RoamingAppData}`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { configDir } from '@tauri-apps/api/path';
|
||||
* const configDirPath = await configDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function configDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's data directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to `$XDG_DATA_HOME` or `$HOME/.local/share`.
|
||||
* - **macOS:** Resolves to `$HOME/Library/Application Support`.
|
||||
* - **Windows:** Resolves to `{FOLDERID_RoamingAppData}`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { dataDir } from '@tauri-apps/api/path';
|
||||
* const dataDirPath = await dataDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function dataDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's desktop directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DESKTOP_DIR`.
|
||||
* - **macOS:** Resolves to `$HOME/Desktop`.
|
||||
* - **Windows:** Resolves to `{FOLDERID_Desktop}`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { desktopDir } from '@tauri-apps/api/path';
|
||||
* const desktopPath = await desktopDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function desktopDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's document directory.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { documentDir } from '@tauri-apps/api/path';
|
||||
* const documentDirPath = await documentDir();
|
||||
* ```
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DOCUMENTS_DIR`.
|
||||
* - **macOS:** Resolves to `$HOME/Documents`.
|
||||
* - **Windows:** Resolves to `{FOLDERID_Documents}`.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function documentDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's download directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux**: Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DOWNLOAD_DIR`.
|
||||
* - **macOS**: Resolves to `$HOME/Downloads`.
|
||||
* - **Windows**: Resolves to `{FOLDERID_Downloads}`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { downloadDir } from '@tauri-apps/api/path';
|
||||
* const downloadDirPath = await downloadDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function downloadDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's executable directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to `$XDG_BIN_HOME/../bin` or `$XDG_DATA_HOME/../bin` or `$HOME/.local/bin`.
|
||||
* - **macOS:** Not supported.
|
||||
* - **Windows:** Not supported.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { executableDir } from '@tauri-apps/api/path';
|
||||
* const executableDirPath = await executableDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function executableDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's font directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to `$XDG_DATA_HOME/fonts` or `$HOME/.local/share/fonts`.
|
||||
* - **macOS:** Resolves to `$HOME/Library/Fonts`.
|
||||
* - **Windows:** Not supported.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { fontDir } from '@tauri-apps/api/path';
|
||||
* const fontDirPath = await fontDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function fontDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's home directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to `$HOME`.
|
||||
* - **macOS:** Resolves to `$HOME`.
|
||||
* - **Windows:** Resolves to `{FOLDERID_Profile}`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { homeDir } from '@tauri-apps/api/path';
|
||||
* const homeDirPath = await homeDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function homeDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's local data directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to `$XDG_DATA_HOME` or `$HOME/.local/share`.
|
||||
* - **macOS:** Resolves to `$HOME/Library/Application Support`.
|
||||
* - **Windows:** Resolves to `{FOLDERID_LocalAppData}`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { localDataDir } from '@tauri-apps/api/path';
|
||||
* const localDataDirPath = await localDataDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function localDataDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's picture directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_PICTURES_DIR`.
|
||||
* - **macOS:** Resolves to `$HOME/Pictures`.
|
||||
* - **Windows:** Resolves to `{FOLDERID_Pictures}`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { pictureDir } from '@tauri-apps/api/path';
|
||||
* const pictureDirPath = await pictureDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function pictureDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's public directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_PUBLICSHARE_DIR`.
|
||||
* - **macOS:** Resolves to `$HOME/Public`.
|
||||
* - **Windows:** Resolves to `{FOLDERID_Public}`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { publicDir } from '@tauri-apps/api/path';
|
||||
* const publicDirPath = await publicDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function publicDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the application's resource directory.
|
||||
* To resolve a resource path, see {@linkcode resolveResource}.
|
||||
*
|
||||
* ## Platform-specific
|
||||
*
|
||||
* Although we provide the exact path where this function resolves to,
|
||||
* this is not a contract and things might change in the future
|
||||
*
|
||||
* - **Windows:** Resolves to the directory that contains the main executable.
|
||||
* - **Linux:** When running in an AppImage, the `APPDIR` variable will be set to
|
||||
* the mounted location of the app, and the resource dir will be `${APPDIR}/usr/lib/${exe_name}`.
|
||||
* If not running in an AppImage, the path is `/usr/lib/${exe_name}`.
|
||||
* When running the app from `src-tauri/target/(debug|release)/`, the path is `${exe_dir}/../lib/${exe_name}`.
|
||||
* - **macOS:** Resolves to `${exe_dir}/../Resources` (inside .app).
|
||||
* - **iOS:** Resolves to `${exe_dir}/assets`.
|
||||
* - **Android:** Currently the resources are stored in the APK as assets so it's not a normal file system path,
|
||||
* we return a special URI prefix `asset://localhost/` here that can be used with the [file system plugin](https://tauri.app/plugin/file-system/),
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { resourceDir } from '@tauri-apps/api/path';
|
||||
* const resourceDirPath = await resourceDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function resourceDir(): Promise<string>;
|
||||
/**
|
||||
* Resolve the path to a resource file.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { resolveResource } from '@tauri-apps/api/path';
|
||||
* const resourcePath = await resolveResource('script.sh');
|
||||
* ```
|
||||
*
|
||||
* @param resourcePath The path to the resource.
|
||||
* Must follow the same syntax as defined in `tauri.conf.json > bundle > resources`, i.e. keeping subfolders and parent dir components (`../`).
|
||||
* @returns The full path to the resource.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function resolveResource(resourcePath: string): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's runtime directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to `$XDG_RUNTIME_DIR`.
|
||||
* - **macOS:** Not supported.
|
||||
* - **Windows:** Not supported.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { runtimeDir } from '@tauri-apps/api/path';
|
||||
* const runtimeDirPath = await runtimeDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function runtimeDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's template directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_TEMPLATES_DIR`.
|
||||
* - **macOS:** Not supported.
|
||||
* - **Windows:** Resolves to `{FOLDERID_Templates}`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { templateDir } from '@tauri-apps/api/path';
|
||||
* const templateDirPath = await templateDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function templateDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the user's video directory.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_VIDEOS_DIR`.
|
||||
* - **macOS:** Resolves to `$HOME/Movies`.
|
||||
* - **Windows:** Resolves to `{FOLDERID_Videos}`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { videoDir } from '@tauri-apps/api/path';
|
||||
* const videoDirPath = await videoDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function videoDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the path to the suggested directory for your app's log files.
|
||||
*
|
||||
* #### Platform-specific
|
||||
*
|
||||
* - **Linux:** Resolves to `${configDir}/${bundleIdentifier}/logs`.
|
||||
* - **macOS:** Resolves to `${homeDir}/Library/Logs/{bundleIdentifier}`
|
||||
* - **Windows:** Resolves to `${configDir}/${bundleIdentifier}/logs`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { appLogDir } from '@tauri-apps/api/path';
|
||||
* const appLogDirPath = await appLogDir();
|
||||
* ```
|
||||
*
|
||||
* @since 1.2.0
|
||||
*/
|
||||
declare function appLogDir(): Promise<string>;
|
||||
/**
|
||||
* Returns a temporary directory.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { tempDir } from '@tauri-apps/api/path';
|
||||
* const temp = await tempDir();
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
declare function tempDir(): Promise<string>;
|
||||
/**
|
||||
* Returns the platform-specific path segment separator:
|
||||
* - `\` on Windows
|
||||
* - `/` on POSIX
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
declare function sep(): string;
|
||||
/**
|
||||
* Returns the platform-specific path segment delimiter:
|
||||
* - `;` on Windows
|
||||
* - `:` on POSIX
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
declare function delimiter(): string;
|
||||
/**
|
||||
* Resolves a sequence of `paths` or `path` segments into an absolute path.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { resolve, appDataDir } from '@tauri-apps/api/path';
|
||||
* const appDataDirPath = await appDataDir();
|
||||
* const path = await resolve(appDataDirPath, '..', 'users', 'tauri', 'avatar.png');
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function resolve(...paths: string[]): Promise<string>;
|
||||
/**
|
||||
* Normalizes the given `path`, resolving `'..'` and `'.'` segments and resolve symbolic links.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { normalize, appDataDir } from '@tauri-apps/api/path';
|
||||
* const appDataDirPath = await appDataDir();
|
||||
* const path = await normalize(`${appDataDirPath}/../users/tauri/avatar.png`);
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function normalize(path: string): Promise<string>;
|
||||
/**
|
||||
* Joins all given `path` segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { join, appDataDir } from '@tauri-apps/api/path';
|
||||
* const appDataDirPath = await appDataDir();
|
||||
* const path = await join(appDataDirPath, 'users', 'tauri', 'avatar.png');
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function join(...paths: string[]): Promise<string>;
|
||||
/**
|
||||
* Returns the parent directory of a given `path`. Trailing directory separators are ignored.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { dirname } from '@tauri-apps/api/path';
|
||||
* const dir = await dirname('/path/to/somedir/');
|
||||
* assert(dir === '/path/to');
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function dirname(path: string): Promise<string>;
|
||||
/**
|
||||
* Returns the extension of the `path`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { extname } from '@tauri-apps/api/path';
|
||||
* const ext = await extname('/path/to/file.html');
|
||||
* assert(ext === 'html');
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function extname(path: string): Promise<string>;
|
||||
/**
|
||||
* Returns the last portion of a `path`. Trailing directory separators are ignored.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { basename } from '@tauri-apps/api/path';
|
||||
* const base = await basename('path/to/app.conf');
|
||||
* assert(base === 'app.conf');
|
||||
* ```
|
||||
* @param ext An optional file extension to be removed from the returned path.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function basename(path: string, ext?: string): Promise<string>;
|
||||
/**
|
||||
* Returns whether the path is absolute or not.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { isAbsolute } from '@tauri-apps/api/path';
|
||||
* assert(await isAbsolute('/home/tauri'));
|
||||
* ```
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
declare function isAbsolute(path: string): Promise<boolean>;
|
||||
export { BaseDirectory, appConfigDir, appDataDir, appLocalDataDir, appCacheDir, appLogDir, audioDir, cacheDir, configDir, dataDir, desktopDir, documentDir, downloadDir, executableDir, fontDir, homeDir, localDataDir, pictureDir, publicDir, resourceDir, resolveResource, runtimeDir, templateDir, videoDir, sep, delimiter, resolve, normalize, join, dirname, extname, basename, isAbsolute, tempDir };
|
||||
+361
@@ -0,0 +1,361 @@
|
||||
'use strict';
|
||||
|
||||
const scan = require('./scan');
|
||||
const parse = require('./parse');
|
||||
const utils = require('./utils');
|
||||
const constants = require('./constants');
|
||||
const isObject = val => val && typeof val === 'object' && !Array.isArray(val);
|
||||
|
||||
/**
|
||||
* Creates a matcher function from one or more glob patterns. The
|
||||
* returned function takes a string to match as its first argument,
|
||||
* and returns true if the string is a match. The returned matcher
|
||||
* function also takes a boolean as the second argument that, when true,
|
||||
* returns an object with additional information.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* // picomatch(glob[, options]);
|
||||
*
|
||||
* const isMatch = picomatch('*.!(*a)');
|
||||
* console.log(isMatch('a.a')); //=> false
|
||||
* console.log(isMatch('a.b')); //=> true
|
||||
*
|
||||
* // For environments without `node.js`, `picomatch/posix` provides you a dependency-free matcher, without automatic OS detection.
|
||||
* const picomatch = require('picomatch/posix');
|
||||
* // the same API, defaulting to posix paths
|
||||
* const isMatch = picomatch('a/*');
|
||||
* console.log(isMatch('a\\b')); //=> false
|
||||
* console.log(isMatch('a/b')); //=> true
|
||||
*
|
||||
* // you can still configure the matcher function to accept windows paths
|
||||
* const isMatch = picomatch('a/*', { options: windows });
|
||||
* console.log(isMatch('a\\b')); //=> true
|
||||
* console.log(isMatch('a/b')); //=> true
|
||||
* ```
|
||||
* @name picomatch
|
||||
* @param {String|Array} `globs` One or more glob patterns.
|
||||
* @param {Object=} `options`
|
||||
* @return {Function=} Returns a matcher function.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
const picomatch = (glob, options, returnState = false) => {
|
||||
if (Array.isArray(glob)) {
|
||||
const fns = glob.map(input => picomatch(input, options, returnState));
|
||||
const arrayMatcher = str => {
|
||||
for (const isMatch of fns) {
|
||||
const state = isMatch(str);
|
||||
if (state) return state;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
return arrayMatcher;
|
||||
}
|
||||
|
||||
const isState = isObject(glob) && glob.tokens && glob.input;
|
||||
|
||||
if (glob === '' || (typeof glob !== 'string' && !isState)) {
|
||||
throw new TypeError('Expected pattern to be a non-empty string');
|
||||
}
|
||||
|
||||
const opts = options || {};
|
||||
const posix = opts.windows;
|
||||
const regex = isState
|
||||
? picomatch.compileRe(glob, options)
|
||||
: picomatch.makeRe(glob, options, false, true);
|
||||
|
||||
const state = regex.state;
|
||||
delete regex.state;
|
||||
|
||||
let isIgnored = () => false;
|
||||
if (opts.ignore) {
|
||||
const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
|
||||
isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
|
||||
}
|
||||
|
||||
const matcher = (input, returnObject = false) => {
|
||||
const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
|
||||
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
||||
|
||||
if (typeof opts.onResult === 'function') {
|
||||
opts.onResult(result);
|
||||
}
|
||||
|
||||
if (isMatch === false) {
|
||||
result.isMatch = false;
|
||||
return returnObject ? result : false;
|
||||
}
|
||||
|
||||
if (isIgnored(input)) {
|
||||
if (typeof opts.onIgnore === 'function') {
|
||||
opts.onIgnore(result);
|
||||
}
|
||||
result.isMatch = false;
|
||||
return returnObject ? result : false;
|
||||
}
|
||||
|
||||
if (typeof opts.onMatch === 'function') {
|
||||
opts.onMatch(result);
|
||||
}
|
||||
return returnObject ? result : true;
|
||||
};
|
||||
|
||||
if (returnState) {
|
||||
matcher.state = state;
|
||||
}
|
||||
|
||||
return matcher;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test `input` with the given `regex`. This is used by the main
|
||||
* `picomatch()` function to test the input string.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* // picomatch.test(input, regex[, options]);
|
||||
*
|
||||
* console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
|
||||
* // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
|
||||
* ```
|
||||
* @param {String} `input` String to test.
|
||||
* @param {RegExp} `regex`
|
||||
* @return {Object} Returns an object with matching info.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.test = (input, regex, options, { glob, posix } = {}) => {
|
||||
if (typeof input !== 'string') {
|
||||
throw new TypeError('Expected input to be a string');
|
||||
}
|
||||
|
||||
if (input === '') {
|
||||
return { isMatch: false, output: '' };
|
||||
}
|
||||
|
||||
const opts = options || {};
|
||||
const format = opts.format || (posix ? utils.toPosixSlashes : null);
|
||||
let match = input === glob;
|
||||
let output = (match && format) ? format(input) : input;
|
||||
|
||||
if (match === false) {
|
||||
output = format ? format(input) : input;
|
||||
match = output === glob;
|
||||
}
|
||||
|
||||
if (match === false || opts.capture === true) {
|
||||
if (opts.matchBase === true || opts.basename === true) {
|
||||
match = picomatch.matchBase(input, regex, options, posix);
|
||||
} else {
|
||||
match = regex.exec(output);
|
||||
}
|
||||
}
|
||||
|
||||
return { isMatch: Boolean(match), match, output };
|
||||
};
|
||||
|
||||
/**
|
||||
* Match the basename of a filepath.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* // picomatch.matchBase(input, glob[, options]);
|
||||
* console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
|
||||
* ```
|
||||
* @param {String} `input` String to test.
|
||||
* @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.matchBase = (input, glob, options, posix = options && options.windows) => {
|
||||
const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
|
||||
return regex.test(utils.basename(input, { windows: posix }));
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if **any** of the given glob `patterns` match the specified `string`.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* // picomatch.isMatch(string, patterns[, options]);
|
||||
*
|
||||
* console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
|
||||
* console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
|
||||
* ```
|
||||
* @param {String|Array} str The string to test.
|
||||
* @param {String|Array} patterns One or more glob patterns to use for matching.
|
||||
* @param {Object} [options] See available [options](#options).
|
||||
* @return {Boolean} Returns true if any patterns match `str`
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
|
||||
|
||||
/**
|
||||
* Parse a glob pattern to create the source string for a regular
|
||||
* expression.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* const result = picomatch.parse(pattern[, options]);
|
||||
* ```
|
||||
* @param {String} `pattern`
|
||||
* @param {Object} `options`
|
||||
* @return {Object} Returns an object with useful properties and output to be used as a regex source string.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.parse = (pattern, options) => {
|
||||
if (Array.isArray(pattern)) return pattern.map(p => picomatch.parse(p, options));
|
||||
return parse(pattern, { ...options, fastpaths: false });
|
||||
};
|
||||
|
||||
/**
|
||||
* Scan a glob pattern to separate the pattern into segments.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* // picomatch.scan(input[, options]);
|
||||
*
|
||||
* const result = picomatch.scan('!./foo/*.js');
|
||||
* console.log(result);
|
||||
* { prefix: '!./',
|
||||
* input: '!./foo/*.js',
|
||||
* start: 3,
|
||||
* base: 'foo',
|
||||
* glob: '*.js',
|
||||
* isBrace: false,
|
||||
* isBracket: false,
|
||||
* isGlob: true,
|
||||
* isExtglob: false,
|
||||
* isGlobstar: false,
|
||||
* negated: true }
|
||||
* ```
|
||||
* @param {String} `input` Glob pattern to scan.
|
||||
* @param {Object} `options`
|
||||
* @return {Object} Returns an object with
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.scan = (input, options) => scan(input, options);
|
||||
|
||||
/**
|
||||
* Compile a regular expression from the `state` object returned by the
|
||||
* [parse()](#parse) method.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* const state = picomatch.parse('*.js');
|
||||
* // picomatch.compileRe(state[, options]);
|
||||
*
|
||||
* console.log(picomatch.compileRe(state));
|
||||
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
||||
* ```
|
||||
* @param {Object} `state`
|
||||
* @param {Object} `options`
|
||||
* @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
|
||||
* @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
|
||||
* @return {RegExp}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
||||
if (returnOutput === true) {
|
||||
return state.output;
|
||||
}
|
||||
|
||||
const opts = options || {};
|
||||
const prepend = opts.contains ? '' : '^';
|
||||
const append = opts.contains ? '' : '$';
|
||||
|
||||
let source = `${prepend}(?:${state.output})${append}`;
|
||||
if (state && state.negated === true) {
|
||||
source = `^(?!${source}).*$`;
|
||||
}
|
||||
|
||||
const regex = picomatch.toRegex(source, options);
|
||||
if (returnState === true) {
|
||||
regex.state = state;
|
||||
}
|
||||
|
||||
return regex;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a regular expression from a parsed glob pattern.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* // picomatch.makeRe(state[, options]);
|
||||
*
|
||||
* const result = picomatch.makeRe('*.js');
|
||||
* console.log(result);
|
||||
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
||||
* ```
|
||||
* @param {String} `state` The object returned from the `.parse` method.
|
||||
* @param {Object} `options`
|
||||
* @param {Boolean} `returnOutput` Implementors may use this argument to return the compiled output, instead of a regular expression. This is not exposed on the options to prevent end-users from mutating the result.
|
||||
* @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
|
||||
* @return {RegExp} Returns a regex created from the given pattern.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
||||
if (!input || typeof input !== 'string') {
|
||||
throw new TypeError('Expected a non-empty string');
|
||||
}
|
||||
|
||||
let parsed = { negated: false, fastpaths: true };
|
||||
|
||||
if (options.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
|
||||
parsed.output = parse.fastpaths(input, options);
|
||||
}
|
||||
|
||||
if (!parsed.output) {
|
||||
parsed = parse(input, options);
|
||||
}
|
||||
|
||||
return picomatch.compileRe(parsed, options, returnOutput, returnState);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a regular expression from the given regex source string.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* // picomatch.toRegex(source[, options]);
|
||||
*
|
||||
* const { output } = picomatch.parse('*.js');
|
||||
* console.log(picomatch.toRegex(output));
|
||||
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
||||
* ```
|
||||
* @param {String} `source` Regular expression source string.
|
||||
* @param {Object} `options`
|
||||
* @return {RegExp}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.toRegex = (source, options) => {
|
||||
try {
|
||||
const opts = options || {};
|
||||
return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
|
||||
} catch (err) {
|
||||
if (options && options.debug === true) throw err;
|
||||
return /$^/;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Picomatch constants.
|
||||
* @return {Object}
|
||||
*/
|
||||
|
||||
picomatch.constants = constants;
|
||||
|
||||
/**
|
||||
* Expose "picomatch"
|
||||
*/
|
||||
|
||||
module.exports = picomatch;
|
||||
Reference in new issue
Block a user