UNPKG

2.5 kBTypeScriptView Raw
1/// <reference types="node" />
2
3import { loader } from "webpack";
4
5export type Readonly<T> = {
6 readonly [P in keyof T]: T[P];
7};
8
9export interface InterpolateOption {
10 context?: string | undefined;
11 content?: string | Buffer | undefined;
12 regExp?: string | RegExp | undefined;
13}
14
15export interface OptionObject {
16 [key: string]: null | false | true | string;
17}
18
19export type HashType = "sha1" | "md4" | "md5" | "sha256" | "sha512";
20
21export type DigestType = "hex" | "base26" | "base32" | "base36" | "base49" | "base52" | "base58" | "base62" | "base64";
22
23/**
24 * Recommended way to retrieve the options of a loader invocation
25 * {@link https://github.com/webpack/loader-utils#getoptions}
26 */
27export function getOptions(loaderContext: loader.LoaderContext): Readonly<OptionObject>;
28
29/**
30 * Parses a passed string (e.g. loaderContext.resourceQuery) as a query string, and returns an object.
31 * {@link https://github.com/webpack/loader-utils#parsequery}
32 */
33export function parseQuery(optionString: string): OptionObject;
34
35/**
36 * 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.
37 * {@link https://github.com/webpack/loader-utils#stringifyrequest}
38 */
39export function stringifyRequest(loaderContext: loader.LoaderContext, resource: string): string;
40
41export function getRemainingRequest(loaderContext: loader.LoaderContext): string;
42
43export function getCurrentRequest(loaderContext: loader.LoaderContext): string;
44
45export function isUrlRequest(url: string, root?: string): boolean;
46
47export function parseString(str: string): string;
48
49/**
50 * Converts some resource URL to a webpack module request.
51 * {@link https://github.com/webpack/loader-utils#urltorequest}
52 */
53export function urlToRequest(url: string, root?: string): string;
54
55/**
56 * Interpolates a filename template using multiple placeholders and/or a regular expression.
57 * The template and regular expression are set as query params called name and regExp on the current loader's context.
58 * {@link https://github.com/webpack/loader-utils#interpolatename}
59 */
60export function interpolateName(loaderContext: loader.LoaderContext, name: string, options?: any): string;
61
62/**
63 * @param buffer
64 * @param [hashType='md4']
65 * @param [digestType='hex']
66 * @param [maxLength=9999]
67 */
68export function getHashDigest(buffer: Buffer, hashType: HashType, digestType: DigestType, maxLength: number): string;