UNPKG

3.4 kBMarkdownView Raw
1# Installation
2> `npm install --save @types/loader-utils`
3
4# Summary
5This package contains type definitions for loader-utils (https://github.com/webpack/loader-utils#readme).
6
7# Details
8Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/loader-utils.
9## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/loader-utils/index.d.ts)
10````ts
11/// <reference types="node" />
12
13import { loader } from "webpack";
14
15export type Readonly<T> = {
16 readonly [P in keyof T]: T[P];
17};
18
19export interface InterpolateOption {
20 context?: string | undefined;
21 content?: string | Buffer | undefined;
22 regExp?: string | RegExp | undefined;
23}
24
25export interface OptionObject {
26 [key: string]: null | false | true | string;
27}
28
29export type HashType = "sha1" | "md4" | "md5" | "sha256" | "sha512";
30
31export type DigestType = "hex" | "base26" | "base32" | "base36" | "base49" | "base52" | "base58" | "base62" | "base64";
32
33/**
34 * Recommended way to retrieve the options of a loader invocation
35 * {@link https://github.com/webpack/loader-utils#getoptions}
36 */
37export function getOptions(loaderContext: loader.LoaderContext): Readonly<OptionObject>;
38
39/**
40 * Parses a passed string (e.g. loaderContext.resourceQuery) as a query string, and returns an object.
41 * {@link https://github.com/webpack/loader-utils#parsequery}
42 */
43export function parseQuery(optionString: string): OptionObject;
44
45/**
46 * Turns a request into a string that can be used inside require() or import while avoiding absolute paths. Use it instead of JSON.stringify(...) if you're generating code inside a loader.
47 * {@link https://github.com/webpack/loader-utils#stringifyrequest}
48 */
49export function stringifyRequest(loaderContext: loader.LoaderContext, resource: string): string;
50
51export function getRemainingRequest(loaderContext: loader.LoaderContext): string;
52
53export function getCurrentRequest(loaderContext: loader.LoaderContext): string;
54
55export function isUrlRequest(url: string, root?: string): boolean;
56
57export function parseString(str: string): string;
58
59/**
60 * Converts some resource URL to a webpack module request.
61 * {@link https://github.com/webpack/loader-utils#urltorequest}
62 */
63export function urlToRequest(url: string, root?: string): string;
64
65/**
66 * Interpolates a filename template using multiple placeholders and/or a regular expression.
67 * The template and regular expression are set as query params called name and regExp on the current loader's context.
68 * {@link https://github.com/webpack/loader-utils#interpolatename}
69 */
70export function interpolateName(loaderContext: loader.LoaderContext, name: string, options?: any): string;
71
72/**
73 * @param buffer
74 * @param [hashType='md4']
75 * @param [digestType='hex']
76 * @param [maxLength=9999]
77 */
78export function getHashDigest(buffer: Buffer, hashType: HashType, digestType: DigestType, maxLength: number): string;
79
80````
81
82### Additional Details
83 * Last updated: Tue, 07 Nov 2023 20:08:00 GMT
84 * Dependencies: [@types/node](https://npmjs.com/package/@types/node), [@types/webpack](https://npmjs.com/package/@types/webpack)
85
86# Credits
87These definitions were written by [Gyusun Yeom](https://github.com/Perlmint), [Totooria Hyperion](https://github.com/TotooriaHyperion), [Piotr Błażejewicz](https://github.com/peterblazejewicz), and [Jesse Katsumata](https://github.com/Naturalclar).
88
\No newline at end of file