UNPKG

@coligo/react-native-table

Version:

Lightweight package for creating flexible tables in React Native.

22 lines (21 loc) 815 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sortData = sortData; function sortData(data, key, direction) { if (!key) return data; return [...data].sort((a, b) => { const aValue = a[key]; const bValue = b[key]; if (typeof aValue === 'string' && typeof bValue === 'string') { return direction === 'asc' ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue); } else if (typeof aValue === 'number' && typeof bValue === 'number') { return direction === 'asc' ? aValue - bValue : bValue - aValue; } else if (aValue instanceof Date && bValue instanceof Date) { return direction === 'asc' ? aValue.getTime() - bValue.getTime() : bValue.getTime() - aValue.getTime(); } return 0; }); } //# sourceMappingURL=sorting.js.map