UNPKG

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