diff --git a/types/loader-utils/index.d.ts b/types/loader-utils/index.d.ts index ba6be659f1..a178ada777 100644 --- a/types/loader-utils/index.d.ts +++ b/types/loader-utils/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for loader-utils 1.1 // Project: https://github.com/webpack/loader-utils#readme // Definitions by: Gyusun Yeom +// Totooria Hyperion // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -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; diff --git a/types/loader-utils/loader-utils-tests.ts b/types/loader-utils/loader-utils-tests.ts index 6ce002a5d1..d54e773eec 100644 --- a/types/loader-utils/loader-utils-tests.ts +++ b/types/loader-utils/loader-utils-tests.ts @@ -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"