UNPKG

850 BJavaScriptView Raw
1import {
2 create,
3 fractionDependencies,
4 addDependencies,
5 divideDependencies,
6 formatDependencies
7} from '../..'
8
9const config = {
10 // optionally, you can specify configuration
11}
12
13// Create just the functions we need
14const { fraction, add, divide, format } = create({
15 fractionDependencies,
16 addDependencies,
17 divideDependencies,
18 formatDependencies
19}, config)
20
21// Use the created functions
22const a = fraction(1, 3)
23const b = fraction(3, 7)
24const c = add(a, b)
25const d = divide(a, b)
26console.log('c =', format(c)) // outputs "c = 16/21"
27console.log('d =', format(d)) // outputs "d = 7/9"
28
29// Now, when bundling your application for use in the browser, only the used
30// parts of math.js will be bundled. For example to create a bundle using Webpack:
31//
32// npx webpack custom_loading.js -o custom_loading.bundle.js --mode=production
33//