Coder Social home page Coder Social logo

random-object-language's Introduction

Random Object Language

  • Version:0.6.1

Introduction

Using a schema to define a random object, limit the value range of each fields, and guide the building process.

Example

{
  "field_1": {
    "@type": "assigned",
    "value": "some concrete value"
  },
  "field_2": {
    "@type": "number",
    "integer": true,
    "range": {"gt": 1, "lte": 10}
  },
  "field_3": {
    "field_3_1": {
      "@type": "enum",
      "values": [1, 3, "Bob", {"name": "Alice"}],
      "weights": [2, 2, 1, 4]
    }
  },
  "field_4": {
    "@type": "dependant",
    "dependsOn": ["field_2", "field_3.field_3_1"],
    "map": [
      [1, 1, {"@type": "number", "range": {"gte": 2, "lt": 9}}],
      [2, 2, {"@type": "enum", "values": ["a", "b", "c"]}],
      [3, "Bob", {"@type": "assigned","value": "God"}],
      [4, {"name": "Alice"}, {"@type": "enum", "values": ["Boy", "Girl"]}]
    ],
    "default": {"@type": "void"}
  }
}

Definition

Base

JSON

Free Object (FO)

A Free Object is a JSON object where the value of any leaf field must be a Free Field.

e.g.

{
  "field_1": FF,
  "field_2": {
    field_2_1: FF,
    ...
  },
  ...
}

Free Field (FF)

A Free Field is a JSON object which contains a special @type field and other option fields required by the type.

e.g.

{
  "@type": ...,
  "option_1": ...,
  "option_2": ...,
  ...
}

Types

"void"

Special type which means this field does not exist.

"assigned"

If a field is of this type, the value should be pre-assigned.

options:
  • value: any - the pre-assigned value.

"number"

Provide a number for this field.

options
  • integer?: bool = false - if true, the number should be an integer.
  • range: object - specify the range of the number, e.g. {gt: 1, lt: 10}. you must limit both the lower and upper boundaries. available limiters are:
    • gt - greater than
    • gte - greater than or equal
    • lt - less than
    • lte - less than or equal

"enum"

Select a value from given values.

options
  • values: array - all available values. cannot be empty.
  • weights?: array of number - weights of corresponding values.

notes

  • the default weight is 1.

"dependant"

The value of this field depends on other field(s).

options
  • dependsOn: array of string - the other FFs this field depends on. use dot format to reference a deep path. e.g. [outer.inner].
  • map: array of [key1, key2, ..., value] - decide the actual FF based on the actual values of the depended fields. the sub arrays each have n+1 items: the first n items, the map keys, are the values of depended fields; the last one is the expected FF.
  • default?: object - the default FF if the depended field value failed to match any item in the map. the default value is {"@type": "void"}.

notes

  • if the map key is an object, it will be compared deeply.
  • if the map key is null, it will match both null and undefined field.

Common Options

  • virtual?=: bool = false - if true, this field will not be present in the generated object.

License

MIT

random-object-language's People

Stargazers

Jinger Tang avatar Yao Zhao avatar

Watchers

James Cloos avatar Yao Zhao avatar

Forkers

zhaochong131

random-object-language's Issues

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.