New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

yayson

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yayson

A library for serializing and reading JSON API standardized data in JavaScript.

  • 1.0.5
  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.9K
decreased by-3.05%
Maintainers
2
Weekly downloads
 
Created
Source

YAYSON

A library for serializing and reading JSON API standardized data in JavaScript.

Presenting data

A basic Presenter can look like this:

  Presenter = require('yayson').presenter()

  class ItemPresenter extends Presenter
    name: 'item'

    attributes: ->
      attrs = super
      attrs.start = moment.utc(attrs.start).toDate()
      attrs

    serialize: ->
      event: EventPresenter

  presenter = new ItemPresenter()
  presenter.present(item)

In JavaScript this would be done as:


var Presenter = require('yayson').presenter()

var ItemPresenter = function () { Presenter.call(this); }
ItemPresenter.prototype = new Presenter()

ItemPresenter.prototype.name = 'item'

ItemPresenter.prototype.attributes = function() {
  var attrs = Presenter.prototype.attributes.apply(this, arguments);

  attrs.start = moment.utc(attrs.start).toDate();
  return attrs;
}

ItemPresenter.prototype.serialize = function() {
  return {
    event: EventPresenter
  }
}

var presenter = new ItemPresenter()
var json = presenter.toJSON(item)

By default it is set up to handle standard JS objects. You can also make it handle Sequalize.js models like this:

Presenter = require('yayson').presenter(adapter: 'sequelize')

Parsing data

You can use a Store can like this:


    store = new yayson.Store types:
      'events': 'event'
      'tickets': 'ticket'

    adapter.get(path: '/events/' + id).then (data) ->
      store.retrive('event', data)

This will give you the parsed event with all its tickets.

Use in the browser

Copy the file dist/yayson.js to your project. Then simply include it:

    <script src="./lib/yayson.js"></script>

Then you can var yayson = require('yayson') use the yayson.Presenter and yayson.Store as usual. IN THE BROWSER! OMG!!

Browser support

Tested

Chrome Firefox Safari Safari iOS

Untested, but should work

IE 9+ Android

Keywords

FAQs

Package last updated on 20 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc