Skip to content

jsonicjs/directive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@jsonic/directive — directive syntax for Jsonic

Adds directive syntax to the Jsonic JSON parser. A directive is a token sequence (e.g. @name, add<1,2>) that triggers custom parsing behaviour. TypeScript and Go ports share the same API shape and test specs.

npm version build

Documentation

This project's documentation follows the Diátaxis framework. Each section has one job — pick the one that matches what you're trying to do.

If you want to… Read
Build your first directive step-by-step Tutorial
Solve a specific problem How-to guides
Look up an option, type, or default Reference
Understand how the plugin works internally Explanation

Quickstart

TypeScript

import { Jsonic } from 'jsonic'
import { Directive } from '@jsonic/directive'

const j = Jsonic.make().use(Directive, {
  name: 'upper',
  open: '@',
  action: (rule) => (rule.node = String(rule.child.node).toUpperCase()),
})

j('[@a, @b, 1]') // → ['A', 'B', 1]

Go

import (
    jsonic "github.com/jsonicjs/jsonic/go"
    directive "github.com/jsonicjs/directive/go"
)

j := jsonic.Make()
directive.Apply(j, directive.DirectiveOptions{
    Name: "upper",
    Open: "@",
    Action: func(r *jsonic.Rule, _ *jsonic.Context) {
        r.Node = strings.ToUpper(fmt.Sprintf("%v", r.Child.Node))
    },
})

j.Parse("[@a, @b, 1]") // → []any{"A", "B", float64(1)}

License

MIT — see LICENSE.

About

Add directives to Jsonic

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors