New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

table-sort-js

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

table-sort-js - npm Package Compare versions

Comparing version 1.3.7-d to 1.3.7-e

2

package.json
{
"name": "table-sort-js",
"version": "1.3.7-d",
"version": "1.3.7-e",
"description": "A JavaScript client-side HTML table sorting library with no dependencies required.",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -12,3 +12,3 @@ ![table-sort-js](https://img.shields.io/npm/v/table-sort-js)

- [Demo](https://leewannacott.github.io/Portfolio/#/GitHub)
- [Documentation.](https://leewannacott.github.io/TABLE-SORT-JS/docs/about.html)
- [Documentation.](https://leewannacott.github.io/table-sort-js/docs/about.html)
(work in progress)

@@ -23,6 +23,6 @@ - [npm package.](https://www.npmjs.com/package/table-sort-js)

```
Refer to the documentation for examples on using TABLE-SORT-JS with frontend frameworks such as
[ReactJS.](https://leewannacott.github.io/TABLE-SORT-JS/docs/react.html)
Refer to the documentation for examples on using table-sort-js with frontend frameworks such as
[ReactJS.](https://leewannacott.github.io/table-sort-js/docs/react.html)
2. [Download table-sort.js](https://leewannacott.github.io/TABLE-SORT-JS/table-sort.js) (Select save as.)
2. [Download table-sort.js](https://leewannacott.github.io/table-sort-js/table-sort.js) (Select save as.)

@@ -33,3 +33,3 @@ Then add the following script before your HTML table:

```
Refer to the documenation for examples how to use TABLE-SORT-JS with [HTML.](https://leewannacott.github.io/TABLE-SORT-JS/docs/html5.html)
Refer to the documenation for examples how to use table-sort-js with [HTML.](https://leewannacott.github.io/table-sort-js/docs/html5.html)
#### To make a table sortable:

@@ -40,6 +40,7 @@ - Add `class="table-sort"` to HTML <table> tags. Click on the columns heads to sort.

| table classes | Description |
| -------------- | ------------------------------------------------ |
| "table-sort" | Make the table sortable! (Words, numbers, dates) |
| "table-arrows" | Display ascending or descending triangle. |
| table classes | Description |
| -------------- | ------------------------------------------------ |
| "table-sort" | Make the table sortable! (Words, numbers, dates) |
| "table-arrows" | Display ascending or descending triangles. |
| "remember-sort"| If clicking on different columns remembers sort of the original column. |

@@ -55,1 +56,4 @@ | th classes | Description |

- If `<thead>` does not exist it will be created by using data from first row. `<tbody>` is optional.
#### Development:
If you wish to contribute, install instructions can be found [here.](https://leewannacott.github.io/table-sort-js/docs/development.html)

@@ -58,2 +58,40 @@ /*

const columnData = [];
let isDayOfWeek = th.classList.contains("days-of-week");
if (isDayOfWeek) {
const day = /(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday|Mon|Tue|Wed|Thur|Fri|Sat|Sun)/i;
const dayOfWeek = {
Monday: 1,
Tuesday: 2,
Wednesday: 3,
Thursday: 4,
Friday: 5,
Saturday: 6,
Sunday: 7,
};
for (let [i, tr] of tableRows.entries()) {
const dayOfWeekTd = tr.querySelectorAll("td").item(columnIndex)
.textContent;
if (dayOfWeekTd.match(day)) {
if (dayOfWeekTd.match(/Monday|Mon/i)) {
columnData.push(`${dayOfWeek.Monday}#${i}`);
} else if (dayOfWeekTd.match(/Tuesday|Tue/i)) {
columnData.push(`${dayOfWeek.Tuesday}#${i}`);
} else if (dayOfWeekTd.match(/Wednesday|Wed/i)) {
columnData.push(`${dayOfWeek.Wednesday}#${i}`);
} else if (dayOfWeekTd.match(/Thursday|Thur/i)) {
columnData.push(`${dayOfWeek.Thursday}#${i}`);
} else if (dayOfWeekTd.match(/Friday|Fri/i)) {
columnData.push(`${dayOfWeek.Friday}#${i}`);
} else if (dayOfWeekTd.match(/Saturday|Sat/i)) {
columnData.push(`${dayOfWeek.Saturday}#${i}`);
} else if (dayOfWeekTd.match(/Sunday|Sun/i)) {
columnData.push(`${dayOfWeek.Sunday}#${i}`);
}
} else {
columnData.push(`!X!Y!Z!#${i}`);
}
}
}
// Handle filesize sorting (e.g KB, MB, GB, TB) - Turns data into KiB.

@@ -75,2 +113,12 @@ let isFileSize = th.classList.contains("file-size");

};
function removeUnitTypeConvertToBytes(fileSizeTd, _replace) {
fileSizeTd = fileSizeTd.replace(unitType, "");
fileSizeTd = fileSizeTd.replace(
fileSizeTd,
fileSizeTd * fileSizes[_replace]
);
return fileSizeTd;
}
for (let [i, tr] of tableRows.entries()) {

@@ -81,56 +129,24 @@ let fileSizeTd = tr.querySelectorAll("td").item(columnIndex)

if (fileSizeTd.match(/\s?KB/i)) {
fileSizeTd = fileSizeTd.replace(unitType, "");
fileSizeTd = fileSizeTd.replace(
fileSizeTd,
fileSizeTd * fileSizes.Kilobyte
);
fileSizeTd = removeUnitTypeConvertToBytes(fileSizeTd, 'Kilobyte')
columnData.push(`${fileSizeTd}#${i}`);
} else if (fileSizeTd.match(/\s?KiB/i)) {
fileSizeTd = fileSizeTd.replace(unitType, "");
fileSizeTd = fileSizeTd.replace(
fileSizeTd,
fileSizeTd * fileSizes.Kibibyte
);
fileSizeTd = removeUnitTypeConvertToBytes(fileSizeTd, 'Kibibyte')
columnData.push(`${fileSizeTd}#${i}`);
} else if (fileSizeTd.match(/\s?MB/i)) {
fileSizeTd = fileSizeTd.replace(unitType, "");
fileSizeTd = fileSizeTd.replace(
fileSizeTd,
fileSizeTd * fileSizes.Megabyte
);
fileSizeTd = removeUnitTypeConvertToBytes(fileSizeTd, 'Megabyte')
columnData.push(`${fileSizeTd}#${i}`);
} else if (fileSizeTd.match(/\s?MiB/i)) {
fileSizeTd = fileSizeTd.replace(unitType, "");
fileSizeTd = fileSizeTd.replace(
fileSizeTd,
fileSizeTd * fileSizes.Mebibyte
);
fileSizeTd = removeUnitTypeConvertToBytes(fileSizeTd, 'Mebibyte')
columnData.push(`${fileSizeTd}#${i}`);
} else if (fileSizeTd.match(/\s?GB/i)) {
fileSizeTd = fileSizeTd.replace(unitType, "");
fileSizeTd = fileSizeTd.replace(
fileSizeTd,
fileSizeTd * fileSizes.Gigabyte
);
fileSizeTd = removeUnitTypeConvertToBytes(fileSizeTd, 'Gigabyte')
columnData.push(`${fileSizeTd}#${i}`);
} else if (fileSizeTd.match(/\s?GiB/i)) {
fileSizeTd = fileSizeTd.replace(unitType, "");
fileSizeTd = fileSizeTd.replace(
fileSizeTd,
fileSizeTd * fileSizes.Gibibyte
);
fileSizeTd = removeUnitTypeConvertToBytes(fileSizeTd, 'Gibibyte')
columnData.push(`${fileSizeTd}#${i}`);
} else if (fileSizeTd.match(/\s?TB/i)) {
fileSizeTd = fileSizeTd.replace(unitType, "");
fileSizeTd = fileSizeTd.replace(
fileSizeTd,
fileSizeTd * fileSizes.Terabyte
);
fileSizeTd = removeUnitTypeConvertToBytes(fileSizeTd, 'Terabyte')
columnData.push(`${fileSizeTd}#${i}`);
} else if (fileSizeTd.match(/\s?TiB/i)) {
fileSizeTd = fileSizeTd.replace(unitType, "");
fileSizeTd = fileSizeTd.replace(
fileSizeTd,
fileSizeTd * fileSizes.Tebibyte
);
fileSizeTd = removeUnitTypeConvertToBytes(fileSizeTd, 'Tebibyte')
columnData.push(`${fileSizeTd}#${i}`);

@@ -147,12 +163,15 @@ } else if (fileSizeTd.match(/\s?B/i)) {

let isRememberSort = sortableTable.classList.contains("remember-sort");
// Checking if user has clicked different column from the first column if yes reset times clicked.
columnIndexesClicked.push(columnIndex);
if (timesClickedColumn === 1 && columnIndexesClicked.length > 1) {
const lastColumnClicked =
columnIndexesClicked[columnIndexesClicked.length - 1];
const secondLastColumnClicked =
columnIndexesClicked[columnIndexesClicked.length - 2];
if (lastColumnClicked !== secondLastColumnClicked) {
timesClickedColumn = 0;
columnIndexesClicked.shift();
if (!isRememberSort) {
columnIndexesClicked.push(columnIndex);
if (timesClickedColumn === 1 && columnIndexesClicked.length > 1) {
const lastColumnClicked =
columnIndexesClicked[columnIndexesClicked.length - 1];
const secondLastColumnClicked =
columnIndexesClicked[columnIndexesClicked.length - 2];
if (lastColumnClicked !== secondLastColumnClicked) {
timesClickedColumn = 0;
columnIndexesClicked.shift();
}
}

@@ -184,3 +203,3 @@ }

// Remove the unique identifyer for duplicate values(#number).
columnData[i] = columnData[i].replace(/#[0-9]*/,"");
columnData[i] = columnData[i].replace(/#[0-9]*/, "");
if (columnData[i] < fileSizes.Kibibyte) {

@@ -247,7 +266,11 @@ fileSizeInBytesHTML = fileSizeInBytesHTML.replace(

if (tdTextContent.trim() !== "") {
if (!isFileSize) {
if (isFileSize) {
fileSizeColumnTextAndRow[columnData[i]] = tr.innerHTML;
}
if (isDayOfWeek) {
columnIndexAndTableRow[columnData[i]] = tr.innerHTML;
}
if (!isFileSize && !isDayOfWeek) {
columnData.push(`${tdTextContent}#${i}`);
columnIndexAndTableRow[`${tdTextContent}#${i}`] = tr.innerHTML;
} else if (isFileSize) {
fileSizeColumnTextAndRow[columnData[i]] = tr.innerHTML;
}

@@ -254,0 +277,0 @@ } else {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc