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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //对数组排序ascii
  2. export function ksort(inputArr, sort_flags) {
  3. var tmp_arr = {},
  4. keys = [],
  5. sorter, i, k, that = this,
  6. strictForIn = false,
  7. populateArr = {};
  8. let php_js = {};
  9. switch (sort_flags) {
  10. case 'SORT_STRING':
  11. // compare items as strings
  12. sorter = function (a, b) {
  13. return that.strnatcmp(a, b);
  14. };
  15. break;
  16. case 'SORT_LOCALE_STRING':
  17. var loc = this.i18n_loc_get_default();
  18. sorter = php_js.i18nLocales[loc].sorting;
  19. break;
  20. case 'SORT_NUMERIC':
  21. // compare items numerically
  22. sorter = function (a, b) {
  23. return ((a + 0) - (b + 0));
  24. };
  25. break;
  26. default:
  27. sorter = function (a, b) {
  28. var aFloat = parseFloat(a),
  29. bFloat = parseFloat(b),
  30. aNumeric = aFloat + '' === a,
  31. bNumeric = bFloat + '' === b;
  32. if (aNumeric && bNumeric) {
  33. return aFloat > bFloat ? 1 : aFloat < bFloat ? -1 : 0;
  34. } else if (aNumeric && !bNumeric) {
  35. return 1;
  36. } else if (!aNumeric && bNumeric) {
  37. return -1;
  38. }
  39. return a > b ? 1 : a < b ? -1 : 0;
  40. };
  41. break;
  42. }
  43. // Make a list of key names
  44. for (k in inputArr) {
  45. if (inputArr.hasOwnProperty(k)) {
  46. keys.push(k);
  47. }
  48. }
  49. keys.sort(sorter);
  50. php_js = php_js || {};
  51. php_js.ini = php_js.ini || {};
  52. // END REDUNDANT
  53. strictForIn = php_js.ini['phpjs.strictForIn'] && php_js.ini['phpjs.strictForIn'].local_value && php_js
  54. .ini['phpjs.strictForIn'].local_value !== 'off';
  55. populateArr = strictForIn ? inputArr : populateArr;
  56. for (i = 0; i < keys.length; i++) {
  57. k = keys[i];
  58. tmp_arr[k] = inputArr[k];
  59. if (strictForIn) {
  60. delete inputArr[k];
  61. }
  62. }
  63. for (i in tmp_arr) {
  64. if (tmp_arr.hasOwnProperty(i)) {
  65. populateArr[i] = tmp_arr[i];
  66. }
  67. }
  68. return strictForIn || populateArr;
  69. }