diff --git a/types/string-replace-webpack-plugin/index.d.ts b/types/string-replace-webpack-plugin/index.d.ts new file mode 100644 index 0000000000..b62c43e448 --- /dev/null +++ b/types/string-replace-webpack-plugin/index.d.ts @@ -0,0 +1,48 @@ +// Type definitions for string-replace-webpack-plugin 0.1 +// Project: https://github.com/jamesandersen/string-replace-webpack-plugin +// Definitions by: Rongjian Zhang +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { Plugin, RuleSetUse } from "webpack"; + +export = StringReplacePlugin; + +declare class StringReplacePlugin extends Plugin { + static replace( + options: StringReplacePlugin.Options, + /** + * loaders to follow the replacement + */ + nextLoaders?: string + ): RuleSetUse; + static replace( + /** + * loaders to apply prior to the replacement + */ + prevLoaders: string, + options: StringReplacePlugin.Options, + /** + * loaders to follow the replacement + */ + nextLoaders?: string + ): RuleSetUse; +} + +declare namespace StringReplacePlugin { + interface Options { + replacements: ReplacementItem[]; + } + + interface ReplacementItem { + /** + * a regex to match against the file contents + */ + pattern: RegExp; + /** + * an ECMAScript string replacement function + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter + */ + replacement: (substring: string, ...args: any[]) => string; + } +} diff --git a/types/string-replace-webpack-plugin/string-replace-webpack-plugin-tests.ts b/types/string-replace-webpack-plugin/string-replace-webpack-plugin-tests.ts new file mode 100644 index 0000000000..b4b0d5304a --- /dev/null +++ b/types/string-replace-webpack-plugin/string-replace-webpack-plugin-tests.ts @@ -0,0 +1,17 @@ +import StringReplacePlugin = require('string-replace-webpack-plugin'); + +StringReplacePlugin.replace('babel-loader', { + replacements: [ + { + // Taken from: + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter + pattern: /([^\d]*)(\d*)([^\w]*)/, + replacement: (match, p1, p2, p3, offset, string) => { + // p1 is nondigits, p2 digits, and p3 non-alphanumerics + return [p1, p2, p3].join(' - '); + } + } + ] +}); + +new StringReplacePlugin(); diff --git a/types/string-replace-webpack-plugin/tsconfig.json b/types/string-replace-webpack-plugin/tsconfig.json new file mode 100644 index 0000000000..0c92ee657b --- /dev/null +++ b/types/string-replace-webpack-plugin/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "string-replace-webpack-plugin-tests.ts"] +} diff --git a/types/string-replace-webpack-plugin/tslint.json b/types/string-replace-webpack-plugin/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/string-replace-webpack-plugin/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }