mahler
Version:
A automated task composer and HTN based planner for building autonomous system agents
44 lines (43 loc) • 1.3 kB
TypeScript
export type PathType = string;
type PathBrand = {
__brand: 'Path';
};
export type Path<T extends string[] | string = string> = T extends string[] ? `/${PathArray<T>}` & PathBrand : T extends string ? T & PathBrand : never;
export type Root = '/';
type PathArray<T extends string[]> = T extends [
infer THead extends string,
...infer TTail extends string[]
] ? PathArrayWithHead<THead, TTail> : '';
type PathArrayWithHead<H extends string, T extends string[]> = T extends [] ? H : `${H}/${PathArray<T>}`;
declare function split(p: Path): string[];
export declare class PathIsInvalid extends Error {
constructor(path: unknown);
}
declare function from<const T extends string | string[]>(p: T): Path<T>;
declare function join<T extends string | string[]>(p: Path, s: T): "/" & PathBrand;
/**
* Return the source (parent) of the path
*
* e.g.
* ```
* Path.source(Path.from('/a/b/c')) // '/a/b'
* ```
*/
declare function source(p: Path): "/" & PathBrand;
/**
* Return the path base name
*
* e.g.
* ```
* Path.basename(Path.from('/a/b/c')) // 'a'
* ```
*/
declare function basename(p: Path): string;
export declare const Path: {
from: typeof from;
split: typeof split;
join: typeof join;
source: typeof source;
basename: typeof basename;
};
export {};