Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

tablesort.js 2.7 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  1. // Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
  2. // tablesort.filesize.min.js
  3. !(function () {
  4. function r(t) {
  5. return (
  6. (t = t.match(/^(\d+(\.\d+)?) ?((K|M|G|T|P|E|Z|Y|B$)i?B?)$/i)),
  7. parseFloat(t[1].replace(/[^\-?0-9.]/g, "")) *
  8. (function (t) {
  9. var e = "i" === (t = t.toLowerCase())[1] ? 1024 : 1e3;
  10. switch (t[0]) {
  11. case "k":
  12. return Math.pow(e, 2);
  13. case "m":
  14. return Math.pow(e, 3);
  15. case "g":
  16. return Math.pow(e, 4);
  17. case "t":
  18. return Math.pow(e, 5);
  19. case "p":
  20. return Math.pow(e, 6);
  21. case "e":
  22. return Math.pow(e, 7);
  23. case "z":
  24. return Math.pow(e, 8);
  25. case "y":
  26. return Math.pow(e, 9);
  27. default:
  28. return e;
  29. }
  30. })(t[3])
  31. );
  32. }
  33. Tablesort.extend(
  34. "filesize",
  35. function (t) {
  36. return /^\d+(\.\d+)? ?(K|M|G|T|P|E|Z|Y|B$)i?B?$/i.test(t);
  37. },
  38. function (t, e) {
  39. return (
  40. (t = r(t)),
  41. (e = r(e)),
  42. (e = e),
  43. (t = t),
  44. (e = parseFloat(e)),
  45. (t = parseFloat(t)),
  46. (e = isNaN(e) ? 0 : e) - (t = isNaN(t) ? 0 : t)
  47. );
  48. },
  49. );
  50. })();
  51. // tablesort.dotsep.min.js
  52. Tablesort.extend(
  53. "dotsep",
  54. function (t) {
  55. return /^(\d+\.)+\d+$/.test(t);
  56. },
  57. function (t, r) {
  58. (t = t.split(".")), (r = r.split("."));
  59. for (var e, n, i = 0, s = t.length; i < s; i++)
  60. if ((e = parseInt(t[i], 10)) !== (n = parseInt(r[i], 10))) {
  61. if (n < e) return -1;
  62. if (e < n) return 1;
  63. }
  64. return 0;
  65. },
  66. );
  67. // tablesort.number.min.js
  68. (function () {
  69. var cleanNumber = function (i) {
  70. // Remove everything after ± symbol if present
  71. i = i.split("±")[0].trim();
  72. return i.replace(/[^\-?0-9.]/g, "");
  73. },
  74. compareNumber = function (a, b) {
  75. a = parseFloat(a);
  76. b = parseFloat(b);
  77. a = isNaN(a) ? 0 : a;
  78. b = isNaN(b) ? 0 : b;
  79. return a - b;
  80. };
  81. Tablesort.extend(
  82. "number",
  83. function (item) {
  84. return (
  85. item.match(/^[-+]?[£\x24Û¢´€]?\d+\s*([,\.]\d{0,2})/) || // Prefixed currency
  86. item.match(/^[-+]?\d+\s*([,\.]\d{0,2})?[£\x24Û¢´€]/) || // Suffixed currency
  87. item.match(/^[-+]?(\d)*-?([,\.]){0,1}-?(\d)+([E,e][\-+][\d]+)?%?$/)
  88. ); // Number
  89. },
  90. function (a, b) {
  91. a = cleanNumber(a);
  92. b = cleanNumber(b);
  93. return compareNumber(b, a);
  94. },
  95. );
  96. })();
  97. // subscribe
  98. document$.subscribe(function () {
  99. var tables = document.querySelectorAll("article table:not([class])");
  100. tables.forEach(function (table) {
  101. new Tablesort(table);
  102. });
  103. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...