Giter Club home page Giter Club logo

gogocode's Introduction

Code transform has never been easier: GoGoCode

npm version license

What is GoGoCode?

中文 README

GoGoCode is a transformer for JavaScript/Typescript/HTML based on AST but providing an intuitive API:

  • A jQuery-like API to select and transform AST.
  • A Regex-like syntax to match and replace code.

Learn more at GoGoCode.io and GoGoCode: Yet Another Automated Refactor Tool for Web Developers

Intro

Let's show you how to select and modify code with our API

In

const a = 1;
const b = 2;

Transform With GoGoCode

const $ = require('gogocode');
const script = $(source);
// use $_$ as a wildcard to match AST element at any position you want
const aAssignment = script.find('const a = $_$');
// get matched AST element value
const aValue = aAssignment.match?.[0]?.[0]?.value;
// replace AST as same as replace a string
// but ignore code format (space、indent or linebreak)
script.replace('const b = $_$', `const b = ${aValue}`);
// generate ast to string
const outCode = script.generate();

Out

const a = 1;
const b = 1;

Try this demo out at our Playground.

Related Project

Project Description
gogocode-plugin-vue transform a project from vue2 to vue3
gogocode-plugin-element transform a project from ElementUI to ElementPlus
gogocode-cli command-line tool for gogocode
gogocode-playground test gogocode at browser instantly
gogocode-vscode refactor your project with gogocode in vscode

Support

  • issues
  • Ding Group:34266233
  • QQ Group:735216094

License

MIT

gogocode's People

Contributors

atqq avatar bigfengyu avatar btea avatar eyis avatar markthree avatar senyawang avatar shuerguo999 avatar thewei avatar wudi3 avatar yexi-xf avatar zhangdaren avatar zhuscat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.