@kayord/ui 1.1.1 → 1.1.2

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.
@@ -1,4 +1,8 @@
1
- export declare const sum: <T>(data: T[], columnId: keyof T) => number;
2
- export declare const min: <T>(data: T[], columnId: keyof T) => number | undefined;
3
- export declare const max: <T>(data: T[], columnId: keyof T) => number | undefined;
4
- export declare const uniqueCount: <T>(data: T[], columnId: keyof T) => number;
1
+ export declare const aggregationFns: {
2
+ sum: <T>(data: T[], columnId: keyof T) => number;
3
+ min: <T>(data: T[], columnId: keyof T) => number | undefined;
4
+ max: <T>(data: T[], columnId: keyof T) => number | undefined;
5
+ mean: <T>(data: T[], columnId: keyof T) => number | undefined;
6
+ uniqueCount: <T>(data: T[], columnId: keyof T) => number;
7
+ count: <T>(data: T[], columnId: keyof T) => number;
8
+ };
@@ -1,10 +1,10 @@
1
- export const sum = (data, columnId) => {
1
+ const sum = (data, columnId) => {
2
2
  return data.reduce((sum, next) => {
3
3
  const nextValue = next[columnId];
4
4
  return sum + (typeof nextValue === "number" ? nextValue : 0);
5
5
  }, 0);
6
6
  };
7
- export const min = (data, columnId) => {
7
+ const min = (data, columnId) => {
8
8
  let min;
9
9
  data.forEach((row) => {
10
10
  const value = Number(row[columnId]);
@@ -14,7 +14,7 @@ export const min = (data, columnId) => {
14
14
  });
15
15
  return min;
16
16
  };
17
- export const max = (data, columnId) => {
17
+ const max = (data, columnId) => {
18
18
  let max;
19
19
  data.forEach((row) => {
20
20
  const value = Number(row[columnId]);
@@ -24,6 +24,30 @@ export const max = (data, columnId) => {
24
24
  });
25
25
  return max;
26
26
  };
27
- export const uniqueCount = (data, columnId) => {
27
+ const uniqueCount = (data, columnId) => {
28
28
  return new Set(data.map((d) => d[columnId])).size;
29
29
  };
30
+ const count = (data, columnId) => {
31
+ return data.length;
32
+ };
33
+ const mean = (data, columnId) => {
34
+ let count = 0;
35
+ let sum = 0;
36
+ data.forEach((row) => {
37
+ let value = Number(row[columnId]);
38
+ if (value != null && (value = +value) >= value) {
39
+ (++count, (sum += value));
40
+ }
41
+ });
42
+ if (count)
43
+ return sum / count;
44
+ return;
45
+ };
46
+ export const aggregationFns = {
47
+ sum,
48
+ min,
49
+ max,
50
+ mean,
51
+ uniqueCount,
52
+ count,
53
+ };
@@ -1,5 +1,5 @@
1
1
  export { default as DataTable } from "./DataTable.svelte";
2
2
  export { createShadTable } from "./shad-table.svelte";
3
- export { max, min, sum, uniqueCount } from "./data-table-utils";
3
+ export { aggregationFns } from "./data-table-utils";
4
4
  export { decodeColumnFilters, decodeGlobalFilter, decodePageIndex, decodeSorting, decodeTableState, encodeColumnFilters, encodeGlobalFilter, encodePageIndex, encodeSorting, encodeTableState, } from "./table-search-params";
5
5
  export type { CustomColumnMeta, CustomOptions } from "./types";
@@ -1,4 +1,4 @@
1
1
  export { default as DataTable } from "./DataTable.svelte";
2
2
  export { createShadTable } from "./shad-table.svelte";
3
- export { max, min, sum, uniqueCount } from "./data-table-utils";
3
+ export { aggregationFns } from "./data-table-utils";
4
4
  export { decodeColumnFilters, decodeGlobalFilter, decodePageIndex, decodeSorting, decodeTableState, encodeColumnFilters, encodeGlobalFilter, encodePageIndex, encodeSorting, encodeTableState, } from "./table-search-params";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kayord/ui",
3
3
  "private": false,
4
- "version": "1.1.1",
4
+ "version": "1.1.2",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./dist/index.d.ts",
@@ -63,7 +63,7 @@
63
63
  "d3-scale": "^4.0.2",
64
64
  "d3-shape": "^3.2.0",
65
65
  "eslint": "^9.31.0",
66
- "eslint-config-prettier": "^10.1.5",
66
+ "eslint-config-prettier": "^10.1.8",
67
67
  "eslint-plugin-svelte": "^3.11.0",
68
68
  "happy-dom": "^18.0.1",
69
69
  "layerchart": "2.0.0-next.30",
@@ -71,7 +71,7 @@
71
71
  "prettier-plugin-svelte": "^3.4.0",
72
72
  "prettier-plugin-tailwindcss": "^0.6.14",
73
73
  "publint": "^0.3.12",
74
- "svelte": "5.36.7",
74
+ "svelte": "5.36.10",
75
75
  "svelte-check": "^4.3.0",
76
76
  "sveltekit-superforms": "^2.27.1",
77
77
  "tailwindcss": "^4.1.11",