<type>api
/
~/

@barelyhuman/fs-route-manifest

0.0.6

dist/index.d.ts

Types
  • FilePathInfo

    export type FilePathInfo = {
        name: string;
        relativePath: any;
        absolutePath: any;
        isDirectory: any;
    };
  • URLPathInfo

    export type URLPathInfo = FilePathInfo & {
        url: string;
        match?: string;
        matchFlags?: string;
    };
  • GenerateOptions

    export type GenerateOptions = {
        normalizer: typeof normalizeURLPaths;
        transformer: typeof expressTransformer;
        sorter: typeof defaultURLSorter;
    };
Functions
  • readDirectory

    export declare function readDirectory(basePath: string, fsInterface?: {
        readDir: typeof fs.readdirSync;
    }): any;
  • generateRoutes

    export declare function generateRoutes(basePath: any, paths: FilePathInfo[], options?: GenerateOptions): URLPathInfo[];
  • expressTransformer

    /**
     * Default transformer used by generateRoutes in conjunction with the `normalizeURLPaths` normalizer
     * to add matching regex to the final manifest.
     * If you've changed the normalizer, make sure you also change the transformer or validate everything
     * you wish for the transformer to handler
     *
     * The current transformer generates a similar regexp pattern to express.js
     */
    export declare function expressTransformer(x: Pick<URLPathInfo, "url"> & Record<string, unknown>): URLPathInfo;
  • normalizeURLPaths

    /**
     * Normalizer used by the generateRoutes function to find and clean up the file paths
     * to valid url segments that can be parsed/compiled to create regex matchers for the final manifest
     * This particular normalizer does the following
     * - Clean File Paths and creates basic urls
     * - Sorts the urls based on the required priority
     */
    export declare function normalizeURLPaths(basePath: string, paths?: FilePathInfo[], sorter?: typeof defaultURLSorter): URLPathInfo[];
  • defaultURLSorter

    export declare function defaultURLSorter(x: URLPathInfo, y: URLPathInfo): number;
  • stringify

    /**
     * Stringify a given manifest with an optional replacer functions
     * the default replacer changes the `match` regex to a string representation of the regex
     */
    export declare function stringify(manifest: URLPathInfo | URLPathInfo[], replacer?: typeof defaultReplacer): string;
  • defaultReplacer

    /**
     * Default replacer used by the `stringify` function to decide what string to be returned in the stringified manifest.
     * As the stringification is on an object, the normal JSON.stringify rules still apply
     */
    export declare function defaultReplacer(k: string, v: unknown): unknown;
All
/// <reference types="node" />
import fs from "node:fs";
export type FilePathInfo = {
    name: string;
    relativePath: any;
    absolutePath: any;
    isDirectory: any;
};
export type URLPathInfo = FilePathInfo & {
    url: string;
    match?: string;
    matchFlags?: string;
};
export type GenerateOptions = {
    normalizer: typeof normalizeURLPaths;
    transformer: typeof expressTransformer;
    sorter: typeof defaultURLSorter;
};
export declare const defaultFS: {
    readDir: typeof fs.readdirSync;
};
export declare function readDirectory(basePath: string, fsInterface?: {
    readDir: typeof fs.readdirSync;
}): any;
export declare function generateRoutes(basePath: any, paths: FilePathInfo[], options?: GenerateOptions): URLPathInfo[];
/**
 * Default transformer used by generateRoutes in conjunction with the `normalizeURLPaths` normalizer
 * to add matching regex to the final manifest.
 * If you've changed the normalizer, make sure you also change the transformer or validate everything
 * you wish for the transformer to handler
 *
 * The current transformer generates a similar regexp pattern to express.js
 */
export declare function expressTransformer(x: Pick<URLPathInfo, "url"> & Record<string, unknown>): URLPathInfo;
/**
 * Normalizer used by the generateRoutes function to find and clean up the file paths
 * to valid url segments that can be parsed/compiled to create regex matchers for the final manifest
 * This particular normalizer does the following
 * - Clean File Paths and creates basic urls
 * - Sorts the urls based on the required priority
 */
export declare function normalizeURLPaths(basePath: string, paths?: FilePathInfo[], sorter?: typeof defaultURLSorter): URLPathInfo[];
export declare function defaultURLSorter(x: URLPathInfo, y: URLPathInfo): number;
/**
 * Stringify a given manifest with an optional replacer functions
 * the default replacer changes the `match` regex to a string representation of the regex
 */
export declare function stringify(manifest: URLPathInfo | URLPathInfo[], replacer?: typeof defaultReplacer): string;
/**
 * Default replacer used by the `stringify` function to decide what string to be returned in the stringified manifest.
 * As the stringification is on an object, the normal JSON.stringify rules still apply
 */
export declare function defaultReplacer(k: string, v: unknown): unknown;