GithubHelp home page GithubHelp logo

cdlaimin / gogocode Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thx/gogocode

0.0 0.0 0.0 2.4 MB

The simplest tool to parse/transform/generate code on ast

License: MIT License

JavaScript 76.00% Vue 23.14% HTML 0.57% Less 0.29%

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 Document

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;

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

yexi-xf avatar bigfengyu avatar wudi3 avatar shuerguo999 avatar atqq avatar btea avatar markthree avatar senyawang avatar william24255 avatar thewei avatar zhangdaren avatar zhuscat avatar eyis 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.