Skip to main content
Home
This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
82%
Published
a year ago (0.0.3)

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.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@kyoh86/denops-bind-params

Import symbol

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

Import directly with a jsr specifier

import * as denops_bind_params from "jsr:@kyoh86/denops-bind-params";

Add Package

pnpm i jsr:@kyoh86/denops-bind-params
or (using pnpm 10.8 or older)
pnpm dlx jsr add @kyoh86/denops-bind-params

Import symbol

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

Add Package

yarn add jsr:@kyoh86/denops-bind-params
or (using Yarn 4.8 or older)
yarn dlx jsr add @kyoh86/denops-bind-params

Import symbol

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

Add Package

vlt install jsr:@kyoh86/denops-bind-params

Import symbol

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

Add Package

npx jsr add @kyoh86/denops-bind-params

Import symbol

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

Add Package

bunx jsr add @kyoh86/denops-bind-params

Import symbol

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