@thi.ng/transducers-stats 2.2.2 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-11-24T18:15:49Z
3
+ - **Last updated**: 2024-12-24T14:04:06Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,18 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [2.2.4](https://github.com/thi-ng/umbrella/tree/@thi.ng/transducers-stats@2.2.4) (2024-12-24)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - replace [@thi.ng/dcons](https://github.com/thi-ng/umbrella/tree/main/packages/dcons) dependency ([e9940ed](https://github.com/thi-ng/umbrella/commit/e9940ed))
17
+ - switch to use more lightweight & GC-friendly ringbuffer impl from [@thi.ng/buffers](https://github.com/thi-ng/umbrella/tree/main/packages/buffers)
18
+ - update the following transducers:
19
+ - `momentum()`
20
+ - `roc()`
21
+ - `sma()`
22
+ - add tests
23
+
12
24
  ## [2.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/transducers-stats@2.2.0) (2024-11-03)
13
25
 
14
26
  #### 🚀 Features
package/README.md CHANGED
@@ -91,13 +91,13 @@ For Node.js REPL:
91
91
  const ts = await import("@thi.ng/transducers-stats");
92
92
  ```
93
93
 
94
- Package sizes (brotli'd, pre-treeshake): ESM: 1.75 KB
94
+ Package sizes (brotli'd, pre-treeshake): ESM: 1.74 KB
95
95
 
96
96
  ## Dependencies
97
97
 
98
98
  - [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
99
+ - [@thi.ng/buffers](https://github.com/thi-ng/umbrella/tree/develop/packages/buffers)
99
100
  - [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
100
- - [@thi.ng/dcons](https://github.com/thi-ng/umbrella/tree/develop/packages/dcons)
101
101
  - [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
102
102
  - [@thi.ng/transducers](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers)
103
103
 
package/momentum.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DCons } from "@thi.ng/dcons/dcons";
1
+ import { sliding } from "@thi.ng/buffers/sliding";
2
2
  import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
3
3
  import { compR } from "@thi.ng/transducers/compr";
4
4
  import { iterator1 } from "@thi.ng/transducers/iterator";
@@ -10,14 +10,13 @@ function momentum(period, src) {
10
10
  period < 1 && illegalArgs("period must be >= 1");
11
11
  return (rfn) => {
12
12
  const reduce = rfn[2];
13
- const window = new DCons();
13
+ const window = sliding(period);
14
14
  return compR(rfn, (acc, x) => {
15
- window.push(x);
16
- if (window.length <= period) {
17
- return acc;
15
+ if (window.length === period) {
16
+ acc = reduce(acc, x - window.read());
18
17
  }
19
- const prev = window.drop();
20
- return reduce(acc, x - prev);
18
+ window.write(x);
19
+ return acc;
21
20
  });
22
21
  };
23
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/transducers-stats",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
4
4
  "description": "Transducers for statistical / technical analysis",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -36,16 +36,16 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.11.13",
40
- "@thi.ng/checks": "^3.6.15",
41
- "@thi.ng/dcons": "^3.2.133",
42
- "@thi.ng/errors": "^2.5.19",
43
- "@thi.ng/transducers": "^9.2.9"
39
+ "@thi.ng/api": "^8.11.14",
40
+ "@thi.ng/buffers": "^0.2.0",
41
+ "@thi.ng/checks": "^3.6.16",
42
+ "@thi.ng/errors": "^2.5.20",
43
+ "@thi.ng/transducers": "^9.2.10"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@microsoft/api-extractor": "^7.48.0",
47
47
  "esbuild": "^0.24.0",
48
- "typedoc": "^0.26.11",
48
+ "typedoc": "^0.27.4",
49
49
  "typescript": "^5.7.2"
50
50
  },
51
51
  "keywords": [
@@ -141,5 +141,5 @@
141
141
  "parent": "@thi.ng/transducers",
142
142
  "year": 2017
143
143
  },
144
- "gitHead": "85e2f0935b58bde5d165fbe754fafec5da0b731e\n"
144
+ "gitHead": "113931a9094c28ae069bcea99adcf4222784d64f\n"
145
145
  }
package/roc.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DCons } from "@thi.ng/dcons/dcons";
1
+ import { sliding } from "@thi.ng/buffers/sliding";
2
2
  import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
3
3
  import { compR } from "@thi.ng/transducers/compr";
4
4
  import { iterator1 } from "@thi.ng/transducers/iterator";
@@ -6,17 +6,18 @@ function roc(period, src) {
6
6
  if (src) {
7
7
  return iterator1(roc(period), src);
8
8
  }
9
+ period |= 0;
9
10
  period < 1 && illegalArgs("period must be >= 1");
10
11
  return (rfn) => {
11
12
  const reduce = rfn[2];
12
- const window = new DCons();
13
+ const window = sliding(period);
13
14
  return compR(rfn, (acc, x) => {
14
- window.push(x);
15
- if (window.length <= period) {
16
- return acc;
15
+ if (window.length === period) {
16
+ const prev = window.read();
17
+ acc = reduce(acc, (x - prev) / prev);
17
18
  }
18
- const prev = window.drop();
19
- return reduce(acc, (x - prev) / prev);
19
+ window.write(x);
20
+ return acc;
20
21
  });
21
22
  };
22
23
  }
package/sma.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DCons } from "@thi.ng/dcons/dcons";
1
+ import { sliding } from "@thi.ng/buffers/sliding";
2
2
  import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
3
3
  import { compR } from "@thi.ng/transducers/compr";
4
4
  import { iterator1 } from "@thi.ng/transducers/iterator";
@@ -7,17 +7,18 @@ function sma(period, src) {
7
7
  return iterator1(sma(period), src);
8
8
  }
9
9
  period |= 0;
10
- period < 2 && illegalArgs("period must be >= 2");
10
+ period < 1 && illegalArgs("period must be >= 1");
11
11
  return (rfn) => {
12
12
  const reduce = rfn[2];
13
- const window = new DCons();
13
+ const window = sliding(period);
14
14
  let sum = 0;
15
15
  return compR(rfn, (acc, x) => {
16
- window.push(x);
17
- const n = window.length;
16
+ if (window.length === period) {
17
+ sum -= window.read();
18
+ }
19
+ window.write(x);
18
20
  sum += x;
19
- n > period && (sum -= window.drop());
20
- return n >= period ? reduce(acc, sum / period) : acc;
21
+ return window.length === period ? reduce(acc, sum / period) : acc;
21
22
  });
22
23
  };
23
24
  }