haye.cr

Expressive string syntax to Array/Hash and Vice-Versa parser for Crystal. Based on the javascript version crystal-shards crystal-shard
HEAD Latest release released
krthr/haye.cr
4
Wilson

Haye.cr

Based on the javascript version.

Haye is a simple super fast string expression parser. In support pipe and qs string expressions ( explained below ).

Pipe expression

The pipe based expression is very popular in Laravel community, due to their Validation engine, and same is adopted by Indicative.

Syntax example:

required|email|max:4|range:10,30
  1. Each item is separated by |
  2. The values are defined after :
  3. Multiple values are separated by ,.
  4. White spaces in keys are trimmed.

Installation

  1. Add the dependency to your shard.yml:
dependencies:
  haye.cr:
    github: krthr/haye.cr
  1. Run shards install

Usage

require "haye.cr"

Pipe -> Array

expression = 'required|email:unique,users'
parsed = Haye.fromPipe(expression) # Haye.fromPipe(expression, Haye::PresenterTypes::Array)

Output (Haye::Presenters::Node[])

[
  #<Haye::Presenters::Node:0x7f11fd891e40 
    @name="required", 
    @args=[]
  >, 
  #<Haye::Presenters::Node:0x7f11fd891de0 
    @name="email", 
    @args=["unique", "users"]
  >
]

Pipe -> Hash

expression = 'required|email:unique,users'
parsed = Haye.fromPipe(expression, Haye::PresenterTypes::Hash)

Output (Hash)

{
  "required" => [], 
  "email" => ["unique", "users"]
}

Contributing

  1. Fork it (https://github.com/krthr/haye.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • krthr - creator and maintainer
haye.cr:
  github: krthr/haye.cr
  
License MIT
Crystal 0.32.0

Authors

Dependencies 0

Development Dependencies 0

Dependents 0

Last synced .
search fire star recently