• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..16-Feb-2021-

typeguard/H03-May-2022-226208

util/H03-May-2022-257251

.editorconfigH A D16-Feb-2021182 1310

.fimbullinter.yamlH A D16-Feb-202127 32

.wotanrc.yamlH A D16-Feb-2021182 65

CHANGELOG.mdH A D16-Feb-202119.2 KiB742432

LICENSEH A D16-Feb-20211.1 KiB2217

README.mdH A D16-Feb-20212.5 KiB6245

index.d.tsH A D16-Feb-202153 32

package.jsonH A D16-Feb-20211.8 KiB6261

README.md

1# Utility functions for working with typescript's AST
2
3[![Greenkeeper badge](https://badges.greenkeeper.io/ajafff/tsutils.svg)](https://greenkeeper.io/)
4
5## Usage
6
7This package consists of two major parts: utilities and typeguard functions.
8By importing the project you will get both of them.
9```js
10import * as utils from "tsutils";
11utils.isIdentifier(node); // typeguard
12utils.getLineRanges(sourceFile); // utilities
13```
14
15If you don't need everything offered by this package, you can select what should be imported. The parts that are not imported are never read from disk and may save some startup time and reduce memory consumtion.
16
17If you only need typeguards you can explicitly import them:
18```js
19import { isIdentifier } from "tsutils/typeguard";
20// You can even distiguish between typeguards for nodes and types
21import { isUnionTypeNode } from "tsutils/typeguard/node";
22import { isUnionType } from "tsutils/typeguard/type";
23```
24
25If you only need the utilities you can also explicitly import them:
26```js
27import { forEachComment, forEachToken } from "tsutils/util";
28```
29
30### Typescript version dependency
31
32This package is backwards compatible with typescript 2.8.0 at runtime although compiling might need a newer version of typescript installed.
33
34Using `typescript@next` might work, but it's not officially supported. If you encounter any bugs, please open an issue.
35
36For compatibility with older versions of TypeScript typeguard functions are separated by TypeScript version. If you are stuck on `typescript@2.8`, you should import directly from the submodule for that version:
37
38```js
39// all typeguards compatible with typescript@2.8
40import { isIdentifier } from "tsutils/typeguard/2.8";
41// you can even use nested submodules
42import { isIdentifier } from "tsutils/typeguard/2.8/node";
43
44// all typeguards compatible with typescript@2.9 (includes those of 2.8)
45import { isIdentifier } from "tsutils/typeguard/2.9";
46
47// always points to the latest stable version (2.9 as of writing this)
48import { isIdentifier } from "tsutils/typeguard";
49import { isIdentifier } from "tsutils";
50
51// always points to the typeguards for the next TypeScript version (3.0 as of writing this)
52import { isIdentifier } from "tsutils/typeguard/next";
53```
54
55Note that if you are also using utility functions, you should prefer the relevant submodule:
56
57```js
58// importing directly from 'tsutils' would pull in the latest typeguards
59import { forEachToken } from 'tsutils/util';
60import { isIdentifier } from 'tsutils/typeguard/2.8';
61```
62