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

@karimsa/tardis

v0.0.19

Published

Transpile languages with simplicity.

Downloads

5

Readme

Motivation

Babel is a very powerful & highly effective tool for transpiling JavaScript. But unfortuanately, due to its extensive architecture, it has grown to be a very large project and so the contributors are not currently looking to extend it any further to support greater syntax. That is a completely fair decision considering the size of their project but for some projects that I am working on, I thought it would be nice to utilize their architecture towards transpiling between languages other than JavaScript. So this project was created as a stripped down version of babel that supports traversal and AST manipulation but is agnostic to things like node types, parser, and generator - all of which can be manually specified.

Usage

Install it: npm install --save-dev @karimsa/tardis.

import { parse } from 'babylon'
import { Node as BabylonNode } from 'babel-types'
import { transpile, fromBabylon, babelGenerator } from '../src'

transpile(`
  console.log('hello')
`, {
  parser (code) {
    const ast: BabylonNode = parse(code)

    // the 'fromBabylon' helper takes an AST from babylon and adds tardis extensions
    // using babel-types
    return fromBabylon(ast)
  },

  visitor: {
    MemberExpression (path) {
      // the basic requirements for a node are 'type' and 'children'
      // everything else is optional + it can be a simple object, does not need to be created
      // from a class
      path.replaceWith({
        type: 'Identifier',
        name: 'print',
        children: () => [],
      })
    }
  },

  // the generator is a simple visitor that receives each node instead of a nodePath
  // and should return a string for the node
  // 'toJS' is a helper that wraps babel-generator to produce javascript code from nodes
  // but allows overrides
  generator: babelGenerator,
})
  .then(console.log)
  .catch(console.error)

Tardis offers APIs for just simple tree traversal as well as transpiling which is just a wrapper around the traversal API that dispatches generation on the root node (which should propagate through the tree if the tree is created properly).

The transpiler & traversal APIs are both asynchronous to allow for asynchronous walking of the tree. This isn't particularly efficient but it allows you to have async checks for how you want to do node replacements.

Some examples are provided in examples/.

Goals

  • Allow usage of existing babel plugins with minimal addition effort
  • This would be an effective way of getting to feature-complete on the NodePath class
  • Add auto-sourcemap support by watching incoming location + creating a outgoing location from the generator

License

Copyright © 2018-present Karim Alibhai.

Licensed under MIT license.