datran-es6

0.1.6 • Public • Published

Build Status

Thanks to NodeJS module generator/boilerplate.

Features

  • Babel - Write next generation JavaScript today;
  • Jest - JavaScript testing framework used by Facebook;
  • ESLint - Make sure you are writing a quality code;
  • Prettier - Enforces a consistent style by parsing your code and re-printing it;
  • Flow - A static type checker for JavaScript used heavily within Facebook;
  • Travis CI - Automate tests and linting for every push or pull request;
  • Documentation - A documentation system so good, you'll actually write documentation.

Install

The easiest way to use nod is through the npm.

$ npm install datran-es6 --save # or yarn add datran-es6

Commands

$ npm test # run tests with Jest
$ npm run coverage # run tests with coverage and open it on browser
$ npm run lint # lint code
$ npm run docs # generate docs
$ npm run build # generate docs and transpile code
$ npm run watch # watch code changes and run scripts automatically
$ npm run patch # bump patch version and publish to npm e.g. 0.0.1
$ npm run minor # bump minor version and publish to npm e.g. 0.1.0
$ npm run major # bump major version and publish to npm e.g. 1.0.0

Change logs

  1. Test method: Switch from jest to mocha, fixed async/await to run test in mocha.

API

Table of Contents

serializer

Output serializer & composer

parser

Field parser

scope

Root scope

serialize

Parameters

  • data any
  • scope any {identifier, resource}
    • scope.identifier
    • scope.resource

This function says hello.

Parameters

  • name Some name to say hello for.

Returns any The hello.

create

Parameters

  • resourceType
  • options any Optional parameters- exlcudes: Exclude string (eg req.query.exclude)
    • includes: Include string (eg req.query.include)
    • serializer
    • parser (optional, default {})
  • resource any instance of the resource type (Collection|Item)

item

Creates an item resource

Parameters

  • model any
  • transformer any

collection

Creates a collection resource

Parameters

  • model any
  • transformer any

Parser

Fields parser

Format

  • post,post.comments,post.author
  • post:limit(5):order(created_at|desc),-post.comments
  • post,-votes

Parameters

  • fields

separator

Character used to separate parameters

includes

Included fields

excludes

Fields to exclude

parameters

Included fields paramters

parse

Parses includes and exclude fields

Returns Parser

constructor

Constructor

Parameters

  • options Object includes: Requested includes (optional, default {})

createScope

Creates a child scope that is nested from current scope

Parameters

  • identifier String Child scope identifier
  • resource any Instance of resource type

Returns Scope

isRoot

Checks if this scope is the root scope

Returns Boolean

isIncluded

Checks if an identifier is included from current scope

Parameters

  • identifier any

isExcluded

Checks if an identifier is excluded from current scope

Parameters

  • identifier any

getPath

Gets the scope identifier path

Returns String

getIdentifier

Get scope (include) identifier

Returns any scope identifier

toPath

Parameters

  • includeIdentifier any

serializer

Default Serializer

collection

Serializes a collection

Parameters

  • key any
  • data any

item

Serializes a resource item

Parameters

  • key any
  • data any

empty

Serialize an empty resource

Returns Object

embedIncludes

Embeds the includes data to the transformed data

Parameters

  • data any
  • includeData any

item

Helper for creating an Item resource

Parameters

  • model any
  • transformer any

collection

Helper for creating a Collection resource

Parameters

  • model any
  • transformer any

hasIncludes

Checks if the transformer has any includes defined

Returns Boolean

create

Creates a new transformer blueprint using object pattern

const MyTransformer = Transformer.create({ transform () {} })

Parameters

  • proto any

License

MIT © Diego Haz

Package Sidebar

Install

npm i datran-es6

Weekly Downloads

8

Version

0.1.6

License

MIT

Unpacked Size

40.8 kB

Total Files

25

Last publish

Collaborators

  • jimmypagesolo