Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jimmytuc/datran-es6

My custom datran module rewrite in ES6 babel npm package boilerplate
https://github.com/jimmytuc/datran-es6

Last synced: 17 days ago
JSON representation

My custom datran module rewrite in ES6 babel npm package boilerplate

Awesome Lists containing this project

README

        

[![Build Status](https://travis-ci.org/jimmytuc/datran-es6.svg?branch=master)](https://travis-ci.org/jimmytuc/datran-es6)

Thanks to NodeJS module generator/boilerplate.

## Features

- [**Babel**](https://babeljs.io/) - Write next generation JavaScript today;
- [**Jest**](https://facebook.github.io/jest) - JavaScript testing framework used by Facebook;
- [**ESLint**](http://eslint.org/) - Make sure you are writing a quality code;
- [**Prettier**](https://prettier.io/) - Enforces a consistent style by parsing your code and re-printing it;
- [**Flow**](https://flowtype.org/) - A static type checker for JavaScript used heavily within Facebook;
- [**Travis CI**](https://travis-ci.org) - Automate tests and linting for every push or pull request;
- [**Documentation**](http://documentation.js.org/) - A documentation system so good, you'll actually write documentation.

## Install

The easiest way to use **nod** is through the `npm`.

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

## Commands

```sh
$ 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](#serializer)
- [parser](#parser)
- [scope](#scope)
- [serialize](#serialize)
- [create](#create)
- [item](#item)
- [collection](#collection)
- [Parser](#parser-1)
- [separator](#separator)
- [includes](#includes)
- [excludes](#excludes)
- [parameters](#parameters)
- [parse](#parse)
- [constructor](#constructor)
- [createScope](#createscope)
- [isRoot](#isroot)
- [isIncluded](#isincluded)
- [isExcluded](#isexcluded)
- [getPath](#getpath)
- [getIdentifier](#getidentifier)
- [toPath](#topath)
- [serializer](#serializer-1)
- [collection](#collection-1)
- [item](#item-1)
- [empty](#empty)
- [embedIncludes](#embedincludes)
- [item](#item-2)
- [collection](#collection-2)
- [hasIncludes](#hasincludes)
- [create](#create-1)

### 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](#parser)**

### constructor

Constructor

**Parameters**

- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** includes: Requested includes (optional, default `{}`)

### createScope

Creates a child scope that is
nested from current scope

**Parameters**

- `identifier` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Child scope identifier
- `resource` **any** Instance of resource type

Returns **Scope**

### isRoot

Checks if this scope is the root scope

Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/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](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/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](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/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](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**

### create

Creates a new transformer blueprint using object pattern


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

**Parameters**

- `proto` **any**

## License

MIT © [Diego Haz](https://github.com/diegohaz)