Skip to content

Latest commit

 

History

History
42 lines (28 loc) · 1.15 KB

cerebro-tools.md

File metadata and controls

42 lines (28 loc) · 1.15 KB

Pluginscerebro-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.

Search

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);

Memoize

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.

shellCommand

It is just promise-wrapper for require('child_process').exec:

const { shellCommand } = require('cerebro-tools');

const result = shellCommand('ls ./').then(output => console.log(output));