@qureshiowais91/smart-table-core 0.1.0 → 0.1.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.
@@ -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 CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "@qureshiowais91/smart-table-core",
3
- "version": "0.1.0",
4
- "description": "Headless utilities for building data tables",
3
+ "version": "0.1.4",
4
+ "description": "Headless utilities for building sortable, searchable tables",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
- "files": ["dist"],
7
+ "files": [
8
+ "dist"
9
+ ],
8
10
  "scripts": {
9
- "build": "tsc",
10
- "publish:public": "npm publish --access public"
11
+ "build": "tsc"
12
+ },
13
+ "license": "MIT",
14
+ "devDependencies": {
15
+ "typescript": "^5.9.3"
11
16
  }
12
17
  }