GithubHelp home page GithubHelp logo

iggyvolz / jtgenerator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bklemm/codegenerator

0.0 2.0 0.0 83 KB

Typescript and ES6 Javascript class/file generator, designed specially to generate Vue files from php

License: MIT License

PHP 100.00%

jtgenerator's Introduction

JTGenerator

Typescript and ES6 Javascript class / file generator

Minimum PHP version: 7.4+ Continuous Integration Build Status codecov phpstan

Installation

JTGenerator supports only installation via composer. So first ensure your composer is installed, configured and ready to use.

$ composer require jtgenerator/jtgenerator

Usage

Define initialized constants:

$state = new Constant('TASK');
$state->setValue('data');
$state->setExport();

$file = new ScriptFile();
$file->addContent($state);

echo $file;

Results:

export const TASK = 'data';

Define constants as object:

$state = new Constant('state');
$state->setExport();

$file = new ScriptFile();
$file->addContent($state);

echo $file;

Results:

export const state = {

};

More complex:

$method = new Method('INCREMENT_ACTIVE');
$method->addParameter('state');
$method->setBody('state.active++');

$method2 = new Method('DECREMENT_ACTIVE');
$method2->addParameter('state');
$method2->setBody('if (state.active >= 1) { state.active-- }');

$s = new Constant('mutations');
$s->setExport();

$methods = [$method,$method2];
$s->setMethods(...$methods);

$file = new ScriptFile();
$file->addContent($s);

echo $file;

Results:

export const mutations = {
        
    INCREMENT_ACTIVE(state) {
        state.active++
    }
    DECREMENT_ACTIVE(state) {
        if (state.active >= 1) { state.active-- }
    }
};

Arrow Functions:

$s = new ArrowFunction();
$s->setExport();
$s->setDefault();

$properties = [
    (new Property('[TASKS]'))->setType('[]'),
    (new Property('[TOTAL]'))->setType('[]'),
    (new Property('[PAGINATION]'))->setType(
        [
            'page' => 1,
            'limit' => 10,
            'totalPages' => 0,
            'totalItems' => 0
        ]
    )
];
$s->setProperties(...$properties);

$file = new ScriptFile();
$file->addContent($s);

echo $file;

Results:

export default () => ({
    [TASKS]: [],
    [TOTAL]: [],
    [PAGINATION]: {
        page: 1,
        limit: 10,
        totalPages: 0,
        totalItems: 0
    }
});

jtgenerator's People

Contributors

bklemm avatar

Watchers

 avatar  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.