util.d.ts 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import * as querystring from 'querystring';
  2. import { PassThrough } from 'stream';
  3. export declare function normalize<T = {}, U = Function>(optionsOrCallback?: T | U, cb?: U): {
  4. options: T;
  5. callback: U;
  6. };
  7. /**
  8. * Flatten an object into an Array of arrays, [[key, value], ..].
  9. * Implements Object.entries() for Node.js <8
  10. * @internal
  11. */
  12. export declare function objectEntries<T>(obj: {
  13. [key: string]: T;
  14. }): Array<[string, T]>;
  15. /**
  16. * Encode `str` with encodeURIComponent, plus these
  17. * reserved characters: `! * ' ( )`.
  18. *
  19. * See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent| MDN: fixedEncodeURIComponent}
  20. *
  21. * @param {string} str The URI component to encode.
  22. * @return {string} The encoded string.
  23. */
  24. export declare function fixedEncodeURIComponent(str: string): string;
  25. /**
  26. * URI encode `uri` for generating signed URLs, using fixedEncodeURIComponent.
  27. *
  28. * Encode every byte except `A-Z a-Z 0-9 ~ - . _`.
  29. *
  30. * @param {string} uri The URI to encode.
  31. * @param [boolean=false] encodeSlash If `true`, the "/" character is not encoded.
  32. * @return {string} The encoded string.
  33. */
  34. export declare function encodeURI(uri: string, encodeSlash: boolean): string;
  35. /**
  36. * Serialize an object to a URL query string using util.encodeURI(uri, true).
  37. * @param {string} url The object to serialize.
  38. * @return {string} Serialized string.
  39. */
  40. export declare function qsStringify(qs: querystring.ParsedUrlQueryInput): string;
  41. export declare function objectKeyToLowercase<T>(object: {
  42. [key: string]: T;
  43. }): {
  44. [key: string]: T;
  45. };
  46. /**
  47. * JSON encode str, with unicode \u+ representation.
  48. * @param {object} obj The object to encode.
  49. * @return {string} Serialized string.
  50. */
  51. export declare function unicodeJSONStringify(obj: object): string;
  52. /**
  53. * Converts the given objects keys to snake_case
  54. * @param {object} obj object to convert keys to snake case.
  55. * @returns {object} object with keys converted to snake case.
  56. */
  57. export declare function convertObjKeysToSnakeCase(obj: object): object;
  58. /**
  59. * Formats the provided date object as a UTC ISO string.
  60. * @param {Date} dateTimeToFormat date object to be formatted.
  61. * @param {boolean} includeTime flag to include hours, minutes, seconds in output.
  62. * @param {string} dateDelimiter delimiter between date components.
  63. * @param {string} timeDelimiter delimiter between time components.
  64. * @returns {string} UTC ISO format of provided date obect.
  65. */
  66. export declare function formatAsUTCISO(dateTimeToFormat: Date, includeTime?: boolean, dateDelimiter?: string, timeDelimiter?: string): string;
  67. /**
  68. * Examines the runtime environment and returns the appropriate tracking string.
  69. * @returns {string} metrics tracking string based on the current runtime environment.
  70. */
  71. export declare function getRuntimeTrackingString(): string;
  72. /**
  73. * Looks at package.json and creates the user-agent string to be applied to request headers.
  74. * @returns {string} user agent string.
  75. */
  76. export declare function getUserAgentString(): string;
  77. export declare function getDirName(): string;
  78. export declare function getModuleFormat(): "ESM" | "CJS";
  79. export declare class PassThroughShim extends PassThrough {
  80. private shouldEmitReading;
  81. private shouldEmitWriting;
  82. _read(size: number): void;
  83. _write(chunk: never, encoding: BufferEncoding, callback: (error?: Error | null | undefined) => void): void;
  84. _final(callback: (error?: Error | null | undefined) => void): void;
  85. }