Skip to main content
Works with
JSR Score
76%
Published
6 days ago (0.0.2)

denops-bind-params

This is a deno library to reserve and bind parameters for denops dispatcher.

This library provides bindDispatcher function to bind parameters for denops dispatcher. For example, if you want to bind parameters, you can write like this:

import { bindDispatcher } from "@kyoh86/denops-bind-params";
import { ensure, is } from "https://deno.land/x/unknownutil@v3.18.0/mod.ts";

export function main(denops: Denops) {
    denops.dispatcher = bindDispatcher({
      hello(uParams: unknown) {
        const {name, age} = uParams as is.ObjectOf({
            name: is.String,
            age: is.Number,
        });
        return `Hello, ${name}! You are ${age} years old.`;
      },

      goodbye(uParams: unknown) {
        const {name} = uParams as is.ObjectOf({
            name: is.String,
        });
        return `Goodbye, ${name}!`;
      },
    });
}

Then, users can reserve parameters for hello method like this:

:call denops#request("foo", "params:set-for-method", ["hello", {"name": "Alice", "age": 20}])

And users can call hello method without parameters like this:

:echo denops#request("foo", "hello")

It will show Hello, Alice! You are 20 years old..

Of course, users can call hello method with parameters like this:

:echo denops#request("foo", "hello", {"name": "Bob", "age": 18})

It will show Hello, Bob! You are 18 years old..

Users can also set one parameter for a method like this:

:call denops#request("foo", "params:set-for-method", ["hello", {"name": "Charlie"}])

or

:call denops#request("foo", "params:set-one", ["hello", "age", 16])

And also can set multiple parameters for multiple methods like this:

:call denops#request("foo", "params:set-all", [{"hello": {"name": "David"}}, {"goodbye": {"name": "Eve"}}])

If users want to set a default value for a parameter across methods, they can specify _ as a method name:

:call denops#request("foo", "params:set-for-method", ["_", {"name": "Frank"}])

Then, hello and goodbye methods will use name parameter as Frank by default. Of cource, users can override the default value like this:

:call denops#request("foo", "params:set-for-method", ["hello", {"name": "Grace"}])

Then, hello method will use name parameter as Grace.

License

MIT License

This software is released under the MIT License, see LICENSE.

Add Package

deno add @kyoh86/denops-bind-params

Import symbol

import * as mod from "@kyoh86/denops-bind-params";

Add Package

npx jsr add @kyoh86/denops-bind-params

Import symbol

import * as mod from "@kyoh86/denops-bind-params";

Add Package

yarn dlx jsr add @kyoh86/denops-bind-params

Import symbol

import * as mod from "@kyoh86/denops-bind-params";

Add Package

pnpm dlx jsr add @kyoh86/denops-bind-params

Import symbol

import * as mod from "@kyoh86/denops-bind-params";

Add Package

bunx jsr add @kyoh86/denops-bind-params

Import symbol

import * as mod from "@kyoh86/denops-bind-params";