datran-es6 v0.1.6
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
- Test method: Switch from
jest
tomocha
, fixed async/await to run test in mocha.
API
Table of Contents
- serializer
- parser
- scope
- serialize
- create
- item
- collection
- Parser
- constructor
- createScope
- isRoot
- isIncluded
- isExcluded
- getPath
- getIdentifier
- toPath
- serializer
- item
- collection
- hasIncludes
- create
serializer
Output serializer & composer
parser
Field parser
scope
Root scope
serialize
Parameters
data
anyscope
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
anytransformer
any
collection
Creates a collection resource
Parameters
model
anytransformer
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 identifierresource
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
anydata
any
item
Serializes a resource item
Parameters
key
anydata
any
empty
Serialize an empty resource
Returns Object
embedIncludes
Embeds the includes data to the transformed data
Parameters
data
anyincludeData
any
item
Helper for creating an Item resource
Parameters
model
anytransformer
any
collection
Helper for creating a Collection resource
Parameters
model
anytransformer
any
hasIncludes
Checks if the transformer has any includes defined
Returns Boolean
create
Creates a new transformer blueprint using object pattern
Parameters
proto
any
License
MIT © Diego Haz