Write typescript data out of laravel. Does not generate interfaces. Eg.:
$simon = [
'name' => 'Simon'
]
will turn into
export const simon: Person = {
name: "Simon"
}
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',
],
],
]),
]),
*/
],
];
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
]
}
}
];
php artisan typescript-writer
composer test
Please see CHANGELOG for more information on what has changed recently.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.