import { type MapSameFunction } from '../value/map'; import { type DecisionFunction } from '../value/decision'; import { type ArrayOrValue } from '../array/array'; import { type FactoryWithRequiredInput } from '../getter/getter'; import { type PrimativeValue } from '../type'; import { type Maybe } from '../value/maybe.type'; import { type IndexRangeInput } from '../value/indexed'; export declare const SLASH_PATH_SEPARATOR = "/"; export declare const SLASH_PATH_FILE_TYPE_SEPARATOR = "."; export type SlashPathSeparatorString = typeof SLASH_PATH_SEPARATOR; export type SlashFileTypeSeparatorString = typeof SLASH_PATH_FILE_TYPE_SEPARATOR; export declare const DEFAULT_SLASH_PATH_ILLEGAL_CHARACTERS: string[]; /** * Default replacement character for illegal characters. */ export declare const DEFAULT_SLASH_PATH_ILLEGAL_CHARACTER_REPLACEMENT = "_"; /** * A relative folder path that does not start with a slash. */ export type RelativeSlashPathFolder = `${string}${SlashPathSeparatorString}`; /** * An absolute folder path that starts with a slash. */ export type AbsoluteSlashPathFolder = `${SlashPathSeparatorString}${string}${SlashPathSeparatorString}`; /** * A forward-slash path string. */ export type SlashPathFolder = AbsoluteSlashPathFolder | RelativeSlashPathFolder | `${SlashPathSeparatorString}`; /** * A relative folder path that is just an empty string. */ export type EmptyRelativeSlashPathFolder = ''; /** * This type includes the empty relative folder path possibility. */ export type InferredSlashPathFolder = SlashPathFolder | EmptyRelativeSlashPathFolder; /** * The file extension of a SlashPathTypedFile. * * e.g. 'png' in 'image.png' */ export type SlashPathTypedFileExtension = string; /** * The suffix of a typed file. * * e.g. '.png' in 'image.png' */ export type SlashPathTypedFileSuffix = `${SlashFileTypeSeparatorString}${SlashPathTypedFileExtension}`; /** * A SlashPath file name without a file type identifier (e.g. 'image', and not 'image.png') */ export type SlashPathUntypedFile = string; /** * A file name that contains a file type identifier (e.g. 'image.png') */ export type SlashPathTypedFile = `${string}${SlashFileTypeSeparatorString}${string}`; /** * A SlashPath file name */ export type SlashPathFile = SlashPathUntypedFile | SlashPathTypedFile; /** * A simple path made up of UTF-8 characters and slashes */ export type SlashPath = SlashPathFolder | SlashPathFile | SlashPathTypedFile; /** * A part of a slash path. * * Does not contain any slashes. */ export type SlashPathPart = string | SlashPathTypedFile; /** * Function that modifies the input SlashPath */ export type SlashPathFunction = MapSameFunction; /** * Slash path type * - folder: is a folder * - file: is a file without a type * - typedfile: is a file with a type * - invalid: is an invalid slash path that might contain multiple '.' values, or is an empty string. */ export type SlashPathType = 'folder' | 'file' | 'typedfile' | 'invalid'; /** * Determines the type of a slash path string. * * @param input - The slash path to classify. * @returns The path type classification. */ export declare function slashPathType(input: SlashPath): SlashPathType; /** * Type guard that checks if the input is a file path (typed or untyped). * * @param input - The string to check. * @returns Whether the input is a file path. */ export declare function isSlashPathFile(input: string): input is SlashPathFile; /** * Type guard that checks if the input is a typed file path (contains a file extension). * * @param input - The string to check. * @returns Whether the input is a typed file path. */ export declare function isSlashPathTypedFile(input: string): input is SlashPathTypedFile; /** * Type guard that checks if the input is a folder path (ends with a slash). * * @param input - The string to check. * @returns Whether the input is a folder path. */ export declare function isSlashPathFolder(input: string): input is SlashPathFolder; /** * Type guard that checks if the input is a valid slash path (not 'invalid' type). * * @param input - The string to check. * @returns Whether the input is a valid slash path. */ export declare function isValidSlashPath(input: string): input is SlashPath; /** * Returns the last part of the slash path. * * @param slashPath - The path to extract the name from. * @returns The last part of the path (file name or folder name). */ export declare function slashPathName(slashPath: SlashPath): SlashPathPart; /** * Returns each section of a SlashPath. * * @param slashPath - The path to split. * @returns Array of non-empty path segments. */ export declare function slashPathParts(slashPath: SlashPath): SlashPathPart[]; /** * Slash path type to enforce. * - relative: path that does not start with a slash * - absolute: path that starts with a slash * - any: either relative or absolute */ export type SlashPathStartType = 'relative' | 'absolute' | 'any'; /** * Factory use to set the slash path type of the input. */ export type SlashPathStartTypeFactory = SlashPathFunction; /** * Creates a function that enforces the specified start type on a slash path. * * @param type - The start type to enforce. * @returns A function that transforms paths to the specified start type. */ export declare function slashPathStartTypeFactory(type: SlashPathStartType): SlashPathStartTypeFactory; export declare const LEADING_SLASHES_REGEX: RegExp; export declare const TRAILING_SLASHES_REGEX: RegExp; export declare const TRAILING_FILE_TYPE_SEPARATORS_REGEX: RegExp; export declare const ALL_SLASHES_REGEX: RegExp; export declare const ALL_DOUBLE_SLASHES_REGEX: RegExp; export declare const ALL_SLASH_PATH_FILE_TYPE_SEPARATORS_REGEX: RegExp; /** * Converts a slash path to a relative path by removing all leading slashes. * * @param input - The slash path to convert. * @returns A relative path without leading slashes. */ export declare function toRelativeSlashPathStartType(input: SlashPath): SlashPath; /** * Factory function that creates a SlashPathFolder from a string. */ export type SlashPathFolderFactory = (input: string) => InferredSlashPathFolder; export interface SlashPathFolderFactoryConfig { /** * Optional start type for the slash path. Defaults to 'any'. */ readonly startType?: SlashPathStartType; /** * Whether to treat untyped files as folders. * * Defaults to false. */ readonly treatUntypedFilesAsFolders?: boolean; /** * Optional validation configuration. */ readonly validationConfig?: SlashPathValidationFactoryConfig; /** * The path value to return if the input is considered invalid after the validation step. * * You can also configure the `throwError` option in `validationConfig` to throw an error, in which case this option will be ignored. * * Defaults to ''. */ readonly invalidPathValue?: Maybe; } /** * Creates a SlashPathFolderFactory. * * @param config Configuration options for the factory. * @returns A SlashPathFolderFactory. */ export declare function slashPathFolderFactory(config?: SlashPathFolderFactoryConfig): SlashPathFolderFactory; /** * Converts the input string to a valid slash path folder based on the configuration. * * If the input is a file, the folder of the file is returned instead. * * @param input - the string path to convert to a folder path * @param config - optional configuration controlling path type inference and invalid-path handling * @returns a valid slash path folder string with a trailing slash, or an empty string for relative root */ export declare function slashPathFolder(input: string, config?: SlashPathFolderFactoryConfig): InferredSlashPathFolder; /** * Converts a slash path to an absolute path by ensuring exactly one leading slash. * * @param input - The slash path to convert. * @returns An absolute path starting with a single slash. */ export declare function toAbsoluteSlashPathStartType(input: SlashPath): SlashPath; /** * Replaces consecutive double slashes with single slashes. * * @param input - The slash path to fix. * @returns The path with double slashes collapsed. */ export declare function fixMultiSlashesInSlashPath(input: SlashPath): SlashPath; /** * Replaces consecutive double slashes with single slashes. Alias for {@link fixMultiSlashesInSlashPath}. * * @param input - The slash path to fix. * @returns The path with double slashes collapsed. */ export declare function replaceMultipleFilePathsInSlashPath(input: SlashPath): SlashPath; /** * Removes all trailing slashes from a slash path. * * @param input - The slash path to trim. * @returns The path without trailing slashes. */ export declare function removeTrailingSlashes(input: SlashPath): SlashPath; /** * Removes all trailing dots from a slash path. * * @param input - The slash path to trim. * @returns The path without trailing dots. */ export declare function removeTrailingFileTypeSeparators(input: SlashPath): SlashPath; /** * Adds a trailing slash to the input if it does not already have one. * * @param input A slash path. * @returns A slash path folder. */ export declare function addTrailingSlash(input: SlashPath): SlashPathFolder; /** * Replaces all extra and invalidate FilePathTypeSeparator values from the SlashPath, returning a valid SlashPath. * * @param input * @param replaceWith * @returns */ export declare function replaceInvalidFilePathTypeSeparatorsInSlashPath(input: SlashPath, replaceWith?: string): SlashPath; /** * Creates a function that replaces all extra and invalidate FilePathTypeSeparator values from the SlashPath, returning a valid SlashPath. * * @param input * @param replaceWith * @returns */ export declare function replaceInvalidFilePathTypeSeparatorsInSlashPathFunction(replaceWith?: string): SlashPathFunction; /** * Factory used to validate and fix invalid SlashPath input. */ export type SlashPathValidationFactory = SlashPathFunction; export interface SlashPathValidationFactoryConfig { /** * Set of illegal characters to find/replace. If not provided, used the DEFAULT_SLASH_PATH_ILLEGAL_CHARACTERS */ readonly illegalStrings?: ArrayOrValue; /** * String used to replace all encountered illegal characters. * * Is true by default. */ readonly replaceIllegalCharacters?: string | boolean; /** * Whether or not to replace extra dots by treating them as illegal characters. * * Will replace extra dots with the input value, or if true, will replace them with the value for replaceIllegalCharacters. */ readonly replaceIllegalDots?: string | boolean; /** * Whether or not to validate a final time after replacing elements and throw an error if it is still not valid. * * Disabled by default unless replaceIllegalCharacters and replaceIllegalDots are false. */ readonly throwError?: boolean; } /** * Creates a validation/fixup function for slash paths that replaces illegal characters and extra dots. * * @param config - Configuration for validation behavior. * @returns A function that validates and fixes a slash path. */ export declare function slashPathValidationFactory(config?: SlashPathValidationFactoryConfig): SlashPathValidationFactory; /** * Factory use to generate/merge file paths together. */ export type SlashPathFactory = FactoryWithRequiredInput>>; export interface SlashPathFactoryConfig { /** * SlashPath start type to enforce */ readonly startType?: SlashPathStartType; /** * Prefix paths to append */ readonly basePath?: ArrayOrValue; /** * SlashPathValidationFactoryConfig to use for validation. */ readonly validate?: boolean | SlashPathValidationFactoryConfig; } /** * Creates a factory function that merges path segments together with optional base path, start type enforcement, and validation. * * @param config - Configuration for path generation. * @returns A factory function that merges input paths into a single validated slash path. */ export declare function slashPathFactory(config?: SlashPathFactoryConfig): SlashPathFactory; /** * Merges an array of path segments into a single slash path, filtering nullish values and collapsing double slashes. * * @param paths - Array of path segments to merge. * @returns The merged slash path. */ export declare function mergeSlashPaths(paths: Maybe[]): SlashPath; /** * Creates an Error indicating that a slash path is invalid. * * @returns A new Error with a descriptive message. */ export declare function slashPathInvalidError(): Error; /** * Splits the path and returns the items at the given ranges. * * @param path - The path to isolate parts from. * @param range - Index range defining which path segments to extract. * @returns A new slash path containing only the segments within the range. */ export declare function isolateSlashPath(path: SlashPath, range: IndexRangeInput): SlashPath; /** * isolateSlashPathFunction() config. */ export interface IsolateSlashPathFunctionConfig { /** * Range to isolate */ readonly range: IndexRangeInput; /** * Start type to force the result to be. */ readonly startType?: SlashPathStartType; /** * Whether or not to isolate the path to a file path. If true, the result string will not end with a slash. */ readonly asFile?: boolean; } /** * Isolates a configured index range of path elements. * * Path start type is retained. I.E. If a relative path is input, a relative path will be returned. */ export type IsolateSlashPathFunction = (path: SlashPath) => SlashPath; /** * Creates an IsolateSlashPathFunction. * * @param config - Configuration with range, optional start type, and file mode. * @returns A function that isolates path segments within the configured range. */ export declare function isolateSlashPathFunction(config: IsolateSlashPathFunctionConfig): IsolateSlashPathFunction; export interface SlashPathDetails { /** * The full path */ readonly path: SlashPath; /** * The path type */ readonly type: SlashPathType; /** * The last part of the path. * * If the input path ended with a slash, indicating it is a file, then this will include the slash. */ readonly end: SlashPathPart; /** * Returns true if the input is a typed or untyped file. */ readonly isFile: boolean; /** * The last part of the path, if the path is not a folder. * * If it is a folder, this is undefined. */ readonly file?: Maybe; /** * The file name, if file is defined. * * This is only the filename without the extension, even if the file is a typed file. */ readonly fileName?: Maybe; /** * The typed file part, if the file is a typed file. * * This is the full file name including the extension if the file is a typed file. */ readonly typedFile: Maybe; /** * The file extension of the typed file, if the file is a typed file. */ readonly typedFileExtension?: Maybe; /** * Contains the name of the folder the file is in, if applicable. * * Unset if there is no file. */ readonly fileFolder: Maybe; /** * Contains all parts of the path, minus the file part. * * If a folder is input, this is the entire folder path. * * If there is only one path part and the path is a relative path, this will be an empty string. */ readonly folderPath: InferredSlashPathFolder; /** * The start type of the path. */ readonly startType: SlashPathStartType; /** * All parts of the path */ readonly parts: SlashPathPart[]; } /** * Returns the details of a path. * * @param path The path to get details for. * @returns The details of the path. */ export declare function slashPathDetails(path: SlashPath): SlashPathDetails; /** * Numbers that are translated into pre-configured function codes. */ export declare enum SlashPathPathMatcherPartCode { /** * Treat as a wildcard */ WILDCARD = 0 } export type SlashPathPathMatcherFunction = DecisionFunction; /** * A part of a path to match against. * * SlashPathFolders are expanded into multiple SlashPathPart values automatically. * SlashPathPathMatcherPartCode values are translated into pre-configured functions. * A boolean value will be translated into a decision function. NOTE: Putting false will cause all matches to fail. * Finally, any function that is provided will be used as-is when matching against a path part. */ export type SlashPathPathMatcherPart = SlashPathPart | SlashPathFolder | SlashPathPathMatcherPartCode | SlashPathPathMatcherFunction | boolean; /** * Matcher path composed of parts to match against. */ export type SlashPathPathMatcherPath = ArrayOrValue; /** * Expands the input matcher path into decision functions. * * @param path - Matcher path parts to expand into decision functions. * @returns Array of decision functions for each path part. */ export declare function expandSlashPathPathMatcherPartToDecisionFunctions(path: SlashPathPathMatcherPath): SlashPathPathMatcherFunction[]; /** * The default value to use when filling non-matching parts. */ export declare const DEFAULT_SLASH_PATH_PATH_MATCHER_NON_MATCHING_FILL_VALUE = false; export interface SlashPathPathMatcherConfig { /** * The base path or parts to match against. */ readonly targetPath: SlashPathPathMatcherPath; /** * A decision function to use when matching against the remaining parts of the input path that go past the target path. * * Defaults to a decision function that returns false. */ readonly matchRemaining?: boolean | DecisionFunction; /** * The maximum number of parts to compare/match. */ readonly maxPartsToCompare?: number; /** * A value to use when filling non-matching parts. * * Defaults to false. */ readonly nonMatchingFillValue?: N; } export type SlashPathPathMatcher = (inputPath: SlashPath) => SlashPathPathMatcherResult; export interface SlashPathPathMatcherResult { /** * The input path that was matched. */ readonly inputPath: SlashPath; /** * True if the input path has the same configured base path. */ readonly matchesTargetPath: boolean; /** * All parts of the input path. */ readonly inputPathParts: SlashPathPart[]; /** * Result of the comparison between the parts of the input path against the base path. * * The array element is null on parts that do not match. */ readonly matchingParts: (SlashPathPart | null)[]; /** * The value to use when filling non-matching parts. */ readonly nonMatchingFillValue: N; /** * Result of the comparison between the parts of the input path against the base path. * * The array element is null on parts that match. * * If the input path is shorter than the target path, the remaining parts will be filled with the nonMatchingFillValue. */ readonly nonMatchingParts: (SlashPathPart | null | N)[]; /** * The total number of parts that did not match. */ readonly nonMatchingPartsCount: number; } export type SlashPathPathMatcherConfigInput = SlashPathPathMatcherConfig | SlashPathPathMatcherConfig['targetPath']; /** * Creates a SlashPathPathMatcherConfig from the input. * * @param input The configuration input. * @returns The configuration. */ export declare function slashPathPathMatcherConfig(input: SlashPathPathMatcherConfigInput): SlashPathPathMatcherConfig; /** * Creates a SlashPathPathMatcher. * * @param input - the matcher configuration, which may be a target path string, an array of path parts, or a full config object * @returns The matcher. */ export declare function slashPathPathMatcher(input: SlashPathPathMatcherConfigInput): SlashPathPathMatcher; export interface SlashPathSubPathMatcherConfig { /** * The base path or parts to match against. */ readonly basePath: SlashPathPathMatcherPath; } export type SlashPathSubPathMatcherResult = SlashPathSubPathMatcherNonMatchResult | SlashPathSubPathMatcherMatchResult; export interface SlashPathSubPathMatcherBaseResult { /** * The input path that was matched. */ readonly inputPath: SlashPath; /** * True if the input path has the same configured base path. */ readonly matchesBasePath: boolean; /** * All parts of the input path. */ readonly inputPathParts: SlashPathPart[]; /** * Result of the comparison between the parts of the input path against the base path. * * The array element is null on parts that match. */ readonly nonMatchingParts: (SlashPathPart | null)[]; /** * All remaining parts of the path, relative to the base path. * * Only non-null if matchesBasePath is true. */ readonly subPathParts: SlashPathPart[] | null; } export interface SlashPathSubPathMatcherMatchResult extends SlashPathSubPathMatcherBaseResult { readonly matchesBasePath: true; /** * All parts of the sub path, relative to the base path. */ readonly subPathParts: SlashPathPart[]; } export interface SlashPathSubPathMatcherNonMatchResult extends SlashPathSubPathMatcherBaseResult { readonly matchesBasePath: false; /** * Unset when the input path does not match the base path. */ readonly subPathParts: null; } /** * Used to match sub paths of a specific configured path. */ export type SlashPathSubPathMatcher = (path: SlashPath) => SlashPathSubPathMatcherResult; /** * Creates a SlashPathSubPathMatcher. * * @param config The configuration for the matcher. * @returns The matcher. */ export declare function slashPathSubPathMatcher(config: SlashPathSubPathMatcherConfig): SlashPathSubPathMatcher;