2.1.0 • Published 6 years ago

piton v2.1.0

Weekly downloads
46
License
MIT
Repository
-
Last release
6 years ago

Piton.js

Build Status

A Piton

Piton.js builds a consistent platform on which to use data retrieved from a JSON-LD Resful API.

Piton supports a Promise-based interface for loading JSON Linked Data documents and expanding links.

Usage

processAPIResponse (obj, definitions [, hops])

obj - {} Object to process.

definitions - {} Schema definitions object

hops - Number Optional Max number of hops to populate in the graph

Returns Promise containing JSON representation of object

Schema

A schema object is used to map JSON-LD 'types' to a set of transforms.

Statics

These are used as a prototype for the resulting object. Useful for adding strings to an object. Also used for defining default types for other properties. By setting a static with an array value any result pulled from props will also be an array.

Props

Props are key, value pairs of what to dynamically pull from the API result. These support JS dot notation and any other accessor method supported by Lodash 'get()'.

Required

The final processing of the resulting objects is to check if there's a value for every field name in the required array. Throws Error if not.

"http://environment.data.gov.uk/catchment-planning/def/water-framework-directive/RiverBasinDistrict": {
  "statics": {
    "slug": "RiverBasinDistrict",
    "measures": []
  },
  "props": {
    "label": "label",
    "notation": "notation",
    "measures": "measures"
  },
  "required": ["label", "notation", "slug", "type"]
}

Why

This was developed to provide a consistent representation of a JSON-LD API. Especially useful in a 'dumb json' templating environment like Vue JS.

2.1.0

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago

4.0.0

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.1.0

6 years ago