UNPKG

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