1 |
|
2 |
|
3 | # Function import
|
4 |
|
5 | Import functions from an object or a module
|
6 |
|
7 |
|
8 | ## Syntax
|
9 |
|
10 | ```js
|
11 | math.import(object)
|
12 | math.import(object, options)
|
13 | ```
|
14 |
|
15 | ### Where
|
16 |
|
17 | - `object: Object`
|
18 | An object with functions to be imported.
|
19 | - `options: Object` An object with import options. Available options:
|
20 | - `override: boolean`
|
21 | If true, existing functions will be overwritten. False by default.
|
22 | - `silent: boolean`
|
23 | If true, the function will not throw errors on duplicates or invalid
|
24 | types. False by default.
|
25 | - `wrap: boolean`
|
26 | If true, the functions will be wrapped in a wrapper function
|
27 | which converts data types like Matrix to primitive data types like Array.
|
28 | The wrapper is needed when extending math.js with libraries which do not
|
29 | support these data type. False by default.
|
30 |
|
31 | ### Parameters
|
32 |
|
33 | Parameter | Type | Description
|
34 | --------- | ---- | -----------
|
35 | `object` | Object | Array | Object with functions to be imported.
|
36 | `options` | Object | Import options.
|
37 |
|
38 | ## Examples
|
39 |
|
40 | ```js
|
41 | // define new functions and variables
|
42 | math.import({
|
43 | myvalue: 42,
|
44 | hello: function (name) {
|
45 | return 'hello, ' + name + '!'
|
46 | }
|
47 | })
|
48 |
|
49 | // use the imported function and variable
|
50 | math.myvalue * 2 // 84
|
51 | math.hello('user') // 'hello, user!'
|
52 |
|
53 | // import the npm module 'numbers'
|
54 | // (must be installed first with `npm install numbers`)
|
55 | math.import(require('numbers'), {wrap: true})
|
56 |
|
57 | math.fibonacci(7) // returns 13
|
58 | ```
|
59 |
|
60 |
|