index.d.mts 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { PropType } from 'vue';
  2. interface DateAdapter<T> {
  3. date(value?: any): T | null;
  4. format(date: T, formatString: string): string;
  5. toJsDate(value: T): Date;
  6. startOfMonth(date: T): T;
  7. endOfMonth(date: T): T;
  8. startOfYear(date: T): T;
  9. endOfYear(date: T): T;
  10. isBefore(date: T, comparing: T): boolean;
  11. isAfter(date: T, comparing: T): boolean;
  12. isEqual(date: T, comparing: T): boolean;
  13. isSameDay(date: T, comparing: T): boolean;
  14. isSameMonth(date: T, comparing: T): boolean;
  15. isValid(date: any): boolean;
  16. isWithinRange(date: T, range: [T, T]): boolean;
  17. addDays(date: T, amount: number): T;
  18. addMonths(date: T, amount: number): T;
  19. getYear(date: T): number;
  20. setYear(date: T, year: number): T;
  21. getDiff(date: T, comparing: T | string, unit?: string): number;
  22. getWeekArray(date: T): T[][];
  23. getWeekdays(): string[];
  24. getMonth(date: T): number;
  25. }
  26. interface DateInstance<T> extends DateAdapter<T> {
  27. locale?: any;
  28. }
  29. type InternalDateOptions<T = any> = {
  30. adapter: (new (options: {
  31. locale: any;
  32. }) => DateInstance<T>) | DateInstance<T>;
  33. formats?: Record<string, string>;
  34. locale: Record<string, any>;
  35. };
  36. type DateOptions<T = any> = Partial<InternalDateOptions<T>>;
  37. declare const makeDateProps: <Defaults extends {
  38. displayDate?: unknown;
  39. hideAdjacentMonths?: unknown;
  40. modelValue?: unknown;
  41. } = {}>(defaults?: Defaults | undefined) => {
  42. displayDate: unknown extends Defaults["displayDate"] ? {
  43. type: PropType<Date>;
  44. default: Date;
  45. } : Omit<{
  46. type: PropType<Date>;
  47. default: Date;
  48. }, "type" | "default"> & {
  49. type: PropType<unknown extends Defaults["displayDate"] ? Date : Date | Defaults["displayDate"]>;
  50. default: unknown extends Defaults["displayDate"] ? Date : Date | Defaults["displayDate"];
  51. };
  52. hideAdjacentMonths: unknown extends Defaults["hideAdjacentMonths"] ? BooleanConstructor : {
  53. type: PropType<unknown extends Defaults["hideAdjacentMonths"] ? boolean : boolean | Defaults["hideAdjacentMonths"]>;
  54. default: unknown extends Defaults["hideAdjacentMonths"] ? boolean : boolean | Defaults["hideAdjacentMonths"];
  55. };
  56. modelValue: unknown extends Defaults["modelValue"] ? {
  57. type: PropType<readonly any[]>;
  58. default: () => never[];
  59. } : Omit<{
  60. type: PropType<readonly any[]>;
  61. default: () => never[];
  62. }, "type" | "default"> & {
  63. type: PropType<unknown extends Defaults["modelValue"] ? readonly any[] : readonly any[] | Defaults["modelValue"]>;
  64. default: unknown extends Defaults["modelValue"] ? readonly any[] : readonly any[] | Defaults["modelValue"];
  65. };
  66. };
  67. declare function useDate(): {
  68. locale?: any;
  69. date: (value?: any) => any;
  70. format: (date: any, formatString: string) => string;
  71. toJsDate: (value: any) => Date;
  72. startOfMonth: (date: any) => any;
  73. endOfMonth: (date: any) => any;
  74. startOfYear: (date: any) => any;
  75. endOfYear: (date: any) => any;
  76. isBefore: (date: any, comparing: any) => boolean;
  77. isAfter: (date: any, comparing: any) => boolean;
  78. isEqual: (date: any, comparing: any) => boolean;
  79. isSameDay: (date: any, comparing: any) => boolean;
  80. isSameMonth: (date: any, comparing: any) => boolean;
  81. isValid: (date: any) => boolean;
  82. isWithinRange: (date: any, range: [any, any]) => boolean;
  83. addDays: (date: any, amount: number) => any;
  84. addMonths: (date: any, amount: number) => any;
  85. getYear: (date: any) => number;
  86. setYear: (date: any, year: number) => any;
  87. getDiff: (date: any, comparing: any, unit?: string | undefined) => number;
  88. getWeekArray: (date: any) => any[][];
  89. getWeekdays: () => string[];
  90. getMonth: (date: any) => number;
  91. };
  92. export { DateAdapter, DateInstance, DateOptions, makeDateProps, useDate };