DefinitelyTyped/types/prettier/prettier-tests.ts
Ika e228e20b8b feat(prettier): initial commit (#18280)
* feat(prettier): initial commit

* style(prettier): fix indentation

* fix(prettier): fix typo

* fix(prettier): replace AST with babylon root node

* refactor(prettier): remove unnecessary export
2017-07-21 10:30:34 -07:00

20 lines
700 B
TypeScript

import * as prettier from 'prettier';
import { ExpressionStatement, CallExpression, Identifier } from 'babel-types';
const formatted = prettier.format("foo ( );", { semi: false });
const isFormatted = prettier.check("foo ( );", { semi: false });
const result = prettier.formatWithCursor(" 1", { cursorOffset: 2 });
const customFormatted = prettier.format("lodash ( )", {
parser(text, { babylon }) {
const ast = babylon(text);
const statement = ast.program.body[0] as ExpressionStatement;
const expression = statement.expression as CallExpression;
const identifier = expression.callee as Identifier;
identifier.name = "_";
return ast;
}
});