From 80b5c8a717722288474870c2c1ee9ca6dfeda0d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Tue, 3 Mar 2020 02:47:31 +0100 Subject: [PATCH] feat(decomment): type definition for v0.9 (#42779) - type definitions - tests https://github.com/vitaly-t/decomment#api Thanks! --- types/decomment/decomment-tests.ts | 11 ++++++ types/decomment/index.d.ts | 60 ++++++++++++++++++++++++++++++ types/decomment/tsconfig.json | 23 ++++++++++++ types/decomment/tslint.json | 1 + 4 files changed, 95 insertions(+) create mode 100644 types/decomment/decomment-tests.ts create mode 100644 types/decomment/index.d.ts create mode 100644 types/decomment/tsconfig.json create mode 100644 types/decomment/tslint.json diff --git a/types/decomment/decomment-tests.ts b/types/decomment/decomment-tests.ts new file mode 100644 index 0000000000..e9d6f46bbb --- /dev/null +++ b/types/decomment/decomment-tests.ts @@ -0,0 +1,11 @@ +import decomment = require('decomment'); +const code = '/* comment */\r\n\r\n var test = 123'; +decomment(code); // $ExpectType string +decomment(code, { space: true }); // $ExpectType string +decomment(code, { ignore: /\/\*\*\s*\n([^\*]|(\*(?!\/)))*\*\//g }); // $ExpectType string +decomment(code, { trim: true }); // $ExpectType string + +const text = '.my-class{color:Red;}// comments'; +decomment.text(text); // $ExpectType string +decomment.html(text, { space: true }); // $ExpectType string +decomment.getEOL(text); // $ExpectType string diff --git a/types/decomment/index.d.ts b/types/decomment/index.d.ts new file mode 100644 index 0000000000..31e3b20e23 --- /dev/null +++ b/types/decomment/index.d.ts @@ -0,0 +1,60 @@ +// Type definitions for decomment 0.9 +// Project: https://github.com/vitaly-t/decomment +// Definitions by: Piotr Błażejewicz (Peter Blazejewicz) +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * This method first checks if the code starts with <, + * as an HTML, and if so, all entries are removed, according to the options + * see {@link https://github.com/vitaly-t/decomment#decommentcode-options--string} + */ +declare function decomment(code: string, options?: decomment.Options): string; + +declare namespace decomment { + interface Options { + /** + * keep special multi-line comments that begin with: + * - entries from it according to the options. + */ + function html(html: string, options?: Options): string; + /** + * Returns End-of-Line string used within the text, based on the occurrence frequency: + * - \n - for Unix-encoded text + * - \r\n - for Windows-encoded text + */ + function getEOL(text: string): string; +} + +export = decomment; diff --git a/types/decomment/tsconfig.json b/types/decomment/tsconfig.json new file mode 100644 index 0000000000..8c5a60f39e --- /dev/null +++ b/types/decomment/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "decomment-tests.ts" + ] +} diff --git a/types/decomment/tslint.json b/types/decomment/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/decomment/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }