Comparing version 0.4.0 to 0.4.1
@@ -37,3 +37,3 @@ #!/usr/bin/env node | ||
const opts = { | ||
mode: normalMode ? 'normal' : 'fzf', | ||
mode: normalMode ? 'normal' : 'fuzzy', | ||
list: files | ||
@@ -55,3 +55,3 @@ } | ||
const opts = { | ||
mode: normalMode ? 'normal' : 'fzf', | ||
mode: normalMode ? 'normal' : 'fuzzy', | ||
list: [] // stdin will update it later | ||
@@ -58,0 +58,0 @@ } |
{ | ||
"name": "node-fzf", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "fzf ( junegunn/fzf ) inspired cli utility for node", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -24,5 +24,42 @@ [](https://www.npmjs.com/package/node-fzf) | ||
#### API usage | ||
##### promises | ||
```js | ||
const nfzf = require( 'node-fzf' ) | ||
const opts = { | ||
list: [ 'whale', 'giraffe', 'monkey' ] | ||
} | ||
;( async function () { | ||
// opens interactive selection CLI | ||
// note! this messes with stdout so if you are | ||
// writing to stdout at the same time it will look a bit messy.. | ||
const result = await nfzf( opts ) | ||
const { selected, query } = result | ||
if( !selected ) { | ||
console.log( 'No matches for:', query ) | ||
} else { | ||
console.log( selected.value ) // 'giraffe' | ||
console.log( selected.index ) // 1 | ||
console.log( selected.value === opts.list[ selected.index ] ) // true | ||
} | ||
} )() | ||
// can also add more items later.. | ||
setInterval( function () { | ||
opts.list.push( 'foobar' ) | ||
// an .update method has been attached to the object/array | ||
// that you gave to nfzf( ... ) | ||
opts.update( list ) | ||
}, 1000 ) | ||
``` | ||
##### callbacks | ||
```js | ||
const nfzf = require( 'node-fzf' ) | ||
const list = [ 'whale', 'giraffe', 'monkey' ] | ||
@@ -34,3 +71,3 @@ | ||
const api = nfzf( list, function ( result ) { | ||
const { selected, query } = result; | ||
const { selected, query } = result | ||
if( !selected ) { | ||
@@ -42,2 +79,7 @@ console.log( 'No matches for:', query ) | ||
console.log( selected.value === list[ selected.index ] ) // true | ||
// the api is a reference to the same argument0 object | ||
// with an added .update method attached. | ||
console.log( list === api ) // true | ||
console.log( list.update === api.update ) // true | ||
} | ||
@@ -52,6 +94,2 @@ | ||
}, 1000 ) | ||
// if you don't need the api returned by nfzf you can use | ||
// promises to await for the result only | ||
const result = await nfzf( list ) | ||
``` | ||
@@ -58,0 +96,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
30839
142
0