Pathtypetype Path = Brand<string, "anyfs path">;A key of a store: one or more segments joined by /, in normalization form C. Made only by parsePath.
The keys of a store: a path and a prefix, each a branded text made only by its parser, and the reasons another file system could not hold a path. A path is a relative key of segments joined by /, never an operating system's path: it has no . or .., no backslash, no control character, and it is in Unicode normalization form C, so that two spellings of one name are one path. Paths are case sensitive; a store that cannot tell two paths apart by case says so in its traits, and portabilityFindings names what a path could not be in a case-folding or Windows file system.
import { parsePath, parsePrefix, isUnder } from "./path.ts";
const p = parsePath("fleet/olympia/asset.json");
const prefix = parsePrefix("fleet");
p.kind === "ok" && prefix.kind === "ok" && isUnder(prefix.value, p.value); // truePathtypetype Path = Brand<string, "anyfs path">;A key of a store: one or more segments joined by /, in normalization form C. Made only by parsePath.
Prefixtypetype Prefix = Brand<string, "anyfs prefix">;The root or a path: what a list is asked below. Made only by parsePrefix.
MAX_SEGMENT_BYTESconstno test imports itconst MAX_SEGMENT_BYTES: 255The longest segment of a path, in UTF-8 bytes.
MAX_PATH_BYTESconstno test imports itconst MAX_PATH_BYTES: 1024The longest path, in UTF-8 bytes.
parsePathfunctionfunction parsePath(text: string): Result<Path, string>A path from text, or the reason it is not one. The text is returned in normalization form C.
ROOTconstconst ROOT: PrefixThe root of a store: the prefix of every path.
parsePrefixfunctionfunction parsePrefix(text: string): Result<Prefix, string>A prefix from text: the empty text is the root, and any other text is a path.
isUnderfunctionfunction isUnder(prefix: Prefix, path: Path): booleanWhether a path is below a prefix: every path is below the root, and a prefix is not below itself.
relativeTofunctionfunction relativeTo(prefix: Prefix, path: Path): Path | undefinedThe path below a prefix, or nothing where the path is not below it.
relativePrefixfunctionno test imports itfunction relativePrefix(base: Prefix, prefix: Prefix): Prefix | undefinedThe prefix below a base: the root where they are the same, and nothing where the prefix is not below the base.
belowfunctionno test imports itfunction below(prefix: Prefix, path: Path): Result<Path, string>A path below a prefix: the prefix, a / and the path, or why it is too long.
nameOffunctionno test imports itfunction nameOf(path: Path): stringThe last segment of a path.
parentOffunctionno test imports itfunction parentOf(path: Path): PrefixThe prefix that holds a path: the root for a path of one segment.
comparePathsfunctionfunction comparePaths(a: string, b: string): numberThe order of paths in a list: by their code points, which no locale changes and which is the order of their UTF-8 bytes.
portabilityFindingsfunctionfunction portabilityFindings(path: Path): readonly string[]What another file system could not hold in a path: one sentence for each reason, none where the path is portable.