underhill
TypeScript icon, indicating that this package has built-in type declarations

1.0.18 • Public • Published

underhill

An opinionated wrapper of tsquery and some other things. Very early in prototyping so everything is likely to change! 🏄

https://astexplorer.net/ is a very useful tool for building selectors.

Examples

import * as path from 'path'
import { SourceCode } from 'underhill'

let example = SourceCode.fromFile(path.join(__dirname, 'example.ts'))

example.modifyParent({
    selector: 'InterfaceDeclaration > Identifier[name!=/[I][A-Z].*/]',
    action: o =>
        o.members.push(
            SourceCode.extractFirst(
                'PropertySignature',
                `
                interface __ {
                    readonly testProperty: boolean
                }
                `
            )
        ),
})

example.modifyParent({
    selector: 'Identifier[name=defaultState]',
    action: o =>
        o.initializer.properties.push(
            SourceCode.extractFirst(
                'PropertyAssignment',
                `
                const __ = {
                    testProperty: false
                }
                `
            )
        ),
})

example.logDiff()

example.writeToFile(path.join(__dirname, 'output.ts'))
let files = await SourceCode.searchFiles(path.join(__dirname, 'my-project'), {
    selector: 'CallExpression[expression.text=getDefault]',
})

files.forEach(f => {
    console.log('\n' + f.path)
    console.log(f.summary.join('\n---\n'))
})

Readme

Keywords

none

Package Sidebar

Install

npm i underhill

Weekly Downloads

0

Version

1.0.18

License

MIT

Unpacked Size

52.1 kB

Total Files

7

Last publish

Collaborators

  • farant