定制 sedlatschek/laravel-typescript-writer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sedlatschek/laravel-typescript-writer

最新稳定版本:v1.0.0-beta.8

Composer 安装命令:

composer require sedlatschek/laravel-typescript-writer

包简介

This is my package laravel-typescript-writer

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Write typescript data out of laravel. Does not generate interfaces. Eg.:

$simon = [
    'name' => 'Simon'
]

will turn into

export const simon: Person = {
    name: "Simon"
}

Installation

You can install the package via composer:

composer require --dev sedlatschek/laravel-typescript-writer

You should publish the config file with:

php artisan vendor:publish --tag="typescript-writer-config"

This is the contents of the published config file:

return [
    // The typescript file indentation
    'indentation' => 2,

    // The end-of-line character
    'eol_char' => PHP_EOL,

    // Whether to use single or double quotes for strings
    'single_quote' => true,

    // The files that should be written
    'files' => [
        /*
        new TypescriptFile(__DIR__.'/example.ts', [
            // The contents of the file
            new TypescriptData('Array<Test>', 'test', [
                [
                    'id' => 33,
                    'name' => 'test',
                    'active' => true,
                    'languages' => [
                        'German',
                        'English',
                    ],
                ],
            ]),
        ]),
        */
    ],
];

Configuration

Value Replacements

You can replace given values with hardcoded strings. This can be useful if you have an enum that can be matched with the output values.

new TypescriptData(
    'Array<Test>',
    'test',
    // the data
    [
        [
            'test' => [
                'flags' => [
                    1,
                    2,
                    3,
                ],
            ],
        ],
    ],
    // the configured replacements
    [
        '*.test.flags' => [
            1 => 'SomeEnum.ABC',
            2 => 'SomeEnum.DEF',
            3 => 'SomeEnum.GHJ',
        ],
    ]),

will output

export const test: Array<Test> = [
  {
    test: {
      flags: [
        SomeEnum.ABC,
        SomeEnum.DEF,
        SomeEnum.GHJ
      ]
    }
  }
];

Usage

php artisan typescript-writer

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 2.92k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-01