What is @types/serve-index?
The @types/serve-index package provides TypeScript type definitions for the serve-index package, which is used to serve pages that display directory listings for a given path in your web server. These type definitions enable TypeScript developers to use serve-index with type safety, ensuring that they use the API correctly according to the expected types.
What are @types/serve-index's main functionalities?
Type Definitions for Directory Listing Configuration
This feature allows developers to configure directory listings with specific options such as displaying icons and filtering files. The type definitions ensure that the configuration options passed to serveIndex are correctly typed.
import * as express from 'express';
import * as serveIndex from 'serve-index';
const app = express();
app.use('/files', serveIndex('path/to/directory', {
icons: true,
filter: (filename, index, files, dir) => files[index].name.endsWith('.txt')
}));
Other packages similar to @types/serve-index
serve-index
serve-index is the JavaScript package that @types/serve-index provides types for. It allows you to serve up directory listings for a specified path on your server. While serve-index itself is used in JavaScript environments, @types/serve-index is specifically used in TypeScript environments to add type safety.
express
Express is a web application framework for Node.js, designed for building web applications and APIs. It is not specifically similar to @types/serve-index, but it often works in conjunction with serve-index for serving static files and directories in Express applications. Express itself does not provide directory listing capabilities, which is why serve-index or similar packages are used.
Installation
npm install --save @types/serve-index
Summary
This package contains type definitions for serve-index (https://github.com/expressjs/serve-index).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/serve-index.
import { Handler } from "express";
import { Stats } from "fs";
declare function serveIndex(path: string, options?: serveIndex.Options): Handler;
declare namespace serveIndex {
interface File {
name: string;
stat: Stats;
}
interface Locals {
directory: string;
displayIcons: boolean;
fileList: File[];
name: string;
stat: Stats;
path: string;
style: string;
viewName: string;
}
type TemplateCallback = (error: Error | null, htmlString?: string) => void;
interface Options {
filter?: ((filename: string, index: number, files: File[], dir: string) => boolean) | undefined;
hidden?: boolean | undefined;
icons?: boolean | undefined;
stylesheet?: string | undefined;
template?: string | ((locals: Locals, callback: TemplateCallback) => void) | undefined;
view?: string | undefined;
}
}
export = serveIndex;
Additional Details
- Last updated: Mon, 25 Sep 2023 13:39:06 GMT
- Dependencies: @types/express
- Global values: none
Credits
These definitions were written by Tanguy Krotoff.