UNPKG

1.66 kBJavaScriptView Raw
1'use strict'
2
3// Note: this file is here purely for generation of documentation for `math.typed`
4
5function factory (type, config, load, typed, math) {
6 /**
7 * Create a typed-function which checks the types of the arguments and
8 * can match them against multiple provided signatures. The typed-function
9 * automatically converts inputs in order to find a matching signature.
10 * Typed functions throw informative errors in case of wrong input arguments.
11 *
12 * See the library [typed-function](https://github.com/josdejong/typed-function)
13 * for detailed documentation.
14 *
15 * Syntax:
16 *
17 * math.typed(name, signatures) : function
18 * math.typed(signatures) : function
19 *
20 * Examples:
21 *
22 * // create a typed function with multiple types per argument (type union)
23 * const fn2 = typed({
24 * 'number | boolean': function (b) {
25 * return 'b is a number or boolean'
26 * },
27 * 'string, number | boolean': function (a, b) {
28 * return 'a is a string, b is a number or boolean'
29 * }
30 * })
31 *
32 * // create a typed function with an any type argument
33 * const log = typed({
34 * 'string, any': function (event, data) {
35 * console.log('event: ' + event + ', data: ' + JSON.stringify(data))
36 * }
37 * })
38 *
39 * @param {string} [name] Optional name for the typed-function
40 * @param {Object<string, function>} signatures Object with one or multiple function signatures
41 * @returns {function} The created typed-function.
42 */
43 return typed
44}
45
46exports.name = 'typed'
47exports.factory = factory