bcchapi 1.0.9 → 2.0.0

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +10 -48
  2. package/LICENSE +18 -4
  3. package/README.md +83 -91
  4. package/dist/client/client.d.ts +60 -0
  5. package/dist/client/client.d.ts.map +1 -0
  6. package/dist/client/client.js +126 -0
  7. package/dist/client/client.js.map +1 -0
  8. package/dist/client/index.d.ts +4 -0
  9. package/dist/client/index.d.ts.map +1 -0
  10. package/dist/client/index.js +3 -0
  11. package/dist/client/index.js.map +1 -0
  12. package/dist/client/types.d.ts +136 -0
  13. package/dist/client/types.d.ts.map +1 -0
  14. package/dist/client/types.js +53 -0
  15. package/dist/client/types.js.map +1 -0
  16. package/dist/index.d.ts +5 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +4 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/series/index.d.ts +2 -0
  21. package/dist/series/index.d.ts.map +1 -0
  22. package/dist/series/index.js +2 -0
  23. package/dist/series/index.js.map +1 -0
  24. package/dist/series/series.d.ts +213 -0
  25. package/dist/series/series.d.ts.map +1 -0
  26. package/dist/series/series.js +213 -0
  27. package/dist/series/series.js.map +1 -0
  28. package/dist/utils/dates.d.ts +30 -0
  29. package/dist/utils/dates.d.ts.map +1 -0
  30. package/dist/utils/dates.js +67 -0
  31. package/dist/utils/dates.js.map +1 -0
  32. package/dist/utils/index.d.ts +4 -0
  33. package/dist/utils/index.d.ts.map +1 -0
  34. package/dist/utils/index.js +4 -0
  35. package/dist/utils/index.js.map +1 -0
  36. package/dist/utils/stats.d.ts +112 -0
  37. package/dist/utils/stats.d.ts.map +1 -0
  38. package/dist/utils/stats.js +185 -0
  39. package/dist/utils/stats.js.map +1 -0
  40. package/dist/utils/transform.d.ts +79 -0
  41. package/dist/utils/transform.d.ts.map +1 -0
  42. package/dist/utils/transform.js +101 -0
  43. package/dist/utils/transform.js.map +1 -0
  44. package/package.json +62 -40
  45. package/.eslintignore +0 -3
  46. package/.eslintrc.json +0 -21
  47. package/.github/workflows/npm-publish.yml +0 -38
  48. package/.prettierrc.json +0 -17
  49. package/.vscode/extensions.json +0 -3
  50. package/.vscode/settings.json +0 -4
  51. package/src/client.ts +0 -108
  52. package/src/errors.ts +0 -36
  53. package/src/handlers.ts +0 -69
  54. package/src/index.ts +0 -8
  55. package/src/types.ts +0 -115
  56. package/src/utils.ts +0 -37
  57. package/test/client.test.ts +0 -226
  58. package/test/fixtures/index.ts +0 -15
  59. package/test/fixtures/responses/credentials.invalid.json +0 -11
  60. package/test/fixtures/responses/getseries.invalid.json +0 -11
  61. package/test/fixtures/responses/getseries.success.json +0 -87
  62. package/test/fixtures/responses/searchseries.invalid.json +0 -11
  63. package/test/fixtures/responses/searchseries.success.json +0 -22
  64. package/test/handlers/handle-get-series.test.ts +0 -45
  65. package/test/handlers/handle-search-series.test.ts +0 -48
  66. package/test/mocks/fetch.mock.ts +0 -76
  67. package/test/utils/is-valid-date.test.ts +0 -17
  68. package/test/utils/reverse-date.test.ts +0 -11
  69. package/tsconfig.eslint.json +0 -5
  70. package/tsconfig.json +0 -9
  71. package/vitest.config.mts +0 -9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,112 @@
