You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

affe

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

affe

AST querying for lazy people

0.0.4
latest
Source
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

npm bundle size npm GitHub Workflow Status

AST querying for lazy people.

import { js, pipe, select, all } from 'affe'


const config = await readFile('eslint.config.js', 'utf8')

//
// 👇 Let's find out which eslint rules are specified
//    in the config.
//
const rules = await pipe(
  js(config),
  select(`
    export property[name=rules]
    > value > object > property > key > *
  `),
  all(),
)

console.log(rules)
// > semi
// > prefer-const

Contents


Installation

Node:

npm i affe

Browser / Deno:

import { js } from 'https://esm.sh/affe'

Usage

affe simplifies ANY syntax tree into a format that can be queried with a CSS-like syntax. It also provides tooling for further simplification of ASTs of a specific language for more convenience.

affe provides support for JavaScript/JSX out of the box, but you can easily add support for any other language.

import { jsx, pipe, select, pick, all } from 'affe'

const code = jsx`
  export default ({ name, style }) => (
    <div className={style}>Hello, {name}!</div>
  )
`

//
// 👇 Let's find out the name of the properties
//    of the exported component.
//
const params = pipe(
  code,
  select('export params property key *'),
  pick(node => node.name ?? node.value),
  all(),
)

console.log(params)
// > [name, style]

Contribution

You need node, NPM to start and git to start.

# clone the code
git clone git@github.com:loreanvictor/affe.git
# install stuff
npm i

Make sure all checks are successful on your PRs. This includes all tests passing, high code coverage, correct typings and abiding all the linting rules. The code is typed with TypeScript, Jest is used for testing and coverage reports, ESLint and TypeScript ESLint are used for linting. Subsequently, IDE integrations for TypeScript and ESLint would make your life much easier (for example, VSCode supports TypeScript out of the box and has this nice ESLint plugin), but you could also use the following commands:

# run tests
npm test
# check code coverage
npm run coverage
# run linter
npm run lint
# run type checker
npm run typecheck

FAQs

Package last updated on 09 Sep 2023

Did you know?

Socket

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