tsutils
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
tslib | 1.14.1 | 7.43 kB | 0BSD | prod | |
typescript | 5.4.5 | 30.87 MB | Apache-2.0 | prod peer |
Tsutils is a utility JavaScript library designed for working with TypeScript's Abstract Syntax Tree (AST). It significantly simplifies the process of interacting and handling TypeScript's AST by offering easy-to-use utility functions and typeguard operations.
Using tsutils is quite straightforward as it efficiently organizes its functionalities into two major parts: utilities and typeguard functions. Once tsutils has been imported into your JavaScript project, you have access to both functionalities. Here's an example:
import * as utils from "tsutils";
utils.isIdentifier(node); // typeguard
utils.getLineRanges(sourceFile); // utilities
If your project doesn't require the entire tsutils package, you can select and import only the specific parts you need. This approach can save some startup time and reduce memory consumption. For example, to import only typeguards, you would do the following:
import { isIdentifier } from "tsutils/typeguard";
import { isUnionTypeNode } from "tsutils/typeguard/node";
import { isUnionType } from "tsutils/typeguard/type";
And to specifically import utilities:
import { forEachComment, forEachToken } from "tsutils/util";
Tsutils maintains backwards compatibility with TypeScript 2.8.0 at runtime, and it has separate typeguard functions for compatibility with different TypeScript versions. For instance, if you're using typescript@2.8.0
, you would import directly from the dedicated submodule like so:
import { isIdentifier } from "tsutils/typeguard/2.8";
The tsutils package does not come with bundled documentation. However, in-depth understanding can be achieved by combing through the provided readme file on the GitHub repository as well as analysis of the codebase itself. The GitHub repository for the package can be found at https://github.com/ajafff/tsutils.