承接 knackline/laravel-toon 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

knackline/laravel-toon

最新稳定版本:1.0

Composer 安装命令:

composer require knackline/laravel-toon

包简介

A powerful Laravel package for integrating Toon functionality into your Laravel applications. Seamlessly add Toon features with elegant Laravel syntax.

README 文档

README

A powerful Laravel package for converting between JSON and Toon format. Seamlessly transform your JSON data into a compact, human-readable Toon format and back again.

Installation

You can install the package via Composer:

composer require knackline/laravel-toon

The package will automatically register its service provider and facade.

Usage

Converting JSON to Toon Format

use Knackline\LaravelToon\Toon;

$jsonData = [
    "context" => [
        "task" => "Our favorite hikes together",
        "location" => "Boulder",
        "season" => "spring_2025"
    ],
    "friends" => ["ana", "luis", "sam"],
    "hikes" => [
        [
            "id" => 1,
            "name" => "Blue Lake Trail",
            "distanceKm" => 7.5,
            "elevationGain" => 320,
            "companion" => "ana",
            "wasSunny" => true
        ]
    ]
];

$toon = Toon::fromJson($jsonData);

Output:

context:
  task: Our favorite hikes together
  location: Boulder
  season: spring_2025
friends[3]: ana,luis,sam
hikes[3]{id,name,distanceKm,elevationGain,companion,wasSunny}:
  1,Blue Lake Trail,7.5,320,ana,true
  2,Ridge Overlook,9.2,540,luis,false
  3,Wildflower Loop,5.1,180,sam,true

Converting Toon Format to JSON

$toonString = "context:
  task: Our favorite hikes together
  location: Boulder
  season: spring_2025
friends[3]: ana,luis,sam
hikes[3]{id,name,distanceKm,elevationGain,companion,wasSunny}:
  1,Blue Lake Trail,7.5,320,ana,true
  2,Ridge Overlook,9.2,540,luis,false";

$jsonData = Toon::toJson($toonString);

Using the Facade

If you prefer using facades:

use Knackline\LaravelToon\Facades\Toon;

$toon = Toon::fromJson($data);
$json = Toon::toJson($toon);

Format Specification

Simple Values

key: value

Objects (Associative Arrays)

key:
  nestedKey: value
  anotherKey: value

Simple Arrays

key[count]: value1,value2,value3

Arrays of Objects

key[count]{field1,field2,field3}:
  value1,value2,value3
  value4,value5,value6

Supported Data Types

  • Strings: Plain text values
  • Numbers: Integers and floats (e.g., 7.5, 320)
  • Booleans: true and false
  • Null: Empty values
  • Arrays: Both indexed and associative arrays
  • Nested Objects: Multi-level object structures

Requirements

  • PHP 8.1 or higher
  • Laravel 9.0, 10.0, or 11.0

License

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

Support

For issues, questions, or contributions, please visit the GitHub repository.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-13