@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
36 lines • 1.75 kB
TypeScript
export declare const NAME_MAX_BYTES = 255;
export declare const SAFE_SLASH = "\u2215";
export declare const ESCAPE_LEAD = "\u2044";
/** Whether the text is empty or nothing but Unicode White_Space. */
export declare function isBlank(text: string): boolean;
/** Measure a string the way the filesystem does: in UTF-8 bytes. */
export declare function byteLength(text: string): number;
/** Trim a string to fit a byte budget without splitting a character. */
export declare function truncateBytes(text: string, budget: number): string;
/** Trim trailing underscores, linearly. python's `str.rstrip("_")`. */
export declare function stripTrailingUnderscores(value: string): string;
/**
* Sanitize a name for use in virtual paths: shell-unsafe characters and
* spaces become underscores, so the name needs no quoting. Never dot-led,
* never empty (`unknown`), at most 100 characters.
*/
export declare function sanitizeName(name: string): string;
/**
* Make a name safe to embed in a VFS path segment: the original spelling,
* `/` replaced with `SAFE_SLASH` and a dot-led name led with `ESCAPE_LEAD`,
* since the hierarchy hides a dot-led segment. A blank name is `unknown`.
*/
export declare function pathSafeName(name: string): string;
/**
* Sanitize an API-supplied label for use inside a filename: as
* `sanitizeName`, but ellipsized past either budget, so a truncated name
* reads as truncated. `maxLen` is the readable length a backend wants and
* `maxBytes` what the filesystem accepts; pass the bytes the rest of the
* filename does not already use.
*/
export declare function sanitizeLabel(text: string, options: {
fallback: string;
maxLen: number;
maxBytes?: number;
}): string;
//# sourceMappingURL=sanitize.d.ts.map