feat(decomment): type definition for v0.9 (#42779)

- type definitions
- tests

https://github.com/vitaly-t/decomment#api

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz)
2020-03-02 17:47:31 -08:00
committed by GitHub
parent 67ab83d478
commit 80b5c8a717
4 changed files with 95 additions and 0 deletions
+11
View File
@@ -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
+60
View File
@@ -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) <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* This method first checks if the code starts with <,
* as an HTML, and if so, all <!-- comment --> 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:
* - <!--[if - for conditional comments in HTML
* - /*! - for everything else (other than HTML)
* @default false - remove all multi-line comments
*/
safe?: boolean;
/**
* Takes either a single or an array of regular expressions to match against.
* All matching blocks are then skipped, as well as any comment-like content inside them
*/
ignore?: RegExp | RegExp[];
/**
* replace comment blocks with white spaces where needed,
* in order to preserve the original line + column position of every code element.
* @default false - remove comment blocks entirely
*/
space?: boolean;
/**
* remove empty lines that follow removed full-line comments
* @defualt false - do not trim comments
*/
trim?: boolean;
}
/**
* Unlike the default decomment, it instructs the library that text is not a JSON,
* JavaScript or HTML, rather a plain text that needs no parsing or validation,
* only to remove \/\/ and \/**\/ comments from it according to the options.
*/
function text(text: string, options?: Options): string;
/**
* Unlike the default decomment method, it instructs the library not to parse
* or validate the input in any way, rather assume it to be HTML,
* and remove all <!-- comment --> 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;
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }