Giter Site home page Giter Site logo

nyml's Introduction

๐Ÿ˜‹ A stupid simple YAML-like implementation in Nim language. From YML to JsonNode
Fast โ€ข Dependency free

Work in progress

Nyml has no serialization, tags, indicators or any weird things. In fact, Nyml is somewhere between toml and yaml If you need a YAML 1.2 compatible library go with flyx's NimYAML.

๐Ÿ˜ Key Features

  • integer, string, boolean, array, object
  • GET access using dot annotations
  • Rules and Validator
  • Open Source | MIT License

Installing

nimble install nyml

Examples

The following example is taken from Madam's Configurator

Contents example
name: "Madam"
path: "./example"
port: 1230

templates:
    views: "views"
    layouts: "layouts"
    partials: "partials"

assets:
    source: "./dist/assets/*"
    public: "/assets"

console:
    logger: true                    # Enable http request logger
    clear: true                     # Clear previous console output on request
let doc = Nyml(engine: Y2J).parse(readFile("sample.yml"),
            rules = @[
                "name*:string",
                "path*:string",
                "port:int|1234",
                
                "templates*:object",
                "templates.layouts*:string",
                "templates.views*:string",
                "templates.partials*:string"
                
                "console:object"
                "console.logger:bool|true"
                "console.clear:bool|true"
            ])

if doc.hasErrorRules():
    let count = doc.getErrorsCount()
    let errorWord = if count == 1: "error" else: "errors"
    echo "๐Ÿ‘‰ Found $1 $2 in your Madam configuration:" % [$count, errorWord]
    for err in doc.getErrorRules():
        echo err.getErrorMessage()
else:
    echo doc.get("name").getStr                     # Madam
    echo doc.get("assets.source").getStr            # ./dist/assets/*

Rules & Validators

need tests

Write your own rules as a seq[string]. The rule syntax is very simple, you got field_name*:string.

Note that field_name should point to a field_name key in your .yml file.

When followed by * it becomes a required field. Then you have the field type.

Now, let's take for example port:int|1234, which is an optional field of int type, with a default value 1234.

Roadmap

  • Add tests
  • Add more examples

โค Contributions

If you like this project you can contribute to Nyml project by opening new issues, fixing bugs, contribute with code, ideas and you can even donate via PayPal address ๐Ÿฅฐ

๐Ÿ‘‘ Discover Nim language

What's Nim? Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Find out more about Nim language

Why Nim? Performance, fast compilation and C-like freedom. We want to keep code clean, readable, concise, and close to our intention. Also a very good language to learn in 2022.

๐ŸŽฉ License

Nyml is an Open Source Software released under MIT license. Developed by Humans from OpenPeep.
Copyright ยฉ 2022 OpenPeep & Contributors โ€” All rights reserved.

nyml's People

Contributors

georgelemon avatar jiro4989 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.