All files / packages/utils/dist index.d.mts

0% Statements 0/0
0% Branches 1/1
0% Functions 1/1
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113                                                                                                                                                                                                                                 
import { MapArray, MapTuple } from '@https-enable/types';
 
declare const isWindows: boolean;
declare function camelCase(name: string): string;
 
declare const WindowsSlashRE: RegExp;
/**
 * windows 盘符
 * @description 匹配 `x:/` 或 `x:\\` 开头的文本
 * @description 最好先将 windows下的路径转换为 posix 风格,否则由于字符串斜杠转义问题,可能会导致正则匹配失败
 */
declare const WindowsDiskRE: RegExp;
declare const ColorStringRE: RegExp;
 
interface ProjectOptions {
  /**
   * Project root directory. Can be an absolute path, or a path relative from
   * the location of the config file itself.
   * @default process.cwd()
   */
  root?: string
  /**
   * 由哪个文件导入,调用方的绝对路径
   * @description 可选,如果不传则会自动获取
   * @description 如要手动传递,则必须传入 `import.meta.url`
   * @default undefined
   */
  callerId?: string
  /**
   * 兜底未知文件作为 raw 处理
   */
  fallback?: boolean
}
 
interface ImportGlobOptions<
  Eager extends boolean,
  AsType extends string,
> {
  /**
   * Import type for the import url.
   *
   * @deprecated Use `query` instead, e.g. `as: 'url'` -> `query: '?url', import: 'default'`
   */
  as?: AsType
  /**
   * Import as static or dynamic
   *
   * @default false
   */
  eager?: Eager
  /**
   * Import only the specific named export. Set to `default` to import the default export.
   */
  import?: string
  /**
   * Custom queries
   * @deprecated 暂时没有使用场景
   */
  query?: string | Record<string, string | number | boolean>
  /**
   * Search files also inside `node_modules/` and hidden directories (e.g. `.git/`). This might have impact on performance.
   *
   * @default false
   */
  exhaustive?: boolean
}
 
interface KnownAsTypeMap {
  raw: string
  url: string
  worker: Worker
}
 
declare const importGlob: <Eager extends boolean, As extends keyof KnownAsTypeMap | string, T = As extends keyof KnownAsTypeMap ? KnownAsTypeMap[As] : unknown>(pattern: string | string[], options?: ImportGlobOptions<Eager, As> & ProjectOptions) => Promise<(Eager extends true ? true : false) extends true ? Record<string, T> : Record<string, () => Promise<T>>>;
/**
 * 将相对路径的 glob 模式转换为绝对路径的 glob 模式
 * @param glob - glob 模式(可能包含相对路径或绝对路径)
 * @param root - 根目录
 * @param importer - 导入文件路径(可选)
 * @returns 转换后的绝对路径 glob 模式
 */
declare function toAbsoluteGlob(glob: string, root: string, importer: string | undefined): string;
declare function globSafePath(path: string): string;
 
declare function slash(p: string): string;
declare function normalizePath(id: string): string;
declare function getCommonBase(globsResolved: string[]): null | string;
/**
 * 处理绝对路径
 */
declare function parseAbsolute(pathStr?: string | null): string | null | undefined;
/**
 * 获取调用方文件路径
 */
declare function getCallerPath(depth?: number): string | null;
 
interface IsStreamOptions {
    /**
     * When this option is `true`, the method returns `false` if the stream has already been closed.
     * @default true
     */
    checkOpen?: boolean;
}
declare function isStream(stream: any, { checkOpen }?: IsStreamOptions): boolean;
declare function strEnum<T extends string>(o: Array<T>): {
    [K in T]: K;
};
declare function numEnum<T extends string>(arr: Array<T>): MapArray<T>;
declare function numEnum<const T extends readonly string[]>(arr: T): MapTuple<T>;
declare function isNil(value?: any, emptyStringCheck?: boolean): boolean;
 
export { ColorStringRE, type IsStreamOptions, WindowsDiskRE, WindowsSlashRE, camelCase, getCallerPath, getCommonBase, globSafePath, importGlob, isNil, isStream, isWindows, normalizePath, numEnum, parseAbsolute, slash, strEnum, toAbsoluteGlob };