mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
feat(decomment): type definition for v0.9 (#42779)
- type definitions - tests https://github.com/vitaly-t/decomment#api Thanks!
This commit is contained in:
parent
67ab83d478
commit
80b5c8a717
@@ -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
|
||||
Vendored
+60
@@ -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;
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user