1.2.1 • Published 9 months ago

@draftbit/variable-json v1.2.1

Weekly downloads
188
License
MIT
Repository
-
Last release
9 months ago

VJson: JSON with variables

This defines a superset of JSON, with the addition of "variables" which appear between curly braces (e.g. {{someVariable}}). The format of the variables can be customized by the user, although by default it will parse an alphanuxmeric identifier which can start with a letter or underscore and subsequently contain any letter, digit or _. Although by default variables are strings, the vjson type is polymorphic and the structure can be mapped over to support more complex information.

{
  "id": {{id}},
  "color": {{color}},
  "allSizes": ["small", "medium", "large"],
  "size": {{size}},
}

This library provides tools for:

  • Parsing the above syntax, including custom variable formats
  • Finding the set of variables in a given tree
  • Replacing all of the variables in a tree with JSON, producing a JSON object

Example

let vJson: VJson.t(string) = VJson.parseDefault("{
  \"id\": {{id}},
  \"color\": {{color}},
  \"allSizes\": [\"small\", \"medium\", \"large\"],
  \"size\": {{size}},
}")->Belt.Result.getExn;

// Prints "Set { 'id', 'color', 'size' }"
Js.log(vJson->VJson.findVariables);

// Customizing the variable format to integers
let vJsonWithInts: VJson.t(int) = VJson.(
    "{{123}}"
    |> VJson.parseWithRegex([%re {|/\d+/|}])
    |> Belt.Result.getExn
  )
  ->VJson.map(int_of_string)

Build

yarn re:build

Watch

yarn re:watch
1.2.0

9 months ago

1.2.1

9 months ago

2.2.2

9 months ago

2.2.1

10 months ago

2.2.0

10 months ago

2.1.0

10 months ago

2.0.0

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.9.0

2 years ago

0.8.1

3 years ago

0.8.0

4 years ago

0.7.1-0

4 years ago

0.7.0

5 years ago

0.6.13

5 years ago

0.6.11

5 years ago

0.6.9

5 years ago

0.6.8

5 years ago

0.6.7

5 years ago

0.6.6

5 years ago

0.6.5

5 years ago

0.6.4

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.2

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago