mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
feat: add definition for prettier-linter-helpers v1.0 (#43776)
This commit is contained in:
parent
69f5a30b3c
commit
31d22b6594
34
types/prettier-linter-helpers/index.d.ts
vendored
Normal file
34
types/prettier-linter-helpers/index.d.ts
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
// Type definitions for prettier-linter-helpers 1.0
|
||||
// Project: https://github.com/prettier/prettier-linter-helpers
|
||||
// Definitions by: JounQin <https://github.com/JounQin>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* Converts invisible characters to a commonly recognizable visible form.
|
||||
* @param str - The string with invisibles to convert.
|
||||
* @returns The converted string.
|
||||
*/
|
||||
export function showInvisibles(str: string): string;
|
||||
|
||||
export interface GenerateDifferences {
|
||||
/**
|
||||
* Generate results for differences between source code and formatted version.
|
||||
*
|
||||
* @param source - The original source.
|
||||
* @param prettierSource - The Prettier formatted source.
|
||||
* @returns An array containing { operation, offset, insertText, deleteText }
|
||||
*/
|
||||
(source: string, prettierSource: string): Difference[];
|
||||
INSERT: 'insert';
|
||||
DELETE: 'delete';
|
||||
REPLACE: 'replace';
|
||||
}
|
||||
|
||||
export const generateDifferences: GenerateDifferences;
|
||||
|
||||
export interface Difference {
|
||||
operation: 'insert' | 'delete' | 'replace';
|
||||
offset: number;
|
||||
insertText?: string;
|
||||
deleteText?: string;
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
import { generateDifferences, showInvisibles } from 'prettier-linter-helpers';
|
||||
|
||||
declare function log(...args: Array<string | number>): void;
|
||||
|
||||
showInvisibles(' some string ');
|
||||
|
||||
generateDifferences('abc', 'def').forEach(difference => {
|
||||
const { operation, offset, deleteText = '', insertText = '' } = difference;
|
||||
|
||||
switch (operation) {
|
||||
case 'delete':
|
||||
log('delete', offset, deleteText);
|
||||
break;
|
||||
case 'insert':
|
||||
log('insert', offset, insertText);
|
||||
break;
|
||||
case 'replace':
|
||||
log('replace', offset, insertText, deleteText);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unexpected operation: '${operation}'`);
|
||||
}
|
||||
});
|
||||
|
||||
generateDifferences.INSERT;
|
||||
generateDifferences.DELETE;
|
||||
generateDifferences.REPLACE;
|
||||
23
types/prettier-linter-helpers/tsconfig.json
Normal file
23
types/prettier-linter-helpers/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"prettier-linter-helpers-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/prettier-linter-helpers/tslint.json
Normal file
1
types/prettier-linter-helpers/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user