@arrows/dispatch

中文文档
1.0.3发布于 2020/01/23ISCCommonJS近 30 天下载 23.5万

Functional dispatch library

原始使用文档
文档目录10 节
  1. Table of contents
  2. Introduction
  3. Installation
  4. API reference
  5. getType
  6. identity
  7. is
  8. isIn
  9. types
  10. License

arrows - dispatch

@arrows/dispatch

npm (scoped) CircleCI David (path) Codecov npm bundle size (scoped) GitHub

Table of contents

  1. Introduction
  2. Installation
  3. API reference
  4. License

Introduction

The library contains a collection of dispatch functions. All functions with the arity (number of arguments) greater than one are automatically curried, so a partial application is possible.

The library has built-in type definitions, which provide an excellent IDE support.

Installation

Via NPM:

npm i @arrows/dispatch

Via Yarn:

yarn add @arrows/dispatch

All modules can be imported independently (to reduce bundle size), here are some import methods (you can use either CommonJS or ES modules):

import dispatch from '@arrows/dispatch'
import { getType } from '@arrows/dispatch'
import getType from '@arrows/dispatch/getType'

API reference

getType

Retrieves the type of a value (using the internal [[Class]] property). A more useful alternative for the typeof operator.

It does not return custom prototypes - if you need that, use the is function instead.

See: types for the list of the most common values.

See: MDN - Object.prototype.toString.call

Parameters

  • value - Any value

Returns

  • Returns an underlying class as a string.

Interface

(value) => underlying_class_name

Example

getType(1) // -> "Number"
getType(/abc/) // -> "RegExp"
getType([1, 2, 3]) // -> "Array"

identity

Standard identity function - useful as a default dispatch or a placeholder.

Parameters

  • value - Any value

Returns

  • Returns the argument as-is.

Interface

(value) => value

Example

identity('foo') // -> "foo"
identity([1, 2, 3]) // -> [1, 2, 3]

is

Checks if a value is an instance of a prototype/class.

Parameters

  • prototype - A prototype/class with which you want to check the value.
  • value - Any value

Returns

  • Returns true is a value is an instance of a prototype/class, false otherwise.

Interface

(prototype, value) => boolean

Example

class Cat {}
class Dog {}

const cat = new Cat()
const dog = new Dog()

is(Cat, cat) // -> true
is(Dog, cat) // -> false

is(Cat)(cat) // -> true
is(Dog)(cat) // -> false

isIn

Checks if a value is inside an array/set.

Parameters

  • list - An array or a set of values
  • value - Any value

Returns

  • Returns true is a value is inside an array/set, false otherwise.

Interface

(array_or_set, value) => boolean

Examples

const names = ['Alice', 'Joe', 'John']

isIn(names, 'Alice') // -> true
isIn(names, 'Bob') // -> false

isIn(names)('Alice') // -> true
isIn(names)('Bob') // -> false
const names = new Set(['Alice', 'Joe', 'John'])

isIn(names, 'Alice') // -> true
isIn(names, 'Bob') // -> false

isIn(names)('Alice') // -> true
isIn(names)('Bob') // -> false

types

An object that contains a list of the most common types to use with the getType function. You can use it instead of using raw strings (which is error-prone).

Example

getType([1, 2, 3]) === types.Array // -> true

getType(() => null) === types.Function // -> true

getType(Promise.resolve()) === types.Promise // -> true

getType('1') === types.Number // -> false

License

Project is under open, non-restrictive ISC license.

版本与发布记录

@arrows/dispatch 共发布 10 个版本,首次发布于 2019/09/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.3latest2020/01/236 年前
1.0.22019/10/217 年前
1.0.12019/10/177 年前
1.0.02019/10/177 年前
0.2.52019/09/307 年前
0.2.42019/09/227 年前

关于 @arrows/dispatch 的常见问题

@arrows/dispatch 是什么?

Functional dispatch library

如何安装 @arrows/dispatch?

在项目目录运行 npm install @arrows/dispatch,或使用 pnpm add / yarn add / bun add。

@arrows/dispatch 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/arrows__dispatch 是否存在。

@arrows/dispatch 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@arrows/dispatch 可以商用吗?

@arrows/dispatch 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@arrows/dispatch 的下载量有多少?

根据 npm 官方下载统计,@arrows/dispatch 在 2026/10/07 – 2026/11/05 这 30 天内被下载 234,855 次,日均约 7,829 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@arrows/dispatch 还在维护吗?

最新版本 1.0.3 发布于 2020/01/23(6 年前);至今共发布 10 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/09/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。