UNPKG

1.07 kBJavaScriptView Raw
1import { DIFFERENCE, ROLLING } from '@analys/enum-difference-modes';
2import { timeseriesDifferential } from '@analys/table-timeseries-differential';
3import { timeseriesRolling } from '@analys/table-timeseries-rolling';
4import { NUM } from '@typen/enum-data-types';
5
6const differential = function ({
7 mode = DIFFERENCE,
8 dateLabel = 'date',
9 fields,
10 depth = 4,
11 mutate = true
12}) {
13 /** @type {Table} */
14 let table = this;
15
16 if (typeof mode === NUM) {
17 if (mode === DIFFERENCE) return timeseriesDifferential.call(table, {
18 dateLabel,
19 fields,
20 mutate
21 });
22 if (mode === ROLLING) return timeseriesRolling.call(table, {
23 dateLabel,
24 fields,
25 depth,
26 mutate
27 });
28 }
29
30 if (Array.isArray(mode)) {
31 if (mode.includes(DIFFERENCE)) table = timeseriesDifferential.call(table, {
32 dateLabel,
33 fields,
34 mutate
35 });
36 if (mode.includes(ROLLING)) table = timeseriesRolling.call(table, {
37 dateLabel,
38 fields,
39 depth,
40 mutate
41 });
42 }
43
44 return table;
45};
46
47export { differential };