You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Plugins/sorting/natural.min.mjs

2 lines
1.8 KiB
JavaScript

/*! © SpryMedia Ltd, Jim Palmer, Michael Buehler, Mike Grier, Clint Priest, Kyle Adams, guillermo - datatables.net/license */
import jQuery from"jquery";import DataTable from"datatables.net";let $=jQuery;function naturalSort(t,a,r){var e=/(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?%?$|^0x[0-9a-f]+$|[0-9]+)/gi,n=/(^[ ]*|[ ]*$)/g,o=/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,l=/^0x[0-9a-f]+$/i,u=/^0/,c=/(<([^>]+)>)/gi,t=t.toString().replace(n,"")||"",a=a.toString().replace(n,"")||"",i=(r||(t=t.replace(c,""),a=a.replace(c,"")),t.replace(e,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0")),p=a.replace(e,"\0$1\0").replace(/\0$/,"").replace(/^\0/,"").split("\0"),n=parseInt(t.match(l),10)||1!==i.length&&t.match(o)&&Date.parse(t),r=parseInt(a.match(l),10)||n&&a.match(o)&&Date.parse(a)||null;if(r){if(n<r)return-1;if(r<n)return 1}for(var f=0,s=Math.max(i.length,p.length);f<s;f++){var d=!(i[f]||"").match(u)&&parseFloat(i[f])||i[f]||0,m=!(p[f]||"").match(u)&&parseFloat(p[f])||p[f]||0;if(isNaN(d)!==isNaN(m))return isNaN(d)?1:-1;if(typeof d!=typeof m&&(d+="",m+=""),d<m)return-1;if(m<d)return 1}return 0}DataTable.ext.type.order["natural-asc"]=function(t,a){return naturalSort(t,a,!0)},DataTable.ext.type.order["natural-desc"]=function(t,a){return-1*naturalSort(t,a,!0)},DataTable.ext.type.order["natural-nohtml-asc"]=function(t,a){return naturalSort(t,a,!1)},DataTable.ext.type.order["natural-nohtml-desc"]=function(t,a){return-1*naturalSort(t,a,!1)},DataTable.ext.type.order["natural-ci-asc"]=function(t,a){return naturalSort(t=t.toString().toLowerCase(),a=a.toString().toLowerCase(),!0)},DataTable.ext.type.order["natural-ci-desc"]=function(t,a){return-1*naturalSort(t=t.toString().toLowerCase(),a=a.toString().toLowerCase(),!0)};export default DataTable;