shared.d.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. export declare const assign: {
  2. <T extends {}, U>(target: T, source: U): T & U;
  3. <T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
  4. <T_2 extends {}, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
  5. (target: object, ...sources: any[]): any;
  6. };
  7. export declare interface BaseError {
  8. code: number;
  9. }
  10. /**
  11. * Create a event emitter
  12. *
  13. * @returns An event emitter
  14. */
  15. export declare function createEmitter<Events extends Record<EventType, unknown>>(): Emittable<Events>;
  16. export declare function deepCopy(src: any, des: any): void;
  17. /**
  18. * Event emitter interface
  19. */
  20. export declare interface Emittable<Events extends Record<EventType, unknown> = {}> {
  21. /**
  22. * A map of event names of registered event handlers
  23. */
  24. events: EventHandlerMap<Events>;
  25. /**
  26. * Register an event handler with the event type
  27. *
  28. * @param event - An {@link EventType}
  29. * @param handler - An {@link EventHandler}, or a {@link WildcardEventHandler} if you are specified "*"
  30. */
  31. on<Key extends keyof Events>(event: Key | '*', handler: EventHandler<Events[keyof Events]> | WildcardEventHandler<Events>): void;
  32. /**
  33. * Unregister an event handler for the event type
  34. *
  35. * @param event - An {@link EventType}
  36. * @param handler - An {@link EventHandler}, or a {@link WildcardEventHandler} if you are specified "*"
  37. */
  38. off<Key extends keyof Events>(event: Key | '*', handler: EventHandler<Events[keyof Events]> | WildcardEventHandler<Events>): void;
  39. /**
  40. * Invoke all handlers with the event type
  41. *
  42. * @remarks
  43. * Note Manually firing "*" handlers should be not supported
  44. *
  45. * @param event - An {@link EventType}
  46. * @param payload - An event payload, optional
  47. */
  48. emit<Key extends keyof Events>(event: Key, payload?: Events[keyof Events]): void;
  49. }
  50. export declare function escapeHtml(rawText: string): string;
  51. /**
  52. * Event handler
  53. */
  54. export declare type EventHandler<T = unknown> = (payload?: T) => void;
  55. /**
  56. * Event handler list
  57. */
  58. export declare type EventHandlerList<T = unknown> = Array<EventHandler<T>>;
  59. /**
  60. * Event handler map
  61. */
  62. export declare type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<keyof Events | '*', EventHandlerList<Events[keyof Events]> | WildcardEventHandlerList<Events>>;
  63. /**
  64. * Event type
  65. */
  66. export declare type EventType = string | symbol;
  67. export declare function format(message: string, ...args: any): string;
  68. export declare const friendlyJSONstringify: (json: unknown) => string;
  69. export declare function generateCodeFrame(source: string, start?: number, end?: number): string;
  70. export declare const generateFormatCacheKey: (locale: string, key: string, source: string) => string;
  71. export declare const getGlobalThis: () => any;
  72. export declare function hasOwn(obj: object | Array<any>, key: string): boolean;
  73. /**
  74. * Original Utilities
  75. * written by kazuya kawaguchi
  76. */
  77. export declare const inBrowser: boolean;
  78. export declare function incrementer(code: number): () => number;
  79. /**
  80. * Useful Utilities By Evan you
  81. * Modified by kazuya kawaguchi
  82. * MIT License
  83. * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
  84. * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
  85. */
  86. export declare const isArray: (arg: any) => arg is any[];
  87. export declare const isBoolean: (val: unknown) => val is boolean;
  88. export declare const isDate: (val: unknown) => val is Date;
  89. export declare const isEmptyObject: (val: unknown) => val is boolean;
  90. export declare const isFunction: (val: unknown) => val is Function;
  91. export declare const isNumber: (val: unknown) => val is number;
  92. export declare const isObject: (val: unknown) => val is Record<any, any>;
  93. export declare const isPlainObject: (val: unknown) => val is object;
  94. export declare const isPromise: <T = any>(val: unknown) => val is Promise<T>;
  95. export declare const isRegExp: (val: unknown) => val is RegExp;
  96. export declare const isString: (val: unknown) => val is string;
  97. export declare const isSymbol: (val: unknown) => val is symbol;
  98. export declare function join(items: string[], separator?: string): string;
  99. export declare const makeSymbol: (name: string, shareable?: boolean) => symbol;
  100. export declare let mark: (tag: string) => void | undefined;
  101. export declare let measure: (name: string, startTag: string, endTag: string) => void | undefined;
  102. export declare const objectToString: () => string;
  103. export declare const toDisplayString: (val: unknown) => string;
  104. export declare const toTypeString: (value: unknown) => string;
  105. export declare function warn(msg: string, err?: Error): void;
  106. export declare function warnOnce(msg: string): void;
  107. /**
  108. * Wildcard event handler
  109. */
  110. export declare type WildcardEventHandler<T = Record<string, unknown>> = (event: keyof T, payload?: T[keyof T]) => void;
  111. /**
  112. * Wildcard event handler list
  113. */
  114. export declare type WildcardEventHandlerList<T = Record<string, unknown>> = Array<WildcardEventHandler<T>>;
  115. export { }