7b086ac3472600fafbea88d38cf9ca663aeb5b192d37b93b71797c2e1de872ed0b1ddb98159938da213c11a9f446f1fe1403947da0113dd02e95123a181474 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { ParsedValue, DimensionType } from '../../util/types.js';
  2. /**
  3. * Convert raw the value in to inner value in List.
  4. *
  5. * [Performance sensitive]
  6. *
  7. * [Caution]: this is the key logic of user value parser.
  8. * For backward compatibiliy, do not modify it until have to!
  9. */
  10. export declare function parseDataValue(value: any, opt: {
  11. type?: DimensionType;
  12. }): ParsedValue;
  13. export declare type RawValueParserType = 'number' | 'time' | 'trim';
  14. declare type RawValueParser = (val: unknown) => unknown;
  15. export declare function getRawValueParser(type: RawValueParserType): RawValueParser;
  16. export interface FilterComparator {
  17. evaluate(val: unknown): boolean;
  18. }
  19. export declare class SortOrderComparator {
  20. private _incomparable;
  21. private _resultLT;
  22. /**
  23. * @param order by defualt: 'asc'
  24. * @param incomparable by defualt: Always on the tail.
  25. * That is, if 'asc' => 'max', if 'desc' => 'min'
  26. * See the definition of "incomparable" in [SORT_COMPARISON_RULE]
  27. */
  28. constructor(order: 'asc' | 'desc', incomparable: 'min' | 'max');
  29. evaluate(lval: unknown, rval: unknown): -1 | 0 | 1;
  30. }
  31. declare type OrderRelationOperator = 'lt' | 'lte' | 'gt' | 'gte';
  32. export declare type RelationalOperator = OrderRelationOperator | 'eq' | 'ne';
  33. /**
  34. * [FILTER_COMPARISON_RULE]
  35. * `lt`|`lte`|`gt`|`gte`:
  36. * + rval must be a number. And lval will be converted to number (`numericToNumber`) to compare.
  37. * `eq`:
  38. * + If same type, compare with `===`.
  39. * + If there is one number, convert to number (`numericToNumber`) to compare.
  40. * + Else return `false`.
  41. * `ne`:
  42. * + Not `eq`.
  43. *
  44. *
  45. * [SORT_COMPARISON_RULE]
  46. * All the values are grouped into three categories:
  47. * + "numeric" (number and numeric string)
  48. * + "non-numeric-string" (string that excluding numeric string)
  49. * + "others"
  50. * "numeric" vs "numeric": values are ordered by number order.
  51. * "non-numeric-string" vs "non-numeric-string": values are ordered by ES spec (#sec-abstract-relational-comparison).
  52. * "others" vs "others": do not change order (always return 0).
  53. * "numeric" vs "non-numeric-string": "non-numeric-string" is treated as "incomparable".
  54. * "number" vs "others": "others" is treated as "incomparable".
  55. * "non-numeric-string" vs "others": "others" is treated as "incomparable".
  56. * "incomparable" will be seen as -Infinity or Infinity (depends on the settings).
  57. * MEMO:
  58. * non-numeric string sort make sence when need to put the items with the same tag together.
  59. * But if we support string sort, we still need to avoid the misleading like `'2' > '12'`,
  60. * So we treat "numeric-string" sorted by number order rather than string comparison.
  61. *
  62. *
  63. * [CHECK_LIST_OF_THE_RULE_DESIGN]
  64. * + Do not support string comparison until required. And also need to
  65. * void the misleading of "2" > "12".
  66. * + Should avoid the misleading case:
  67. * `" 22 " gte "22"` is `true` but `" 22 " eq "22"` is `false`.
  68. * + JS bad case should be avoided: null <= 0, [] <= 0, ' ' <= 0, ...
  69. * + Only "numeric" can be converted to comparable number, otherwise converted to NaN.
  70. * See `util/number.ts#numericToNumber`.
  71. *
  72. * @return If `op` is not `RelationalOperator`, return null;
  73. */
  74. export declare function createFilterComparator(op: string, rval?: unknown): FilterComparator;
  75. export {};