Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/defmulti

Package Overview
Dependencies
Maintainers
1
Versions
186
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/defmulti - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

27

api.d.ts
import { Fn, Fn2, Fn3, Fn4, Fn5, Fn6, Fn7, Fn8, FnAny, ILogger, IObjectOf } from "@thi.ng/api";
/**
* Unique symbol used for registering a default / fallback
* implementation.
*/
export declare const DEFAULT: unique symbol;

@@ -43,4 +47,4 @@ export declare type DispatchFn = FnAny<PropertyKey>;

*
* @param id
* @param impl
* @param id - implementation ID (dispatch value)
* @param impl - implementation
*/

@@ -54,3 +58,3 @@ add(id: PropertyKey, impl: I): boolean;

*
* @param impls
* @param impls - object of implementations
*/

@@ -62,3 +66,3 @@ addAll(impls: IObjectOf<I>): boolean;

*
* @param id
* @param id - implementation ID
*/

@@ -70,3 +74,3 @@ remove(id: PropertyKey): boolean;

*
* @param args
* @param args - arguments to find impl for
*/

@@ -83,4 +87,4 @@ callable(...args: any[]): boolean;

*
* @param id
* @param parent
* @param id - implementation ID
* @param parent -parent implementation ID
*/

@@ -98,9 +102,9 @@ isa(id: PropertyKey, parent: PropertyKey): boolean;

*
* @param id
* @param id - implementation ID
*/
parents(id: PropertyKey): Set<PropertyKey>;
/**
* Similar to `parents()`, but includes all transitive parent dispatch
* values for given dispatch value `id`.
* @param id
* Similar to {@link MultiFnBase.parents}, but includes all
* transitive parent dispatch values for given dispatch value `id`.
* @param id - implementation ID
*/

@@ -146,1 +150,2 @@ ancestors(id: PropertyKey): Set<PropertyKey>;

export declare const setLogger: (logger: ILogger) => ILogger;
//# sourceMappingURL=api.d.ts.map
import { NULL_LOGGER } from "@thi.ng/api";
/**
* Unique symbol used for registering a default / fallback
* implementation.
*/
export const DEFAULT = Symbol();
export let LOGGER = NULL_LOGGER;
export const setLogger = (logger) => (LOGGER = logger);

@@ -6,2 +6,10 @@ # Change Log

## [1.2.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/defmulti@1.2.1...@thi.ng/defmulti@1.2.2) (2020-01-24)
**Note:** Version bump only for package @thi.ng/defmulti
## [1.2.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/defmulti@1.2.0...@thi.ng/defmulti@1.2.1) (2019-11-30)

@@ -8,0 +16,0 @@

/**
* Returns a multi-dispatch function which delegates to one of the
* provided implementations, based on the arity (number of args) when
* the function is called. Internally uses `defmulti`, so new arities
* can be dynamically added (or removed) at a later time. If no
* `fallback` is provided, `defmultiN` also registers a `DEFAULT`
* implementation which simply throws an `IllegalArityError` when
* the function is called.
*
* @remarks
* Internally uses {@link (defmulti:1)}, so new arities can be dynamically
* added (or removed) at a later time. If no `fallback` is provided,
* `defmultiN` also registers a {@link DEFAULT} implementation which
* simply throws an {@link @thi.ng/errors#IllegalArityError} when
* invoked.
*
* **Note:** Unlike `defmulti` no argument type checking is supported,
* however you can specify the return type for the generated function.
* **Note:** Unlike {@link (defmulti:1)} no argument type checking is
* supported, however you can specify the return type for the generated
* function.
*
* ```
* @example
* ```ts
* const foo = defmultiN<string>({

@@ -34,4 +39,4 @@ * 0: () => "zero",

*
* @param impls
* @param fallback
* @param impls - implementations
* @param fallback - fallback implementation
*/

@@ -41,1 +46,2 @@ export declare const defmultiN: <T>(impls: {

}, fallback?: import("@thi.ng/api").FnAny<T> | undefined) => import("./api").MultiFn<T>;
//# sourceMappingURL=defmulti-n.d.ts.map

@@ -7,12 +7,17 @@ import { illegalArity } from "@thi.ng/errors";

