All Projects → jpsim → Yams

jpsim / Yams

Licence: mit
A Sweet and Swifty YAML parser.

Programming Languages

c
50402 projects - #5 most used programming language
swift
15916 projects

Projects that are alternatives of or similar to Yams

Swaggen
OpenAPI/Swagger 3.0 Parser and Swift code generator
Stars: ✭ 385 (-44.36%)
Mutual labels:  yaml
K2tf
Kubernetes YAML to Terraform HCL converter
Stars: ✭ 477 (-31.07%)
Mutual labels:  yaml
Invoice Boilerplate
Simple automated LaTeX invoicing system
Stars: ✭ 604 (-12.72%)
Mutual labels:  yaml
Datamodel Code Generator
Pydantic model generator for easy conversion of JSON, OpenAPI, JSON Schema, and YAML data sources.
Stars: ✭ 393 (-43.21%)
Mutual labels:  yaml
Xcodegen
A Swift command line tool for generating your Xcode project
Stars: ✭ 5,032 (+627.17%)
Mutual labels:  yaml
Libyaml
Canonical source repository for LibYAML
Stars: ✭ 502 (-27.46%)
Mutual labels:  yaml
Letter Boilerplate
Finest letter typesetting from the command line
Stars: ✭ 374 (-45.95%)
Mutual labels:  yaml
Neon
🍸 Encodes and decodes NEON file format.
Stars: ✭ 674 (-2.6%)
Mutual labels:  yaml
Dhall Kubernetes
Typecheck, template and modularize your Kubernetes definitions with Dhall
Stars: ✭ 458 (-33.82%)
Mutual labels:  yaml
Countries
World countries in JSON, CSV, XML and Yaml. Any help is welcome!
Stars: ✭ 5,379 (+677.31%)
Mutual labels:  yaml
Latexindent.pl
Perl script to add indentation (leading horizontal space) to LaTeX files. It can modify line breaks before, during and after code blocks; it can perform text wrapping and paragraph line break removal. It can also perform string-based and regex-based substitutions/replacements. The script is customisable through its YAML interface.
Stars: ✭ 415 (-40.03%)
Mutual labels:  yaml
Koanf
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.
Stars: ✭ 450 (-34.97%)
Mutual labels:  yaml
Ios Dev Playbook
不会运维的 iOS 开发不是好设计师。这个 Ansible Playbook 能快速配置 iOS 开发需要的服务,安装如 Gogs、GitLab、Jenkins、Ghost、Ajenti 等常用服务。
Stars: ✭ 542 (-21.68%)
Mutual labels:  yaml
Go Yaml
YAML support for the Go language
Stars: ✭ 393 (-43.21%)
Mutual labels:  yaml
Omegaconf
Flexible Python configuration system. The last one you will ever need.
Stars: ✭ 632 (-8.67%)
Mutual labels:  yaml
Packagedev
Tools to ease the creation of snippets, syntax definitions, etc. for Sublime Text.
Stars: ✭ 378 (-45.38%)
Mutual labels:  yaml
Draft
Generate High Level Cloud Architecture diagrams using YAML syntax.
Stars: ✭ 483 (-30.2%)
Mutual labels:  yaml
Structured Text Tools
A list of command line tools for manipulating structured text data
Stars: ✭ 6,180 (+793.06%)
Mutual labels:  yaml
Shyaml
YAML for command line
Stars: ✭ 642 (-7.23%)
Mutual labels:  yaml
Panini
A super simple flat file generator.
Stars: ✭ 562 (-18.79%)
Mutual labels:  yaml

Yams

Yams

A sweet and swifty YAML parser built on LibYAML.

SwiftPM xcodebuild pod lib lint Nightly codecov

Installation

Building Yams requires Xcode 11.x or a Swift 5.1+ toolchain with the Swift Package Manager or CMake and Ninja.

CMake

CMake 3.17.2 or newer is required, along with Ninja 1.9.0 or newer.

When building for non-Apple platforms:

cmake -B /path/to/build -G Ninja -S /path/to/yams -DCMAKE_BUILD_TYPE=Release -DFoundation_DIR=/path/to/foundation/build/cmake/modules
cmake --build /path/to/build

To build for Apple platforms (macOS, iOS, tvOS, watchOS), there is no need to spearately build Foundation because it is included as part of the SDK:

cmake -B /path/to/build -G Ninja -S /path/to/yams -DCMAKE_BUILD_TYPE=Release
cmake --build /path/to/build

Swift Package Manager

Add .package(url: "https://github.com/jpsim/Yams.git", from: "4.0.4") to your Package.swift file's dependencies.

CocoaPods

Add pod 'Yams' to your Podfile.

Carthage

Add github "jpsim/Yams" to your Cartfile.

Usage

Yams has three groups of conversion APIs: one for use with Codable types, another for Swift Standard Library types, and a third one for a Yams-native representation.

Codable types

  • Codable is an encoding & decoding strategy introduced in Swift 4 enabling easy conversion between YAML and other Encoders like JSONEncoder and PropertyListEncoder.
  • Lowest computational overhead, equivalent to Yams.Node.
  • Encoding: YAMLEncoder.encode(_:) Produces a YAML String from an instance of type conforming to Encodable.
  • Decoding: YAMLDecoder.decode(_:from:) Decodes an instance of type conforming to Decodable from YAML String or Data.
import Foundation
import Yams

struct S: Codable {
    var p: String
}

let s = S(p: "test")
let encoder = YAMLEncoder()
let encodedYAML = try encoder.encode(s)
encodedYAML == """
p: test

"""
let decoder = YAMLDecoder()
let decoded = try decoder.decode(S.self, from: encodedYAML)
s.p == decoded.p

Swift Standard Library types

  • The type of Swift Standard Library is inferred from the contents of the internal Yams.Node representation by matching regular expressions.
  • This method has the largest computational overhead When decoding YAML, because the type inference of all objects is done up-front.
  • It may be easier to use in such a way as to handle objects created from JSONSerialization or if the input is already standard library types (Any, Dictionary, Array, etc.).
  • Encoding: Yams.dump(object:) Produces a YAML String from an instance of Swift Standard Library types.
  • Decoding: Yams.load(yaml:) Produces an instance of Swift Standard Library types as Any from YAML String.
// [String: Any]
let dictionary: [String: Any] = ["key": "value"]
let mapYAML: String = try Yams.dump(object: dictionary)
mapYAML == """
key: value

"""
let loadedDictionary = try Yams.load(yaml: mapYAML) as? [String: Any]

// [Any]
let array: [Int] = [1, 2, 3]
let sequenceYAML: String = try Yams.dump(object: array)
sequenceYAML == """
- 1
- 2
- 3

"""
let loadedArray: [Int]? = try Yams.load(yaml: sequenceYAML) as? [Int]

// Any
let string = "string"
let scalarYAML: String = try Yams.dump(object: string)
scalarYAML == """
string

"""
let loadedString: String? = try Yams.load(yaml: scalarYAML) as? String

Yams.Node

  • Yams' native model representing Nodes of YAML which provides all functions such as detection and customization of the YAML format.
  • Depending on how it is used, computational overhead can be minimized.
  • Encoding: Yams.serialize(node:) Produces a YAML String from an instance of Node.
  • Decoding Yams.compose(yaml:) Produces an instance of Node from YAML String.
var map: Yams.Node = [
    "array": [
        1, 2, 3
    ]
]
map.mapping?.style = .flow
map["array"]?.sequence?.style = .flow
let yaml = try Yams.serialize(node: map)
yaml == """
{array: [1, 2, 3]}

"""
let node = try Yams.compose(yaml: yaml)
map == node

Integrating with Combine

When Apple's Combine framework is available, YAMLDecoder conforms to the TopLevelDecoder protocol, which allows it to be used with the decode(type:decoder:) operator:

import Combine
import Foundation
import Yams

func fetchBook(from url: URL) -> AnyPublisher<Book, Error> {
    URLSession.shared.dataTaskPublisher(for: url)
        .map(\.data)
        .decode(type: Book.self, decoder: YAMLDecoder())
        .eraseToAnyPublisher()
}

License

Both Yams and libYAML are MIT licensed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].