Socket
Socket
Sign inDemoInstall

tsutils

Package Overview
Dependencies
2
Maintainers
1
Versions
94
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tsutils

utilities for working with typescript's AST


Version published
Maintainers
1
Install size
238 kB
Created

Changelog

Source

3.11.0

Features:

  • typeguards: isNumericOrStringLikeLiteral, isTupleTypeReference
  • intersectionTypeParts as counterpart to unionTypeParts
  • someTypePart to execute a callback for each union or intersection constituent until the callback returns true
  • getPropertyOfType looks up a property by its escaped name
  • isPropertyReadonlyInType determines whether a property in a given type cannot be written to
  • symbolHasReadonlyDeclaration determines if a Symbol has any readonly or constant declaration
  • isNumericPropertyName determines whether a property name would match an index signature
  • isBindableObjectDefinePropertyCall returns true for statically analyzable forms of Object.defineProperty(o, 'p', {value, writable})
  • isReadonlyAssignmentDeclaration determines whether an Object.defineProperty call is known to result in a readonly property
  • getLateBoundPropertyNames returns all known property names of an expression
  • getPropertyNameFromType extracts the property name of literal types
  • isWellKnownSymbolLiterally to recognize expressions in the form of Symbol.<name>
  • getPropertyNameOfWellKnownSymbol returns the escaped name for a well known symbol literal
  • unwrapParentheses returns the first child expression that is not a ParenthesizedExpression

Readme

Source

Utility functions for working with typescript's AST

Greenkeeper badge

Usage

This package consists of two major parts: utilities and typeguard functions. By importing the project you will get both of them.

import * as utils from "tsutils";
utils.isIdentifier(node); // typeguard
utils.getLineRanges(sourceFile); // utilities

If 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.

If you only need typeguards you can explicitly import them:

import { isIdentifier } from "tsutils/typeguard";
// You can even distiguish between typeguards for nodes and types
import { isUnionTypeNode } from "tsutils/typeguard/node";
import { isUnionType } from "tsutils/typeguard/type";

If you only need the utilities you can also explicitly import them:

import { forEachComment, forEachToken } from "tsutils/util";

Typescript version dependency

This package is backwards compatible with typescript 2.8.0 at runtime although compiling might need a newer version of typescript installed.

Using typescript@next might work, but it's not officially supported. If you encounter any bugs, please open an issue.

For 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:

// all typeguards compatible with typescript@2.8
import { isIdentifier } from "tsutils/typeguard/2.8";
// you can even use nested submodules
import { isIdentifier } from "tsutils/typeguard/2.8/node";

// all typeguards compatible with typescript@2.9 (includes those of 2.8)
import { isIdentifier } from "tsutils/typeguard/2.9";

// always points to the latest stable version (2.9 as of writing this)
import { isIdentifier } from "tsutils/typeguard";
import { isIdentifier } from "tsutils";

// always points to the typeguards for the next TypeScript version (3.0 as of writing this)
import { isIdentifier } from "tsutils/typeguard/next";

Note that if you are also using utility functions, you should prefer the relevant submodule:

// importing directly from 'tsutils' would pull in the latest typeguards
import { forEachToken } from 'tsutils/util';
import { isIdentifier } from 'tsutils/typeguard/2.8';

Keywords

FAQs

Last updated on 28 May 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc