Skip to content

Commit c4b0fa0

Browse files
committed
fix: use compact in compare method to showcase token savings benefits
- Changed compare method to use compact() instead of encode() - Removed off on off off off off off off off off on off on off off off off off on off off off on on off off off off on off off off off off off off off off off off off on off off off off off off off on off on on off off off on off off on off off on off off on off on off off on off on off off off off on off off off on off off on off off off off off off off off on off on off off on off off off off off off off off off off off off on off off off on off on off on on off off off off on on on off on on off on off on on off off off off on on off off on off off off off off on off off on off off on off off off off off off on off off off off on on off on off off off off off on off on off off off off off off off off off off on on off on off off off parameter since compare should always showcase best-case savings - Ensures TOON's token efficiency is properly demonstrated
1 parent 7ca5f67 commit c4b0fa0

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

src/Toon.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Toon
2727
public static function encode($value, $options = null): string
2828
{
2929
if ($options === null) {
30-
$options = new EncodeOptions();
30+
$options = new EncodeOptions;
3131
}
3232

3333
return ToonSerializer::serialize($value, $options);
@@ -45,7 +45,7 @@ public static function encode($value, $options = null): string
4545
public static function decode(string $toon, $options = null)
4646
{
4747
if ($options === null) {
48-
$options = new DecodeOptions();
48+
$options = new DecodeOptions;
4949
}
5050

5151
return ToonDeserializer::deserialize($toon, $options);
@@ -54,8 +54,7 @@ public static function decode(string $toon, $options = null)
5454
/**
5555
* Encode to compact TOON format (minimal whitespace).
5656
*
57-
* @param mixed $value
58-
* @return string
57+
* @param mixed $value
5958
*/
6059
public static function compact($value): string
6160
{
@@ -65,8 +64,7 @@ public static function compact($value): string
6564
/**
6665
* Encode to readable TOON format (more whitespace for readability).
6766
*
68-
* @param mixed $value
69-
* @return string
67+
* @param mixed $value
7068
*/
7169
public static function readable($value): string
7270
{
@@ -76,8 +74,7 @@ public static function readable($value): string
7674
/**
7775
* Encode to tabular TOON format (optimized for uniform arrays).
7876
*
79-
* @param mixed $value
80-
* @return string
77+
* @param mixed $value
8178
*/
8279
public static function tabular($value): string
8380
{
@@ -98,13 +95,14 @@ public static function estimateTokens(string $toon): int
9895
/**
9996
* Compare TOON vs JSON token usage.
10097
*
101-
* @param mixed $value
102-
* @param EncodeOptions|null $options
98+
* Uses compact format to showcase TOON's token savings benefits.
99+
*
100+
* @param mixed $value
103101
* @return array<string, mixed> Array with keys: toon, json, toon_tokens, json_tokens, savings_percent
104102
*/
105-
public static function compare($value, $options = null): array
103+
public static function compare($value): array
106104
{
107-
$toon = self::encode($value, $options);
105+
$toon = self::compact($value);
108106
$json = json_encode($value, JSON_THROW_ON_ERROR);
109107

110108
$toonTokens = self::estimateTokens($toon);

0 commit comments

Comments
 (0)