1
+ import type { Observation } from '../client/types.js';
2
+ /**
3
+ * Calculates the arithmetic mean of valid observation values, ignoring gaps.
4
+ *
5
+ * @param observations - Array of observations.
6
+ * @returns The arithmetic mean.
7
+ * @throws {Error} When there are no valid (non-null) values.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * mean(data.observations); // 1.78
12
+ * ```
13
+ */
14
+ export declare function mean(observations: Observation[]): number;
15
+ /**
16
+ * Calculates the sample standard deviation of valid observation values,
17
+ * ignoring gaps.
18
+ *
19
+ * Uses Bessel's correction (divides by `n - 1`).
20
+ *
21
+ * @param observations - Array of observations.
22
+ * @returns The sample standard deviation.
23
+ * @throws {Error} When fewer than two valid values are present.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * stdDev(data.observations); // 0.035
28
+ * ```
29
+ */
30
+ export declare function stdDev(observations: Observation[]): number;
31
+ /**
32
+ * Returns the minimum valid observation value, ignoring gaps.
33
+ *
34
+ * @param observations - Array of observations.
35
+ * @returns The minimum value.
36
+ * @throws {Error} When there are no valid values.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * min(data.observations); // 0.5
41
+ * ```
42
+ */
43
+ export declare function min(observations: Observation[]): number;
44
+ /**
45
+ * Returns the maximum valid observation value, ignoring gaps.
46
+ *
47
+ * @param observations - Array of observations.
48
+ * @returns The maximum value.
49
+ * @throws {Error} When there are no valid values.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * max(data.observations); // 8.25
54
+ * ```
55
+ */
56
+ export declare function max(observations: Observation[]): number;
57
+ /**
58
+ * Calculates period-over-period fractional change for each observation.
59
+ *
60
+ * The result at index `i` is `value[i] / value[i-1] - 1`.
61
+ * Returns `null` for the first position, and for any position where the
62
+ * current or previous value is `null`.
63
+ *
64
+ * @param observations - Array of observations in chronological order.
65
+ * @returns Array of fractional changes, same length as input, `null` for gaps.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * // values: 100, 105, null, 110
70
+ * periodVariation(obs); // [null, 0.05, null, null]
71
+ * ```
72
+ */
73
+ export declare function periodVariation(observations: Observation[]): Array<number | null>;
74
+ /**
75
+ * Calculates year-over-year fractional change using a fixed period offset.
76
+ *
77
+ * The result at index `i` is `value[i] / value[i - periodsPerYear] - 1`.
78
+ * Returns `null` for the first `periodsPerYear` positions, and for any
79
+ * position where the current or base value is `null`.
80
+ *
81
+ * @param observations - Array of observations in chronological order.
82
+ * @param periodsPerYear - Number of periods per year (e.g. `12` for monthly,
83
+ * `4` for quarterly, `252` for daily trading days).
84
+ * @returns Array of fractional changes, same length as input.
85
+ * @throws {Error} When `periodsPerYear` is not a positive integer.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * // Monthly CPI, 12-month change
90
+ * annualVariation(cpi.observations, 12);
91
+ * ```
92
+ */
93
+ export declare function annualVariation(observations: Observation[], periodsPerYear: number): Array<number | null>;
94
+ /**
95
+ * Calculates a rolling (moving) average over a fixed window of observations.
96
+ *
97
+ * Returns `null` for positions before the window is full, and for any window
98
+ * that contains at least one gap value.
99
+ *
100
+ * @param observations - Array of observations in chronological order.
101
+ * @param window - Number of periods in the rolling window.
102
+ * @returns Array of rolling means, same length as input.
103
+ * @throws {Error} When `window` is not a positive integer.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * // 3-month moving average
108
+ * rollingMean(data.observations, 3);
109
+ * ```
110
+ */
111
+ export declare function rollingMean(observations: Observation[], window: number): Array<number | null>;
112
+ //# sourceMappingURL=stats.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../src/utils/stats.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAatD;;;;;;;;;;;GAWG;AACH,wBAAgB,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,CAMxD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,CAQ1D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,GAAG,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,CAMvD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,GAAG,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,CAMvD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAQjF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,WAAW,EAAE,EAC3B,cAAc,EAAE,MAAM,GACrB,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAYtB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAa7F"}
@@ -0,0 +1,185 @@
1
+ import { parseValue } from './transform.js';
2
+ function validNumbers(observations) {
3
+ const result = [];
4
+ for (const obs of observations) {
5
+ const n = parseValue(obs.value);
6
+ if (n !== null) {
7
+ result.push(n);
8
+ }
9
+ }
10
+ return result;
11
+ }
12
+ /**
13
+ * Calculates the arithmetic mean of valid observation values, ignoring gaps.
14
+ *
15
+ * @param observations - Array of observations.
16
+ * @returns The arithmetic mean.
17
+ * @throws {Error} When there are no valid (non-null) values.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * mean(data.observations); // 1.78
22
+ * ```
23
+ */
24
+ export function mean(observations) {
25
+ const values = validNumbers(observations);
26
+ if (values.length === 0) {
27
+ throw new Error('No valid observations to compute mean');
28
+ }
29
+ return values.reduce((sum, v) => sum + v, 0) / values.length;
30
+ }
31
+ /**
32
+ * Calculates the sample standard deviation of valid observation values,
33
+ * ignoring gaps.
34
+ *
35
+ * Uses Bessel's correction (divides by `n - 1`).
36
+ *
37
+ * @param observations - Array of observations.
38
+ * @returns The sample standard deviation.
39
+ * @throws {Error} When fewer than two valid values are present.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * stdDev(data.observations); // 0.035
44
+ * ```
45
+ */
46
+ export function stdDev(observations) {
47
+ const values = validNumbers(observations);
48
+ if (values.length < 2) {
49
+ throw new Error('stdDev requires at least two valid observations');
50
+ }
51
+ const avg = values.reduce((sum, v) => sum + v, 0) / values.length;
52
+ const variance = values.reduce((sum, v) => sum + (v - avg) ** 2, 0) / (values.length - 1);
53
+ return Math.sqrt(variance);
54
+ }
55
+ /**
56
+ * Returns the minimum valid observation value, ignoring gaps.
57
+ *
58
+ * @param observations - Array of observations.
59
+ * @returns The minimum value.
60
+ * @throws {Error} When there are no valid values.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * min(data.observations); // 0.5
65
+ * ```
66
+ */
67
+ export function min(observations) {
68
+ const values = validNumbers(observations);
69
+ if (values.length === 0) {
70
+ throw new Error('No valid observations to compute min');
71
+ }
72
+ return Math.min(...values);
73
+ }
74
+ /**
75
+ * Returns the maximum valid observation value, ignoring gaps.
76
+ *
77
+ * @param observations - Array of observations.
78
+ * @returns The maximum value.
79
+ * @throws {Error} When there are no valid values.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * max(data.observations); // 8.25
84
+ * ```
85
+ */
86
+ export function max(observations) {
87
+ const values = validNumbers(observations);
88
+ if (values.length === 0) {
89
+ throw new Error('No valid observations to compute max');
90
+ }
91
+ return Math.max(...values);
92
+ }
93
+ /**
94
+ * Calculates period-over-period fractional change for each observation.
95
+ *
96
+ * The result at index `i` is `value[i] / value[i-1] - 1`.
97
+ * Returns `null` for the first position, and for any position where the
98
+ * current or previous value is `null`.
99
+ *
100
+ * @param observations - Array of observations in chronological order.
101
+ * @returns Array of fractional changes, same length as input, `null` for gaps.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * // values: 100, 105, null, 110
106
+ * periodVariation(obs); // [null, 0.05, null, null]
107
+ * ```
108
+ */
109
+ export function periodVariation(observations) {
110
+ const values = observations.map((obs) => parseValue(obs.value));
111
+ return values.map((current, i) => {
112
+ if (i === 0)
113
+ return null;
114
+ const previous = values[i - 1] ?? null;
115
+ if (current === null || previous === null || previous === 0)
116
+ return null;
117
+ return current / previous - 1;
118
+ });
119
+ }
120
+ /**
121
+ * Calculates year-over-year fractional change using a fixed period offset.
122
+ *
123
+ * The result at index `i` is `value[i] / value[i - periodsPerYear] - 1`.
124
+ * Returns `null` for the first `periodsPerYear` positions, and for any
125
+ * position where the current or base value is `null`.
126
+ *
127
+ * @param observations - Array of observations in chronological order.
128
+ * @param periodsPerYear - Number of periods per year (e.g. `12` for monthly,
129
+ * `4` for quarterly, `252` for daily trading days).
130
+ * @returns Array of fractional changes, same length as input.
131
+ * @throws {Error} When `periodsPerYear` is not a positive integer.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * // Monthly CPI, 12-month change
136
+ * annualVariation(cpi.observations, 12);
137
+ * ```
138
+ */
139
+ export function annualVariation(observations, periodsPerYear) {
140
+ if (!Number.isInteger(periodsPerYear) || periodsPerYear < 1) {
141
+ throw new Error(`periodsPerYear must be a positive integer, got: ${periodsPerYear}`);
142
+ }
143
+ const values = observations.map((obs) => parseValue(obs.value));
144
+ return values.map((current, i) => {
145
+ if (i < periodsPerYear)
146
+ return null;
147
+ const base = values[i - periodsPerYear] ?? null;
148
+ if (current === null || base === null || base === 0)
149
+ return null;
150
+ return current / base - 1;
151
+ });
152
+ }
153
+ /**
154
+ * Calculates a rolling (moving) average over a fixed window of observations.
155
+ *
156
+ * Returns `null` for positions before the window is full, and for any window
157
+ * that contains at least one gap value.
158
+ *
159
+ * @param observations - Array of observations in chronological order.
160
+ * @param window - Number of periods in the rolling window.
161
+ * @returns Array of rolling means, same length as input.
162
+ * @throws {Error} When `window` is not a positive integer.
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * // 3-month moving average
167
+ * rollingMean(data.observations, 3);
168
+ * ```
169
+ */
170
+ export function rollingMean(observations, window) {
171
+ if (!Number.isInteger(window) || window < 1) {
172
+ throw new Error(`window must be a positive integer, got: ${window}`);
173
+ }
174
+ const values = observations.map((obs) => parseValue(obs.value));
175
+ return values.map((_, i) => {
176
+ if (i < window - 1)
177
+ return null;
178
+ const slice = values.slice(i - window + 1, i + 1);
179
+ if (slice.some((v) => v === null))
180
+ return null;
181
+ const sum = slice.reduce((acc, v) => acc + v, 0);
182
+ return sum / window;
183
+ });
184
+ }
185
+ //# sourceMappingURL=stats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stats.js","sourceRoot":"","sources":["../../src/utils/stats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,SAAS,YAAY,CAAC,YAA2B;IAC/C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QAC/B,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,IAAI,CAAC,YAA2B;IAC9C,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;IAC1C,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;AAC/D,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,MAAM,CAAC,YAA2B;IAChD,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;IAC1C,IAAI,MAAM,CAAC,M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IAC5B,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,WAAW,CAAC,YAA2B,EAAE,MAAc;IACrE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,2CAA2C,MAAM,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IAChE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACzB,IAAI,CAAC,GAAG,MAAM,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QAChC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAClD,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QAC/C,MAAM,GAAG,GAAI,KAAkB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/D,OAAO,GAAG,GAAG,MAAM,CAAC;IACtB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,79 @@
1
+ import type { Observation } from '../client/types.js';
2
+ /**
3
+ * Parses a raw observation value string to a number, or `null` for gaps.
4
+ *
5
+ * @param value - Raw value string from an {@link Observation}.
6
+ * @returns The parsed number, or `null` when the string is empty or non-numeric.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * parseValue('1.75'); // 1.75
11
+ * parseValue(''); // null
12
+ * parseValue('N/A'); // null
13
+ * ```
14
+ */
15
+ export declare function parseValue(value: string): number | null;
16
+ /**
17
+ * Filters an array of observations, returning only those with parseable values.
18
+ *
19
+ * An observation is considered valid when its `value` field is a non-empty,
20
+ * numeric string (i.e. `parseValue` returns a number, not `null`).
21
+ *
22
+ * @param observations - Array of observations to filter.
23
+ * @returns A new array containing only the valid observations.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const valid = filterValid(data.observations);
28
+ * ```
29
+ */
30
+ export declare function filterValid(observations: Observation[]): Observation[];
31
+ /**
32
+ * Converts an array of observations to an array of `number | null` values.
33
+ *
34
+ * Gaps (empty or non-numeric values) are represented as `null`, preserving
35
+ * the positional alignment with the original observations array.
36
+ *
37
+ * @param observations - Array of observations to convert.
38
+ * @returns Array of parsed values, `null` for gaps.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * toNumbers(data.observations); // [1.75, null, 1.80, ...]
43
+ * ```
44
+ */
45
+ export declare function toNumbers(observations: Observation[]): Array<number | null>;
46
+ /**
47
+ * Converts an array of observations to a `Map` keyed by the observation date
48
+ * string (`"DD-MM-YYYY"`).
49
+ *
50
+ * When duplicate dates exist, the last one wins. Values are `null` for gaps.
51
+ *
52
+ * @param observations - Array of observations to convert.
53
+ * @returns Map from date string to `number | null`.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * const map = toMap(data.observations);
58
+ * map.get('01-01-2024'); // 1.75
59
+ * ```
60
+ */
61
+ export declare function toMap(observations: Observation[]): Map<string, number | null>;
62
+ /**
63
+ * Converts an array of observations to parallel `dates` and `values` arrays
64
+ * suitable for charting libraries.
65
+ *
66
+ * @param observations - Array of observations to convert.
67
+ * @returns Object with `dates` (UTC `Date[]`) and `values` (`Array<number | null>`).
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * const { dates, values } = toArrays(data.observations);
72
+ * // pass to Chart.js, D3, etc.
73
+ * ```
74
+ */
75
+ export declare function toArrays(observations: Observation[]): {
76
+ dates: Date[];
77
+ values: Array<number | null>;
78
+ };
79
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/utils/transform.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOvD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CAEtE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAE3E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAM7E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG;IACrD,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC9B,CAQA"}
@@ -0,0 +1,101 @@
1
+ import { parseObservationDate } from './dates.js';
2
+ /**
3
+ * Parses a raw observation value string to a number, or `null` for gaps.
4
+ *
5
+ * @param value - Raw value string from an {@link Observation}.
6
+ * @returns The parsed number, or `null` when the string is empty or non-numeric.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * parseValue('1.75'); // 1.75
11
+ * parseValue(''); // null
12
+ * parseValue('N/A'); // null
13
+ * ```
14
+ */
15
+ export function parseValue(value) {
16
+ const trimmed = value.trim();
17
+ if (trimmed === '') {
18
+ return null;
19
+ }
20
+ const n = Number(trimmed);
21
+ return isNaN(n) ? null : n;
22
+ }
23
+ /**
24
+ * Filters an array of observations, returning only those with parseable values.
25
+ *
26
+ * An observation is considered valid when its `value` field is a non-empty,
27
+ * numeric string (i.e. `parseValue` returns a number, not `null`).
28
+ *
29
+ * @param observations - Array of observations to filter.
30
+ * @returns A new array containing only the valid observations.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const valid = filterValid(data.observations);
35
+ * ```
36
+ */
37
+ export function filterValid(observations) {
38
+ return observations.filter((obs) => parseValue(obs.value) !== null);
39
+ }
40
+ /**
41
+ * Converts an array of observations to an array of `number | null` values.
42
+ *
43
+ * Gaps (empty or non-numeric values) are represented as `null`, preserving
44
+ * the positional alignment with the original observations array.
45
+ *
46
+ * @param observations - Array of observations to convert.
47
+ * @returns Array of parsed values, `null` for gaps.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * toNumbers(data.observations); // [1.75, null, 1.80, ...]
52
+ * ```
53
+ */
54
+ export function toNumbers(observations) {
55
+ return observations.map((obs) => parseValue(obs.value));
56
+ }
57
+ /**
58
+ * Converts an array of observations to a `Map` keyed by the observation date
59
+ * string (`"DD-MM-YYYY"`).
60
+ *
61
+ * When duplicate dates exist, the last one wins. Values are `null` for gaps.
62
+ *
63
+ * @param observations - Array of observations to convert.
64
+ * @returns Map from date string to `number | null`.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * const map = toMap(data.observations);
69
+ * map.get('01-01-2024'); // 1.75
70
+ * ```
71
+ */
72
+ export function toMap(observations) {
73
+ const result = new Map();
74
+ for (const obs of observations) {
75
+ result.set(obs.indexDateString, parseValue(obs.value));
76
+ }
77
+ return result;
78
+ }
79
+ /**
80
+ * Converts an array of observations to parallel `dates` and `values` arrays
81
+ * suitable for charting libraries.
82
+ *
83
+ * @param observations - Array of observations to convert.
84
+ * @returns Object with `dates` (UTC `Date[]`) and `values` (`Array<number | null>`).
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const { dates, values } = toArrays(data.observations);
89
+ * // pass to Chart.js, D3, etc.
90
+ * ```
91
+ */
92
+ export function toArrays(observations) {
93
+ const dates = [];
94
+ const values = [];
95
+ for (const obs of observations) {
96
+ dates.push(parseObservationDate(obs.indexDateString));
97
+ values.push(parseValue(obs.value));
98
+ }
99
+ return { dates, values };
100
+ }
101
+ //# sourceMappingURL=transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/utils/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAGlD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1B,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CAAC,YAA2B;IACrD,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;AACtE,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CAAC,YAA2B;IACnD,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,KAAK,CAAC,YAA2B;IAC/C,MAAM,MAAM,GAAG,IAAI,GAAG,EAAyB,CAAC;IAChD,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QAC/B,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,QAAQ,CAAC,YAA2B;IAIlD,MAAM,KAAK,GAAW,EAAE,CAAC;IACzB,MAAM,MAAM,GAAyB,EAAE,CAAC;IACxC,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC;QACtD,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC"}
package/package.json CHANGED
@@ -1,52 +1,74 @@
1
1
  {
2
2
  "name": "bcchapi",
3
- "version": "1.0.9",
4
- "description": "API para acceder al Web Service del Banco Central de Chile.",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "scripts": {
8
- "build": "rimraf dist && tsc",
9
- "test": "vitest",
10
- "coverage": "vitest --coverage",
11
- "lint": "eslint --ignore-path .eslintignore --ext .ts",
12
- "format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\""
3
+ "version": "2.0.0",
4
+ "description": "Node.js wrapper for the Banco Central de Chile API. Features a fully typed API client and utility tools to streamline macroeconomic data integration.",
5
+ "homepage": "https://github.com/airarrazaval/bcchapi#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/airarrazaval/bcchapi/issues"
13
8
  },
9
+ "license": "MIT",
14
10
  "repository": {
15
11
  "type": "git",
16
- "url": "git+https://github.com/airarrazaval/bcchapi.git"
12
+ "url": "https://github.com/airarrazaval/bcchapi.git"
17
13
  },
18
- "keywords": [
19
- "node",
20
- "javascript",
21
- "typescript",
22
- "bcchapi"
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "CHANGELOG.md",
18
+ "LICENSE"
23
19
  ],
24
- "author": "Alfredo Irarrazaval",
25
- "license": "MIT",
26
- "bugs": {
27
- "url": "https://github.com/airarrazaval/bcchapi/issues"
20
+ "type": "module",
21
+ "sideEffects": false,
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "./client": {
32
+ "types": "./dist/client/index.d.ts",
33
+ "import": "./dist/client/index.js",
34
+ "default": "./dist/client/index.js"
35
+ },
36
+ "./series": {
37
+ "types": "./dist/series/index.d.ts",
38
+ "import": "./dist/series/index.js",
39
+ "default": "./dist/series/index.js"
40
+ },
41
+ "./utils": {
42
+ "types": "./dist/utils/index.d.ts",
43
+ "import": "./dist/utils/index.js",
44
+ "default": "./dist/utils/index.js"
45
+ }
46
+ },
47
+ "scripts": {
48
+ "build": "tsc -p tsconfig.build.json",
49
+ "dev": "node --import tsx/esm --test --watch \"tests/**/*.test.ts\"",
50
+ "test": "node --import tsx/esm --test \"tests/**/*.test.ts\"",
51
+ "test:coverage": "node --test-coverage --import tsx/esm --test \"tests/**/*.test.ts\"",
52
+ "typecheck": "tsc --noEmit",
53
+ "lint": "oxlint src tests",
54
+ "lint:fix": "oxlint --fix src tests",
55
+ "format": "oxfmt",
56
+ "format:check": "oxfmt --check",
57
+ "clean": "rm -rf dist docs",
58
+ "docs": "typedoc",
59
+ "changelog": "git-cliff --bump -o CHANGELOG.md",
60
+ "prepublishOnly": "npm run typecheck && npm run lint && npm run clean && npm run build"
28
61
  },
29
- "homepage": "https://github.com/airarrazaval/bcchapi#readme",
30
62
  "devDependencies": {
31
- "@tsconfig/node20": "^20.1.4",
32
- "@types/node": "^20.14.2",
33
- "@typescript-eslint/eslint-plugin": "^6.21.0",
34
- "@typescript-eslint/parser": "^6.21.0",
35
- "@vitest/coverage-v8": "^3.0.6",
36
- "eslint": "^8.57.0",
37
- "eslint-config-prettier": "^9.1.0",
38
- "eslint-plugin-import": "^2.29.1",
39
- "prettier": "^3.3.2",
40
- "rimraf": "^6.0.1",
41
- "ts-node": "^10.9.2",
42
- "typescript": "^5.4.5",
43
- "vitest": "^3.0.6"
63
+ "@types/node": "^24.12.0",
64
+ "git-cliff": "^2.12.0",
65
+ "oxfmt": "^0.36.0",
66
+ "oxlint": "^1.51.0",
67
+ "tsx": "^4.21.0",
68
+ "typedoc": "^0.28.17",
69
+ "typescript": "^5.8.0"
44
70
  },
45
71
  "engines": {
46
- "node": ">=18.19.0",
47
- "npm": ">=10.2.3"
48
- },
49
- "volta": {
50
- "node": "20.11.0"
72
+ "node": ">=24.0.0"
51
73
  }
52
- }
74
+ }
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- node_modules
2
- coverage
3
- dist
package/.eslintrc.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "env": {
3
- "es2021": true,
4
- "node": true
5
- },
6
- "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
7
- "overrides": [],
8
- "parser": "@typescript-eslint/parser",
9
- "parserOptions": {
10
- "ecmaVersion": "latest",
11
- "sourceType": "module",
12
- "project": "./tsconfig.eslint.json"
13
- },
14
- "plugins": ["@typescript-eslint"],
15
- "rules": {
16
- "max-classes-per-file": "off",
17
- "eol-last": ["error", "always"],
18
- "@typescript-eslint/no-unused-vars": "error",
19
- "@typescript-eslint/consistent-type-definitions": ["error", "interface"]
20
- }
21
- }