Here we fetch some JSON from a placeholder API and present matching items to the user:
const arvish = require('arvish');
const getPluginItems = async ({ inputStr }) => {
const data = await arvish.fetch('https://jsonplaceholder.typicode.com/posts');
const items = arvish
.inputMatches(data, 'title')
.map(element => ({
title: element.title,
subtitle: element.body,
arg: element.id
}));
return arvish.output(items);
};
Type: string
Input from Arvis. What the user wrote in the input box.
Return output objects to Arvis
Note that usage are a little different from output
of workflow
Log value
to the debugger
Returns an string[]
of items in list
that case-insensitively contains input
.
arvish.matches('Corn', ['foo', 'unicorn']);
//=> ['unicorn']
Type: string
Text to match against the list
items.
Type: string[]
List to be matched against.
Type: string | Function
By default, it will match against the list
items.
Specify a string to match against an object property:
const list = [
{
title: 'foo'
},
{
title: 'bar'
}
];
arvish.matches('foo', list, 'title');
//=> [{title: 'foo'}]
Or nested property:
const list = [
{
name: {
first: 'John',
last: 'Doe'
}
},
{
name: {
first: 'Gil-dong',
last: 'Hong'
}
}
];
arvish.matches('gil-dong', list, 'name.first');
//=> [{name: {first: 'Gil-dong', last: 'Hong'}}]
Specify a function to handle the matching yourself. The function receives the list item and input, both lowercased, as arguments, and is expected to return a boolean of whether it matches:
const list = ['foo', 'bar'];
// Here we do an exact match.
// `Foo` matches the item since it's lowercased for you.
arvish.matches('Foo', list, (item, input) => item === input);
//=> ['foo']
Same as matches()
, but with arvish.input
as input
.
Display an error or error message in debugger.
Note: You don't need to .catch()
promises. Arvish handles that for you.
Type: Error | string
Error or error message to be displayed in devtools
.
Returns a Promise
that returns the body of the response.
Type: string
URL to fetch.
Type: object
Any of the got
options.
Type: boolean
Default: true
Parse response body with JSON.parse
and set accept
header to application/json
.
Type: number
Number of milliseconds this request should be cached.
Type: Function
Transform the response before it gets cached.
await arvish.fetch('https://api.foo.com', {
transform: body => {
body.foo = 'bar';
return body;
}
})
You can also return a Promise.
const xml2js = require('xml2js');
const pify = require('pify');
const parseString = pify(xml2js.parseString);
await arvish.fetch('https://api.foo.com', {
transform: body => parseString(body)
})
Type: object
Keys: 'info' | 'warning' | 'error' | 'alert' | 'like' | 'delete'
Get various default system icons.
The most useful ones are included as keys.
Type: object
Persist config data.
Exports a conf
instance with the correct config path set.
Example:
arvish.conf.set('unicorn', 'π¦');
arvish.conf.get('unicorn');
//=> 'π¦'
Type: () => object
Persist cache data.
Exports a modified conf
instance with the correct cache path set.
Example:
arvish.cache.set('unicorn', 'π¦');
arvish.cache.get('unicorn');
//=> 'π¦'
The set
method of this instance accepts an optional third argument where you can provide a maxAge
option. maxAge
is
the number of milliseconds the value is valid in the cache.
Example:
const delay = require('delay');
arvish.cache.set('foo', 'bar', {maxAge: 5000});
arvish.cache.get('foo');
//=> 'bar'
// Wait 5 seconds
await delay(5000);
arvish.cache.get('foo');
//=> undefined
Type: object
Example:
{
name: 'some_extension_name',
version: '0.0.1',
bundleId: 'some_extension_bundleId',
type: 'plugin'
}
Recommended location for non-volatile data. Just use arvish.config
which uses this path.
Recommended location for volatile data. Just use arvish.cache
which uses this path.
Path for saving the action logs and query logs.
User's home directory.
Directory where crash dumps are stored.
The current user's Desktop directory.
Directory for a user's "My Documents".
Directory for a user's "Downloads".
The current executable file.
Directory for a user's music.
Directory for a user's pictures.
Temporary directory
The directory for storing your app's configuration files, which by default it is the appData directory appended with your app's name.
Per-user application data directory, which by default points to