* provided implementations, based on the arity (number of args) when
* the function is called. Internally uses `defmulti`, so new arities
* can be dynamically added (or removed) at a later time. If no
* `fallback` is provided, `defmultiN` also registers a `DEFAULT`
* implementation which simply throws an `IllegalArityError` when
* the function is called.
*
* @remarks
* Internally uses {@link (defmulti:1)}, so new arities can be dynamically
* added (or removed) at a later time. If no `fallback` is provided,
* `defmultiN` also registers a {@link DEFAULT} implementation which
* simply throws an {@link @thi.ng/errors#IllegalArityError} when
* invoked.
*
* **Note:** Unlike `defmulti` no argument type checking is supported,
* however you can specify the return type for the generated function.
* **Note:** Unlike {@link (defmulti:1)} no argument type checking is
* supported, however you can specify the return type for the generated
* function.
*
* ```
* @example
* ```ts
* const foo = defmultiN<string>({

@@ -38,4 +43,4 @@ * 0: () => "zero",

*
* @param impls
* @param fallback
* @param impls - implementations
* @param fallback - fallback implementation
*/

@@ -42,0 +47,0 @@ export const defmultiN = (impls, fallback) => {

import { AncestorDefs, DispatchFn, DispatchFn1, DispatchFn1O, DispatchFn2, DispatchFn2O, DispatchFn3, DispatchFn3O, DispatchFn4, DispatchFn4O, DispatchFn5, DispatchFn5O, DispatchFn6, DispatchFn6O, DispatchFn7, DispatchFn7O, DispatchFn8, DispatchFn8O, MultiFn, MultiFn1, MultiFn1O, MultiFn2, MultiFn2O, MultiFn3, MultiFn3O, MultiFn4, MultiFn4O, MultiFn5, MultiFn5O, MultiFn6, MultiFn6O, MultiFn7, MultiFn7O, MultiFn8, MultiFn8O } from "./api";
/**
* Returns a new multi-dispatch function using the provided dispatcher.
* Returns a new multi-dispatch function using the provided dispatch
* value function.
*
* @remarks
* The dispatcher can take any number of arguments and must produce a

@@ -38,1 +41,2 @@ * dispatch value (string, number or symbol) used to lookup an

export declare function defmulti<A, B, C, D, E, F, G, H, I, T>(f: DispatchFn8O<A, B, C, D, E, F, G, H, I>, rels?: AncestorDefs): MultiFn8O<A, B, C, D, E, F, G, H, I, T>;
//# sourceMappingURL=defmulti.d.ts.map

@@ -9,2 +9,3 @@ import { IObjectOf } from "@thi.ng/api";

*
* @remarks
* The relations object has dispatch values (parents) as keys and arrays

@@ -18,3 +19,4 @@ * of multi-methods as their values. For each multi-method associates

*
* ```
* @example
* ```ts
* foo = defmulti((x) => x.id);

@@ -56,5 +58,6 @@ * bar = defmulti((x) => x.id);

*
* @param type
* @param impls
* @param id - dispatch value / implementation ID
* @param impls - implementations
*/
export declare const implementations: (type: string | number | symbol, rels: IObjectOf<MultiFn<any>[]>, ...impls: (MultiFn<any> | import("@thi.ng/api").FnAny<any>)[]) => void;
export declare const implementations: (id: string | number | symbol, rels: IObjectOf<MultiFn<any>[]>, ...impls: (MultiFn<any> | import("@thi.ng/api").FnAny<any>)[]) => void;
//# sourceMappingURL=impls.d.ts.map

@@ -8,2 +8,3 @@ import { illegalArgs } from "@thi.ng/errors";

*
* @remarks
* The relations object has dispatch values (parents) as keys and arrays

@@ -17,3 +18,4 @@ * of multi-methods as their values. For each multi-method associates

*
* ```
* @example
* ```ts
* foo = defmulti((x) => x.id);

@@ -55,6 +57,6 @@ * bar = defmulti((x) => x.id);

*
* @param type
* @param impls
* @param id - dispatch value / implementation ID
* @param impls - implementations
*/
export const implementations = (type, rels, ...impls) => {
export const implementations = (id, rels, ...impls) => {
impls.length & 1 &&

@@ -65,3 +67,3 @@ illegalArgs("expected an even number of implementation items");

for (let fn of rels[parent]) {
fn.isa(type, parent);
fn.isa(id, parent);
}

@@ -71,4 +73,4 @@ }

for (let i = 0; i < impls.length; i += 2) {
impls[i].add(type, impls[i + 1]);
impls[i].add(id, impls[i + 1]);
}
};

@@ -5,1 +5,2 @@ export * from "./api";

export * from "./impls";
//# sourceMappingURL=index.d.ts.map

@@ -106,3 +106,3 @@ 'use strict';

const implementations = (type, rels, ...impls) => {
const implementations = (id, rels, ...impls) => {
impls.length & 1 &&

@@ -113,3 +113,3 @@ errors.illegalArgs("expected an even number of implementation items");

for (let fn of rels[parent]) {
fn.isa(type, parent);
fn.isa(id, parent);
}

@@ -119,3 +119,3 @@ }

for (let i = 0; i < impls.length; i += 2) {
impls[i].add(type, impls[i + 1]);
impls[i].add(id, impls[i + 1]);
}

@@ -122,0 +122,0 @@ };

{
"name": "@thi.ng/defmulti",
"version": "1.2.1",
"version": "1.2.2",
"description": "Dynamic, extensible multiple dispatch via user supplied dispatch function.",

@@ -26,17 +26,19 @@ "module": "./index.js",

"doc": "node_modules/.bin/typedoc --mode modules --out doc src",
"doc:ae": "mkdir -p .ae/doc .ae/temp && node_modules/.bin/api-extractor run --local --verbose",
"pub": "yarn build:release && yarn publish --access public"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^0.1.3",
"@types/mocha": "^5.2.6",
"@types/node": "^12.12.11",
"mocha": "^6.2.2",
"nyc": "^14.0.0",
"ts-node": "^8.5.2",
"typedoc": "^0.15.2",
"typescript": "^3.7.2"
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@microsoft/api-extractor": "^7.7.7",
"@types/mocha": "^5.2.7",
"@types/node": "^13.5.0",
"mocha": "^7.0.0",
"nyc": "^15.0.0",
"ts-node": "^8.6.2",
"typedoc": "^0.16.8",
"typescript": "^3.7.5"
},
"dependencies": {
"@thi.ng/api": "^6.6.0",
"@thi.ng/errors": "^1.2.2"
"@thi.ng/api": "^6.7.0",
"@thi.ng/errors": "^1.2.3"
},

@@ -54,3 +56,3 @@ "keywords": [

},
"gitHead": "36c4d9e967bd80ccdbfa0f4a42f594080f95f105"
"gitHead": "93d8af817724c1c5b06d80ffa2492fe5b4fb7bc4"
}

@@ -18,8 +18,8 @@ <!-- This file is generated - DO NOT EDIT! -->

- [API](#api)
- [defmulti()](#defmulti--)
- [defmulti()](#defmulti)
- [Dispatch value hierarchies](#dispatch-value-hierarchies)
- [implementations()](#implementations--)
- [defmultiN()](#defmultin--)
- [implementations()](#implementations)
- [defmultiN()](#defmultin)
- [Usage examples](#usage-examples)
- [Dynamic dispatch: Simple S-expression interpreter](#dynamic-dispatch--simple-s-expression-interpreter)
- [Dynamic dispatch: Simple S-expression interpreter](#dynamic-dispatch-simple-s-expression-interpreter)
- [True multiple arg dispatch](#true-multiple-arg-dispatch)

@@ -47,6 +47,8 @@ - [Authors](#authors)

Package sizes (gzipped): ESM: 0.7KB / CJS: 0.8KB / UMD: 0.8KB
## Dependencies
- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/master/packages/api)
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/master/packages/errors)
- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)

@@ -56,3 +58,3 @@ ## Usage examples

Several demos in this repo's
[/examples](https://github.com/thi-ng/umbrella/tree/master/examples)
[/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
directory are using this package.

@@ -64,3 +66,3 @@

[Live demo](https://demo.thi.ng/umbrella/rstream-spreadsheet/) | [Source](https://github.com/thi-ng/umbrella/tree/master/examples/rstream-spreadsheet)
[Live demo](https://demo.thi.ng/umbrella/rstream-spreadsheet/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rstream-spreadsheet)

@@ -218,3 +220,3 @@ ## API

Also see the WIP package
[@thi.ng/geom](https://github.com/thi-ng/umbrella/tree/master/packages/geom)
[@thi.ng/geom](https://github.com/thi-ng/umbrella/tree/develop/packages/geom)
for a concreate realworld usage example.

@@ -278,3 +280,3 @@

See
[/test/index.ts](https://github.com/thi-ng/umbrella/tree/master/packages/defmulti/test/index.ts)
[/test/index.ts](https://github.com/thi-ng/umbrella/tree/develop/packages/defmulti/test/index.ts)
for a variation of this example.

@@ -329,2 +331,2 @@

&copy; 2018 - 2019 Karsten Schmidt // Apache Software License 2.0
&copy; 2018 - 2020 Karsten Schmidt // Apache Software License 2.0

@@ -34,2 +34,4 @@ # ${pkg.name}

${pkg.size}
## Dependencies

@@ -192,3 +194,3 @@

Also see the WIP package
[@thi.ng/geom](https://github.com/thi-ng/umbrella/tree/master/packages/geom)
[@thi.ng/geom](https://github.com/thi-ng/umbrella/tree/develop/packages/geom)
for a concreate realworld usage example.

@@ -252,3 +254,3 @@

See
[/test/index.ts](https://github.com/thi-ng/umbrella/tree/master/packages/defmulti/test/index.ts)
[/test/index.ts](https://github.com/thi-ng/umbrella/tree/develop/packages/defmulti/test/index.ts)
for a variation of this example.

@@ -255,0 +257,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc