Plugins → cerebro-tools
cerebro-tools
is a package to DRY your plugins code. Currently it includes only three functions: memoize
, search
and shellCommand
.
Later more functions and react components will be added.
Use this function to filter your collection by provided search term.
// Require from npm module
const { search } = require('cerebro-tools');
// Convert item from collection to string. Default is `(el) => el`
const toString = (el) => el.title;
// Search for `term` in your collection
const results = search(collection, term, toString);
Use this function to reduce calls to external APIs.
const { memoize } = require('cerebro-tools');
const fetchResults = require('path/to/fetchResults');
const cachedFetchResults = memoize(fetchResults)
Check out memoizee docs for more info.
How to share your plugin.
It is just promise-wrapper for require('child_process').exec
:
const { shellCommand } = require('cerebro-tools');
const result = shellCommand('ls ./').then(output => console.log(output));