npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-simple-ast-extra

v0.3.15

Published

High level TypeScript Compiler API and refactor tools based on ts-morph (ex ts-simple-ast) library

Downloads

876

Readme

ts-simple-ast-extra

High level TypeScript Compiler API and TypeScript/JavaScript refactor APIs based on ts-morph (ex ts-simple-ast) library.

Contents

Summary

  • Browser support (out of the box)

  • Many APIs for project's code refactors.

    • in general based on TypeScript built in code fixes and refactors
    • Easy to use.
    • Configurable
    • Composable
    • Have tests but use at your own risk
  • APIs useful to me that unfortunately are out of topic to pull them to in ts-morph like astPath or generalNode abstraction or

  • utilities related with TypeScript Plugin development like abstract types, Tests Helpers, AST, repeated code, codefixes generic structure, etc

  • Access to not so public areas of TypeScript APIs or some encapsulated hacks

Install

npm install ts-simple-ast-extra

Usage

NOTE: Currently, although there is API documentation I would say the best source of documentation are the test.

  • There are many different kind of APIs. Each file in src implements a "topic".
  • Each file or "topic" has a test at spec folder using the same name. At the beggining there is alwasys a simple usage src/refactor contain many interesting code refactors at the project level

Refactors

In general they have the same API, you pass a SourceFile and the Project (they need access to the LanguageService):

addBracesToArrowFunctions

import {Project, addBracesToArrowFunctions} from 'ts-simple-ast-extra'
const project = new Project()
const f = project.createSourceFile('f1.ts',  `
  const c = a => a+1
  export f = (b:number h: Date[])=>null
`)
addBracesToArrowFunctions(project, f)
console.log(f.getText())
/*
const c = a => { 
  return a + 1; 
} 
export f = (b:number h: Date[])=>{ 
  return null; 
}
*/

format

import {Project, format} from 'ts-simple-ast-extra'
const project = new Project()
const file = project.createSourceFile('f2.ts',  `
function f(){
alert(1);
log(2,function(){
return 1+g(a=>{
return 2
}              )
}    );
}`)
const output = format({
  file,
  project,
  trailingSemicolons: 'never',
  indentSize: 2,
})
console.log(f.getText())
/*
function f() {
  alert(1)
  log(2, function() {
    return 1 + g(a => {
      return 2
    })
  })
}
*/

API docs

See API docs

CHANGELOG

CHANGELOG.md

TODO

TODO.md

Related projects