flow-launcher-helper
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import { IFlow, JSONRPCResponse, MethodsObj, Params } from './types'; | ||
import { FlowParameters, IFlow, JSONRPCResponse, MethodsObj, MethodsObjGeneric } from './types'; | ||
/** | ||
@@ -9,3 +9,3 @@ * A class that helps in the communication between the Flow Launcher app and a plugin. | ||
*/ | ||
declare class Flow<TMethods, TSettings = Record<string, string>> implements IFlow<TMethods, TSettings> { | ||
declare class Flow<TMethods extends MethodsObjGeneric, TSettings = Record<string, string>> implements IFlow<TMethods, TSettings> { | ||
private methods; | ||
@@ -24,3 +24,3 @@ private defaultIconPath; | ||
*/ | ||
get method(): import("./types").Methods<TMethods> extends string ? string & import("./types").Methods<TMethods> : import("./types").JSONRPCMethods | (string & {}); | ||
get method(): import("./types").Methods<TMethods>; | ||
/** | ||
@@ -34,7 +34,7 @@ * Use the `param` argument in the `callbackFn` of the `on` method instead, or the `requestParams` method. | ||
/** | ||
* If there is only a parameter of primitive type, returns it, otherwise returns an array of parameters. | ||
* Returns the array of parameters sent from Flow Launcher. | ||
* | ||
* @readonly | ||
*/ | ||
get requestParams(): string | number | boolean | import("./types").FlowParameters; | ||
get requestParams(): FlowParameters; | ||
/** | ||
@@ -52,3 +52,3 @@ * @readonly | ||
*/ | ||
on<T extends Params>(method: keyof MethodsObj<TMethods>, callbackFn: (params: T) => void): void; | ||
on<T extends FlowParameters>(method: keyof MethodsObj<TMethods>, callbackFn: (params: T) => void): void; | ||
/** | ||
@@ -55,0 +55,0 @@ * Takes a JSONRPCResponse object and returns a Result object |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Flow = void 0; | ||
function isPrimitive(value) { | ||
return (typeof value == 'string' || | ||
typeof value == 'number' || | ||
typeof value == 'boolean'); | ||
} | ||
/** | ||
@@ -48,3 +43,3 @@ * A class that helps in the communication between the Flow Launcher app and a plugin. | ||
/** | ||
* If there is only a parameter of primitive type, returns it, otherwise returns an array of parameters. | ||
* Returns the array of parameters sent from Flow Launcher. | ||
* | ||
@@ -54,6 +49,2 @@ * @readonly | ||
get requestParams() { | ||
const firstParam = this.data.parameters[0]; | ||
const hasJustOneItem = this.data.parameters.length == 1; | ||
if (hasJustOneItem && isPrimitive(firstParam)) | ||
return firstParam; | ||
return this.data.parameters; | ||
@@ -60,0 +51,0 @@ } |
@@ -5,11 +5,11 @@ type PrependFlowLauncher<Method> = Method extends string ? `Flow.Launcher.${Method}` : never; | ||
export type Methods<T> = JSONRPCMethods | T; | ||
export type MethodsObj<TMethods> = { | ||
[key in Methods<TMethods> extends string ? Methods<TMethods> : // eslint-disable-next-line @typescript-eslint/ban-types | ||
JSONRPCMethods | (string & {})]: (params: any) => void; | ||
export type MethodsObjGeneric = string & {}; | ||
export type MethodsObj<TMethods extends MethodsObjGeneric> = { | ||
[key in Methods<TMethods>]: (params: any) => void; | ||
}; | ||
export type ParametersAllowedTypes = string | number | boolean | Record<string, unknown> | ParametersAllowedTypes[]; | ||
export type Method<T> = keyof MethodsObj<T>; | ||
export type Method<T extends MethodsObjGeneric> = keyof MethodsObj<T>; | ||
export type FlowParameters = ParametersAllowedTypes[]; | ||
export type Params = FlowParameters | string | number | boolean; | ||
export interface Data<TMethods, TSettings> { | ||
export interface Data<TMethods extends MethodsObjGeneric, TSettings> { | ||
method: Method<TMethods>; | ||
@@ -19,3 +19,3 @@ parameters: FlowParameters; | ||
} | ||
export interface JSONRPCResponse<TMethods> { | ||
export interface JSONRPCResponse<TMethods extends MethodsObjGeneric> { | ||
title: string; | ||
@@ -29,3 +29,3 @@ subtitle?: string; | ||
} | ||
export interface Result<TMethods> { | ||
export interface Result<TMethods extends MethodsObjGeneric> { | ||
Title: string; | ||
@@ -41,8 +41,8 @@ Subtitle?: string; | ||
} | ||
export type ShowResult<TMethods> = (...results: JSONRPCResponse<TMethods>[]) => void; | ||
export type On<TMethods> = (method: Method<TMethods>, callbackFn: (params: Params) => void) => void; | ||
export interface IFlow<TMethods, TSettings> { | ||
export type ShowResult<TMethods extends MethodsObjGeneric> = (...results: JSONRPCResponse<TMethods>[]) => void; | ||
export type On<TMethods extends MethodsObjGeneric> = (method: Method<TMethods>, callbackFn: (params: Params) => void) => void; | ||
export interface IFlow<TMethods extends MethodsObjGeneric, TSettings> { | ||
method: Method<TMethods>; | ||
params: string; | ||
requestParams: Params; | ||
requestParams: FlowParameters; | ||
settings: TSettings; | ||
@@ -53,3 +53,3 @@ on: On<TMethods>; | ||
} | ||
export interface IFlowPrivate<TMethods = unknown, TSettings = unknown> extends IFlow<TMethods, TSettings> { | ||
export interface IFlowPrivate<TMethods extends MethodsObjGeneric = string & {}, TSettings = unknown> extends IFlow<TMethods, TSettings> { | ||
methods: MethodsObj<TMethods>; | ||
@@ -56,0 +56,0 @@ defaultIconPath: string | undefined; |
{ | ||
"name": "flow-launcher-helper", | ||
"version": "2.2.0-beta.3", | ||
"version": "2.2.0", | ||
"description": "A simple lib to help build plugins for Flow Launcher", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -18,7 +18,7 @@ <h1 align="center">Flow Launcher Helper</h1> | ||
const { params, on, showResult, run } = new Flow(); | ||
const { on, showResult, run } = new Flow(); | ||
on('query', () => { | ||
on('query', (params) => { | ||
showResult({ | ||
title: 'Hello World Typescript', | ||
title: 'Hello World', | ||
subtitle: `Showing your query parameters: ${params}. Click to open Flow's website`, | ||
@@ -48,8 +48,10 @@ method: 'do_something_for_query', | ||
- `method` — `string`: current method. | ||
- `params` — `string`: current parameters. | ||
- `requestParams` - `FlowParameters`: array of parameters sent from Flow. | ||
- `settings` — `object`: plugin settings. | ||
- `on` — `function`: receives a method (string) and a callback function that will be executed when the method matches the current method. | ||
- `showResult` — `function`: receives an array of results, where you specify the title, subtitle, method, params and icon path, and logs the data to be displayed in Flow. | ||
- `on` — `(params: T extends FlowParameters) => void`: receives a method (string) and a callback function that will be executed when the method matches the current method. | ||
- `showResult` — `(...results: JSONRPCResponse<TMethods>[]) => void`: receives an array of results, where you specify the title, subtitle, method, params and icon path, and logs the data to be displayed in Flow. | ||
- `run` — `function`: runs the current method. You should call this function at the end of your script, or after all the `on` functions have been called. | ||
- ~~`params` — `string`: current parameters.~~ | ||
- Note: it is no longer recommended to get the params from this method, as it returns only the first parameter as a string. | ||
##### Typescript | ||
@@ -56,0 +58,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
-100%76
2.7%13939
-0.85%235
-3.69%