搜尋套件、儲存庫與 APP 分類

套件詳情v2.1.0

yaml_writer

一個用於撰寫 YAML 文件的程式庫,支援物件編碼與 'dart:convert' 的 'Converter'。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
66.6萬
喜歡數
29
Pub 分數
160

安裝套件

flutter pub add yaml_writer

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

yaml_writer 是一個 Dart 庫,專為產生支援物件編碼並整合 'dart:convert' Converter 接口的 YAML 文件而設計。它能無縫地將 Dart 物件序列化為結構化的 YAML 格式,非常適合用於設定檔、資料交換與永久儲存。此套件相容於所有主要平台,包含 Android、iOS、Web、macOS、Windows 與 Linux。以簡潔性與互通性為重點,它擴展了標準 Dart 生態系統,同時維持乾淨、易讀的輸出。

適用情境

  • 產生設定檔
  • 將 Dart 物件序列化為 YAML
  • YAML 格式的数据持久化
  • 與 dart:convert 的互操作性
  • 建立結構化資料匯出

主要特色

  • 物件編碼支援
  • 與 dart:convert Converter 的整合
  • 跨平台相容性
  • 乾淨且可讀的 YAML 輸出
  • 用於撰寫 YAML 文件的簡單 API

適合對象

  • 處理設定資料的開發者
  • 需要 YAML 輸出的應用程式
  • 使用 dart:convert 工具的專案
  • 跨平台 Flutter 應用
  • 需要結構化文字序列化的工具

使用建議

  • 僅限撰寫 YAML(不支援解析)
  • 依賴外部相依性以實現完整功能
  • 未針對大規模 YAML 產生進行優化
  • 輸入物件無內建驗證
  • 需要手動處理複雜的嵌套結構

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

yaml_writer

pub package Null Safety Codecov Dart CI GitHub Tag New Commits Last Commits Pull Requests Code size License

A library to write YAML documents, supporting Object encoding and dart:convert Converter.

Usage

A simple usage example:

import 'package:yaml_writer/yaml_writer.dart';

void main() {
  final yamlWriter = YamlWriter();

  final yamlDoc = yamlWriter.write({
    'name': 'Joe',
    'ids': [10, 20, 30],
    'desc': 'This is\na multiline\ntext',
    'enabled': true,
  });

  print(yamlDoc);
}

OUTPUT:

name: "Joe"
ids: 
  - 10
  - 20
  - 30
desc: |-
    This is
    a multiline
    text
enabled: true

YAML Strings

The writer will try to encode strings using the best format depending on the text, avoiding to escape " and using | for multiline texts.

Encoding Objects

You can use YAMLWriter.toEncodable to convert an Object to an encodable version, similar to what is done by dart:convert JsonEncoder.

If YAMLWriter.toEncodable is not set, it will try to call toJson().

Features and bugs

Please file feature requests and bugs at the issue tracker.

Author

Graciliano M. Passos: gmpassos@GitHub.

Liplum: liplum@GitHub

License

Dart free & open-source license.

所屬分類

原始碼儲存庫

使用此套件的專案