mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
Merge pull request #22286 from TotooriaHyperion/loader-utils
add missing types to loader-utils
This commit is contained in:
Vendored
+5
@@ -1,6 +1,7 @@
|
||||
// Type definitions for loader-utils 1.1
|
||||
// Project: https://github.com/webpack/loader-utils#readme
|
||||
// Definitions by: Gyusun Yeom <https://github.com/Perlmint>
|
||||
// Totooria Hyperion <https://github.com/TotooriaHyperion>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
/// <reference types="node" />
|
||||
|
||||
@@ -20,6 +21,10 @@ export type DigestType = "hex" | "base26" | "base32" | "base36" | "base49" | "ba
|
||||
export function getOptions(loaderContext: loader.LoaderContext): OptionObject;
|
||||
export function parseQuery(optionString: string): OptionObject;
|
||||
export function stringifyRequest(loaderContext: loader.LoaderContext, resource: string): string;
|
||||
export function getRemainingRequest(loaderContext: loader.LoaderContext): string;
|
||||
export function getCurrentRequest(loaderContext: loader.LoaderContext): string;
|
||||
export function isUrlRequest(url: string, root?: string): boolean;
|
||||
export function parseString(str: string): string;
|
||||
export function urlToRequest(url: string, root?: string): string;
|
||||
export function interpolateName(loaderContext: loader.LoaderContext, name: string, options?: any): string;
|
||||
export function getHashDigest(buffer: Buffer, hashType: HashType, digestType: DigestType, maxLength: number): string;
|
||||
|
||||
@@ -1,11 +1,32 @@
|
||||
import { loader } from "webpack";
|
||||
import { getOptions, parseQuery, stringifyRequest, urlToRequest, interpolateName, getHashDigest } from "loader-utils";
|
||||
import {
|
||||
getOptions,
|
||||
parseQuery,
|
||||
stringifyRequest,
|
||||
urlToRequest,
|
||||
interpolateName,
|
||||
getHashDigest,
|
||||
getRemainingRequest,
|
||||
getCurrentRequest,
|
||||
isUrlRequest,
|
||||
parseString,
|
||||
} from "loader-utils";
|
||||
|
||||
parseQuery("?{data:{a:1},isJSON5:true}");
|
||||
parseString(`"123"`); // "123"
|
||||
parseString(`'123'`); // "123"
|
||||
parseString(`123`); // "123"
|
||||
const jsonStr = JSON.stringify({ a: 1, b: 2 });
|
||||
const parsed = parseString(jsonStr);
|
||||
jsonStr === parsed; // true
|
||||
|
||||
function loader(this: loader.LoaderContext) {
|
||||
getOptions(this);
|
||||
|
||||
getRemainingRequest(this);
|
||||
|
||||
getCurrentRequest(this);
|
||||
|
||||
stringifyRequest(this, "./test.js");
|
||||
// "\"./test.js\""
|
||||
|
||||
@@ -35,6 +56,10 @@ urlToRequest("path/to/module.js"); // "./path/to/module.js"
|
||||
urlToRequest("~path/to/module.js"); // "path/to/module.js"
|
||||
urlToRequest("/path/to/module.js", "./root"); // "./root/path/to/module.js"
|
||||
urlToRequest("/path/to/module.js", "~"); // "path/to/module.js"
|
||||
isUrlRequest("path/to/module.js");
|
||||
isUrlRequest("~path/to/module.js");
|
||||
isUrlRequest("/path/to/module.js", "./root");
|
||||
isUrlRequest("/path/to/module.js", "~");
|
||||
|
||||
function loader2(this: loader.LoaderContext) {
|
||||
// loaderContext.resourcePath = "/app/js/javascript.js"
|
||||
|
||||
Reference in New Issue
Block a user