@stacksjs/arrays 0.75.118 → 0.75.120

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/dist/arr.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './contains';
2
2
  export * from './helpers';
3
3
  export * from './math';
4
4
  export * from './transform';
5
+ export * from './series';
package/dist/arr.js CHANGED
@@ -1 +1 @@
1
- export*from"./contains";export*from"./helpers";export*from"./math";export*from"./transform";
1
+ export*from"./contains";export*from"./helpers";export*from"./math";export*from"./transform";export*from"./series";
@@ -0,0 +1,26 @@
1
+ /** Reject absent and nonnumeric values without turning null, false or blanks into zero. */
2
+ export declare function finiteNumeric(value: unknown): number | null;
3
+ /** Prefer a direct source per field; a missing field can fall back to another source. */
4
+ export declare function mergeDailySeries(rows: readonly DailyObservation[], priority?: readonly string[]): DailySeriesPoint[];
5
+ /** Statistics over valid observations, including zero; latest is by date rather than input order. */
6
+ export declare function summarizeSeries(points: readonly NumericSeriesPoint[]): NumericSeriesSummary;
7
+ /** Numeric observations grouped by calendar day, with provenance per field. */
8
+ export declare interface DailyObservation {
9
+ day: string
10
+ source: string
11
+ values: Record<string, unknown>
12
+ updatedAt?: string
13
+ }
14
+ export declare interface DailySeriesPoint {
15
+ date: string
16
+ values: Record<string, number>
17
+ sources: Record<string, string>
18
+ }
19
+ export declare interface NumericSeriesPoint { date: string, value: number, source?: string }
20
+ export declare interface NumericSeriesSummary {
21
+ count: number
22
+ latest: NumericSeriesPoint | null
23
+ average: number | null
24
+ lowest: number | null
25
+ highest: number | null
26
+ }
package/dist/series.js ADDED
@@ -0,0 +1 @@
1
+ export function finiteNumeric(value){if(typeof value!=="number"&&typeof value!=="string")return null;if(typeof value==="string"&&!value.trim())return null;const number=Number(value);return Number.isFinite(number)?number:null}export function mergeDailySeries(rows,priority=[]){const rank=(source)=>{const at=priority.indexOf(source);return at<0?priority.length:at},sorted=[...rows].sort((a,b)=>rank(a.source)-rank(b.source)||String(b.updatedAt||"").localeCompare(String(a.updatedAt||""))||a.source.localeCompare(b.source)),days=new Map;for(const row of sorted){if(!/^\d{4}-\d{2}-\d{2}$/.test(row.day))continue;const parsed=new Date(`${row.day}T00:00:00Z`);if(!Number.isFinite(parsed.getTime())||parsed.toISOString().slice(0,10)!==row.day)continue;const point=days.get(row.day)||{date:row.day,values:{},sources:{}};for(const[key,raw]of Object.entries(row.values)){if(Object.hasOwn(point.values,key))continue;const value=finiteNumeric(raw);if(value===null)continue;Object.defineProperty(point.values,key,{value,enumerable:!0,configurable:!0,writable:!0});Object.defineProperty(point.sources,key,{value:row.source,enumerable:!0,configurable:!0,writable:!0})}if(Object.keys(point.values).length)days.set(row.day,point)}return[...days.values()].sort((a,b)=>a.date.localeCompare(b.date))}export function summarizeSeries(points){const valid=points.filter((point)=>Number.isFinite(point.value)).sort((a,b)=>a.date.localeCompare(b.date));let sum=0,lowest=1/0,highest=-1/0;for(const point of valid){sum+=point.value;lowest=Math.min(lowest,point.value);highest=Math.max(highest,point.value)}return{count:valid.length,latest:valid.at(-1)??null,average:valid.length?sum/valid.length:null,lowest:valid.length?lowest:null,highest:valid.length?highest:null}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/arrays",
3
3
  "type": "module",
4
- "version": "0.75.118",
4
+ "version": "0.75.120",
5
5
  "description": "The Stacks array utilities.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [