API Description mixins for Lodash based on the Refract API Description namespace
This library takes a lodash
instance and adds API Description mixins, which are the functions described below. These functions are usable and chainable just like any other Lodash function. Additionally, all Lodash functions are available here.
It is recommended to use these functions and other Lodash functions when interacting with Refract because you get some safety when chaining and looking for data.
Takes a Refract element and returns its content, which MAY be of any JavaScript type.
// Returns an array with the resource element
_.content({
element: 'category',
content: [
{
element: 'resource',
content: []
}
]
});
Takes any value and checks if it is Refract element. If it is Refract element then returns its content, which MAY be of any JavaScript type. Otherwise returns value itself.
// Returns passed value
_.contentOrValue('primitive value');
// Returns array with the resource element
_.contentOrValue({
element: 'category',
content: [
{
element: 'resource',
content: []
}
]
});
Takes a Refract element and returns an array of all dataStructure
elements found in the content.
// Returns array including the one dataStructure element in content
_.dataStructures({
element: 'category',
content: [
{
element: 'dataStructure',
content: []
}
]
});
Takes a Refract element and returns an array of all resource
elements found in the content.
// Returns array including the one resource element in content
_.resources({
element: 'category',
content: [
{
element: 'resource',
content: []
}
]
});
Takes a Refract element and returns an array of all transition
elements found in the content.
// Returns array including the one transition element in content
_.transitions({
element: 'resource',
content: [
{
element: 'transition',
content: []
}
]
});
Takes a Refract element and returns an array of all copy
elements found in the content.
// Returns array including the one copy element in content
_.copy({
element: 'category',
content: [
{
element: 'copy',
content: 'Copy text here'
}
]
});
Takes a Refract element and returns an array of all httpTransaction
elements found in the content.
// Returns array including the one httpTransaction element in content
_.httpTransaction({
element: 'transition',
content: [
{
element: 'httpTransaction',
content: []
}
]
});
Takes a Refract element and returns an array of all httpRequest
elements found in the content.
// Returns array including the one httpRequest element in content
_.httpRequests({
element: 'transaction',
content: [
{
element: 'httpRequest',
content: []
}
]
});
Takes a Refract element and returns an array of all httpResponse
elements found in the content.
// Returns array including the one httpResponse element in content
_.httpResponses({
element: 'transaction',
content: [
{
element: 'httpResponse',
content: []
}
]
});
Takes a Refract element and returns an array of all messageBody
elements found in the content.
// Returns array including the one messageBody element in content
_.messageBodies({
element: 'httpRequest',
content: [
{
element: 'asset',
meta: {
classes: ['messageBody']
}
content: 'Body here'
}
]
});
Takes a Refract element and returns an array of all messageBodySchema
elements found in the content.
// Returns array including the one messageBodySchema element in content
_.messageBodySchemas({
element: 'httpRequest',
content: [
{
element: 'asset',
meta: {
classes: ['messageBodySchema']
}
content: 'Body Schema here'
}
]
});
Takes a Refract element and filter condition, gets its content, and filters it.
// Returns array including the one messageBodySchema element in content
_.filterContent({
element: 'httpRequest',
content: [
{
element: 'asset',
meta: {
classes: ['messageBodySchema']
}
content: 'Body Schema here'
},
{
element: 'copy',
content: 'Copy text here.'
}
]
}, {element: 'asset'});
npm install lodash-api-description --save
If you are using this library in a project of yours, we recommend loading Lodash in its own module, using runInContext
, and adding mixins. Your module would look like:
// utils.js
var lodash = require('lodash').runInContext(); // creates a copy of lodash
var apiDescriptionMixins = require('lodash-api-description');
apiDescriptionMixins(lodash); // adds API Description mixins
module.exports = lodash;
Then when using this functionality in your project, you can do the following:
// Requiring custom lodash from another file
var lodash = require('./utils.js');
This prevents you from adding mixins to Lodash for entire project.
$ npm install
$ npm test
MIT (see LICENSE
file)
Apiary Inc. support@apiary.io