diff --git a/src/Enum/Info.php b/src/Enum/Info.php index 22e9dd3..49a0e2c 100644 --- a/src/Enum/Info.php +++ b/src/Enum/Info.php @@ -72,4 +72,13 @@ public static function nameOf(string|int $value): ?string default => $res, }; } + + /** + * Convert the Enum into a Javascript structure. + */ + public static function toJavascript(): string + { + return JavascriptConverter::new() + ->convertToObject(static::class); /* @phpstan-ignore-line */ + } } diff --git a/src/Enum/InfoTest.php b/src/Enum/InfoTest.php index 488d064..de4b212 100644 --- a/src/Enum/InfoTest.php +++ b/src/Enum/InfoTest.php @@ -19,6 +19,16 @@ public function it_can_get_information_from_a_pure_enumeration(): void self::assertSame(['Top', 'Down', 'Left', 'Right'], Direction::names()); self::assertSame([], Direction::values()); self::assertNull(Direction::nameOf('Up')); + $expected = <<