headless-table-core 0.1.6

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/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # smart-table-core
2
+
3
+ Simple, headless utilities for building **searchable, sortable, paginated tables**.
4
+
5
+ No UI.
6
+ No framework lock-in.
7
+ Works with Angular, React, Vue, or plain JavaScript.
8
+
9
+ ---
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @qureshiowais91/smart-table-core
15
+ ````
16
+
17
+ ---
18
+
19
+ ## Import
20
+
21
+ ```ts
22
+ import {
23
+ getValue,
24
+ sortData,
25
+ filterData,
26
+ paginate
27
+ } from "@qureshiowais91/smart-table-core";
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Example data
33
+
34
+ ```ts
35
+ const users = [
36
+ {
37
+ id: 1,
38
+ user: { name: "Ali", profile: { age: 28 } },
39
+ email: "ali@gmail.com"
40
+ },
41
+ {
42
+ id: 2,
43
+ user: { name: "Zara", profile: { age: 24 } },
44
+ email: "zara@gmail.com"
45
+ }
46
+ ];
47
+ ```
48
+
49
+ ---
50
+
51
+ ## getValue – safe nested access
52
+
53
+ ```ts
54
+ getValue(users[0], "user.name"); // "Ali"
55
+ getValue(users[0], "user.profile.age"); // 28
56
+ getValue(users[0], "user.address.city"); // ""
57
+ ```
58
+
59
+ With fallback:
60
+
61
+ ```ts
62
+ getValue(users[0], "user.address.city", "N/A");
63
+ ```
64
+
65
+ ---
66
+
67
+ ## sortData – sort by column
68
+
69
+ ```ts
70
+ sortData(users, "user.name", "asc");
71
+ sortData(users, "user.profile.age", "desc");
72
+ ```
73
+
74
+ * Non-mutating
75
+ * Supports nested keys
76
+
77
+ ---
78
+
79
+ ## filterData – global search
80
+
81
+ ```ts
82
+ filterData(users, "ali", ["user.name", "email"]);
83
+ ```
84
+
85
+ * Case-insensitive
86
+ * Searches multiple fields
87
+
88
+ ---
89
+
90
+ ## paginate – pagination logic
91
+
92
+ ```ts
93
+ paginate(users, 1, 10);
94
+ ```
95
+
96
+ Returns:
97
+
98
+ ```ts
99
+ {
100
+ data: [...],
101
+ total: number,
102
+ page: number,
103
+ limit: number
104
+ }
105
+ ```
106
+
107
+ ---
108
+
109
+ ## Recommended usage (real flow)
110
+
111
+ ```ts
112
+ let rows = users;
113
+
114
+ rows = filterData(rows, searchText, ["user.name", "email"]);
115
+ rows = sortData(rows, sortKey, sortOrder);
116
+ const result = paginate(rows, page, limit);
117
+
118
+ // render result.data
119
+ ```
120
+
121
+ ---
122
+
123
+ ## Notes
124
+
125
+ * This library handles **logic only**
126
+ * You control UI and rendering
127
+ * Original data is never mutated
128
+
129
+ ---
130
+
131
+ ## License
132
+
133
+ MIT
134
+
135
+ ```
136
+
137
+ ---
138
+
139
+ ### This README is **good enough to ship**.
140
+
141
+ If you want next:
142
+ - Ultra-short README for npm page
143
+ - Examples folder
144
+ - React hook version
145
+ - Angular wrapper
146
+
147
+ Just tell me.
148
+
@@ -0,0 +1 @@
1
+ export declare function filterData<T>(data: T[], search: string, keys: string[]): T[];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterData = filterData;
4
+ const getValue_1 = require("./getValue");
5
+ function filterData(data, search, keys) {
6
+ if (!search)
7
+ return data;
8
+ const query = search.toLowerCase();
9
+ return data.filter(row => keys.some(key => String((0, getValue_1.getValue)(row, key))
10
+ .toLowerCase()
11
+ .includes(query)));
12
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Safely get nested object value using dot notation
3
+ * Example: getValue(row, "user.profile.name")
4
+ */
5
+ export declare function getValue<T = any>(obj: Record<string, any>, path: string, fallback?: T): T;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getValue = getValue;
4
+ /**
5
+ * Safely get nested object value using dot notation
6
+ * Example: getValue(row, "user.profile.name")
7
+ */
8
+ function getValue(obj, path, fallback = "") {
9
+ if (!obj || !path)
10
+ return fallback;
11
+ return path.split(".").reduce((acc, key) => {
12
+ return acc && acc[key] !== undefined ? acc[key] : fallback;
13
+ }, obj);
14
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./getValue";
2
+ export * from "./sortData";
3
+ export * from "./filterData";
4
+ export * from "./paginate";
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./getValue"), exports);
18
+ __exportStar(require("./sortData"), exports);
19
+ __exportStar(require("./filterData"), exports);
20
+ __exportStar(require("./paginate"), exports);
@@ -0,0 +1,6 @@
1
+ export declare function paginate<T>(data: T[], page: number, limit: number): {
2
+ data: T[];
3
+ total: number;
4
+ page: number;
5
+ limit: number;
6
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.paginate = paginate;
4
+ function paginate(data, page, limit) {
5
+ const start = (page - 1) * limit;
6
+ const end = start + limit;
7
+ return {
8
+ data: data.slice(start, end),
9
+ total: data.length,
10
+ page,
11
+ limit
12
+ };
13
+ }
@@ -0,0 +1 @@
1
+ export declare function sortData<T>(data: T[], key: string, order?: "asc" | "desc"): T[];
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sortData = sortData;
4
+ const getValue_1 = require("./getValue");
5
+ function sortData(data, key, order = "asc") {
6
+ return [...data].sort((a, b) => {
7
+ const aVal = (0, getValue_1.getValue)(a, key);
8
+ const bVal = (0, getValue_1.getValue)(b, key);
9
+ if (aVal > bVal)
10
+ return order === "asc" ? 1 : -1;
11
+ if (aVal < bVal)
12
+ return order === "asc" ? -1 : 1;
13
+ return 0;
14
+ });
15
+ }
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "headless-table-core",
3
+ "version": "0.1.6",
4
+ "description": "Headless utilities for building sortable, searchable tables",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc"
12
+ },
13
+ "license": "MIT",
14
+ "devDependencies": {
15
+ "typescript": "^5.9.3"
16
+ }
17
+ }