Skip to content

Commit a6949da

Browse files
authored
use named imports from mathjs to reduce bundle size (#235)
1 parent 65d5b83 commit a6949da

File tree

4 files changed

+25
-35
lines changed

4 files changed

+25
-35
lines changed

src/exports.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export * from './ready';
2-
export * from './math';
32

43
export * from './keri/app/habery';
54
export * from './keri/app/controller';

src/keri/core/tholder.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { BexDex, Matter, NumDex } from './matter';
22
import { CesrNumber } from './number';
3-
import { Fraction } from 'mathjs';
4-
import { math } from '../../index';
3+
import { Fraction, format, sum, fraction } from 'mathjs';
54

65
export class Tholder {
76
private _weighted: boolean = false;
@@ -45,9 +44,9 @@ export class Tholder {
4544
let sith = this.thold.map((clause: Fraction[]) => {
4645
return clause.map((c) => {
4746
if (0 < Number(c) && Number(c) < 1) {
48-
return math.format(c, { fraction: 'ratio' });
47+
return format(c, { fraction: 'ratio' });
4948
} else {
50-
return math.format(c, { fraction: 'decimal' });
49+
return format(c, { fraction: 'decimal' });
5150
}
5251
});
5352
});
@@ -159,7 +158,7 @@ export class Tholder {
159158

160159
private _processWeighted(thold: Array<Array<Fraction>>) {
161160
for (const clause of thold) {
162-
if (Number(math.sum(clause)) < 1) {
161+
if (Number(sum(clause)) < 1) {
163162
throw new Error(
164163
'Invalid sith clause: ' +
165164
thold +
@@ -178,7 +177,7 @@ export class Tholder {
178177
}
179178

180179
private weight(w: string): Fraction {
181-
return math.fraction(w);
180+
return fraction(w);
182181
}
183182

184183
private _satisfy_numeric(indices: any[]) {

src/math.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/core/tholder.test.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { strict as assert } from 'assert';
2+
import { fraction } from 'mathjs';
23
import { Tholder } from '../../src/keri/core/tholder';
3-
import { math } from '../../src';
44

55
describe('THolder', () => {
66
it('should hold thresholds', async () => {
@@ -66,11 +66,11 @@ describe('THolder', () => {
6666
assert.equal(tholder.size, 5);
6767
assert.deepStrictEqual(tholder.thold, [
6868
[
69-
math.fraction('1/2'),
70-
math.fraction('1/2'),
71-
math.fraction('1/4'),
72-
math.fraction('1/4'),
73-
math.fraction('1/4'),
69+
fraction('1/2'),
70+
fraction('1/2'),
71+
fraction('1/4'),
72+
fraction('1/4'),
73+
fraction('1/4'),
7474
],
7575
]);
7676
assert.equal(tholder.satisfy([0, 1]), true);
@@ -96,13 +96,8 @@ describe('THolder', () => {
9696
['1/3', '1/3', '1/3', '1/3'],
9797
]);
9898
assert.deepStrictEqual(tholder.thold, [
99-
[math.fraction(1, 2), math.fraction(1, 2), math.fraction(1, 2)],
100-
[
101-
math.fraction(1, 3),
102-
math.fraction(1, 3),
103-
math.fraction(1, 3),
104-
math.fraction(1, 3),
105-
],
99+
[fraction(1, 2), fraction(1, 2), fraction(1, 2)],
100+
[fraction(1, 3), fraction(1, 3), fraction(1, 3), fraction(1, 3)],
106101
]);
107102
assert.equal(tholder.satisfy([0, 2, 3, 5, 6]), true);
108103
assert.equal(tholder.satisfy([1, 2, 3, 4, 5]), true);
@@ -122,13 +117,13 @@ describe('THolder', () => {
122117
]);
123118
assert.deepStrictEqual(tholder.thold, [
124119
[
125-
math.fraction(1, 2),
126-
math.fraction(1, 2),
127-
math.fraction(1, 4),
128-
math.fraction(1, 4),
129-
math.fraction(1, 4),
120+
fraction(1, 2),
121+
fraction(1, 2),
122+
fraction(1, 4),
123+
fraction(1, 4),
124+
fraction(1, 4),
130125
],
131-
[math.fraction(1, 1), math.fraction(1, 1)],
126+
[fraction(1, 1), fraction(1, 1)],
132127
]);
133128
assert.equal(tholder.satisfy([1, 2, 3, 5]), true);
134129
assert.equal(tholder.satisfy([0, 1, 6]), true);
@@ -155,13 +150,13 @@ describe('THolder', () => {
155150
);
156151
assert.deepStrictEqual(tholder.thold, [
157152
[
158-
math.fraction(1, 2),
159-
math.fraction(1, 2),
160-
math.fraction(1, 4),
161-
math.fraction(1, 4),
162-
math.fraction(1, 4),
153+
fraction(1, 2),
154+
fraction(1, 2),
155+
fraction(1, 4),
156+
fraction(1, 4),
157+
fraction(1, 4),
163158
],
164-
[math.fraction(1, 1), math.fraction(1, 1)],
159+
[fraction(1, 1), fraction(1, 1)],
165160
]);
166161
assert.equal(tholder.satisfy([1, 2, 3, 5]), true);
167162
assert.equal(tholder.satisfy([0, 1, 6]), true);

0 commit comments

Comments
 (0)