@fluid-internal/client-utils 2.0.0-dev-rc.1.0.0.224419

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/.eslintrc.js +16 -0
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +37 -0
  4. package/LICENSE +21 -0
  5. package/README.md +75 -0
  6. package/api-extractor-lint.json +4 -0
  7. package/api-extractor.json +4 -0
  8. package/api-report/client-utils.api.md +130 -0
  9. package/dist/base64Encoding.cjs +46 -0
  10. package/dist/base64Encoding.cjs.map +1 -0
  11. package/dist/base64Encoding.d.ts +28 -0
  12. package/dist/base64Encoding.d.ts.map +1 -0
  13. package/dist/bufferBrowser.cjs +212 -0
  14. package/dist/bufferBrowser.cjs.map +1 -0
  15. package/dist/bufferBrowser.d.ts +84 -0
  16. package/dist/bufferBrowser.d.ts.map +1 -0
  17. package/dist/bufferNode.cjs +59 -0
  18. package/dist/bufferNode.cjs.map +1 -0
  19. package/dist/bufferNode.d.ts +62 -0
  20. package/dist/bufferNode.d.ts.map +1 -0
  21. package/dist/bufferShared.cjs +21 -0
  22. package/dist/bufferShared.cjs.map +1 -0
  23. package/dist/bufferShared.d.ts +12 -0
  24. package/dist/bufferShared.d.ts.map +1 -0
  25. package/dist/client-utils-alpha.d.ts +82 -0
  26. package/dist/client-utils-beta.d.ts +73 -0
  27. package/dist/client-utils-public.d.ts +73 -0
  28. package/dist/client-utils-untrimmed.d.ts +247 -0
  29. package/dist/eventForwarder.cjs +98 -0
  30. package/dist/eventForwarder.cjs.map +1 -0
  31. package/dist/eventForwarder.d.ts +34 -0
  32. package/dist/eventForwarder.d.ts.map +1 -0
  33. package/dist/hashFileBrowser.cjs +99 -0
  34. package/dist/hashFileBrowser.cjs.map +1 -0
  35. package/dist/hashFileBrowser.d.ts +30 -0
  36. package/dist/hashFileBrowser.d.ts.map +1 -0
  37. package/dist/hashFileNode.cjs +56 -0
  38. package/dist/hashFileNode.cjs.map +1 -0
  39. package/dist/hashFileNode.d.ts +30 -0
  40. package/dist/hashFileNode.d.ts.map +1 -0
  41. package/dist/index.cjs +45 -0
  42. package/dist/index.cjs.map +1 -0
  43. package/dist/index.d.ts +20 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/indexBrowser.cjs +19 -0
  46. package/dist/indexBrowser.cjs.map +1 -0
  47. package/dist/indexBrowser.d.ts +8 -0
  48. package/dist/indexBrowser.d.ts.map +1 -0
  49. package/dist/indexNode.cjs +19 -0
  50. package/dist/indexNode.cjs.map +1 -0
  51. package/dist/indexNode.d.ts +8 -0
  52. package/dist/indexNode.d.ts.map +1 -0
  53. package/dist/performanceIsomorphic.cjs +17 -0
  54. package/dist/performanceIsomorphic.cjs.map +1 -0
  55. package/dist/performanceIsomorphic.d.ts +21 -0
  56. package/dist/performanceIsomorphic.d.ts.map +1 -0
  57. package/dist/trace.cjs +36 -0
  58. package/dist/trace.cjs.map +1 -0
  59. package/dist/trace.d.ts +40 -0
  60. package/dist/trace.d.ts.map +1 -0
  61. package/dist/tsdoc-metadata.json +11 -0
  62. package/dist/typedEventEmitter.cjs +28 -0
  63. package/dist/typedEventEmitter.cjs.map +1 -0
  64. package/dist/typedEventEmitter.d.ts +36 -0
  65. package/dist/typedEventEmitter.d.ts.map +1 -0
  66. package/jest-puppeteer.config.js +13 -0
  67. package/jest.config.js +20 -0
  68. package/lib/base64Encoding.d.mts +28 -0
  69. package/lib/base64Encoding.d.mts.map +1 -0
  70. package/lib/base64Encoding.mjs +40 -0
  71. package/lib/base64Encoding.mjs.map +1 -0
  72. package/lib/bufferBrowser.d.mts +84 -0
  73. package/lib/bufferBrowser.d.mts.map +1 -0
  74. package/lib/bufferBrowser.mjs +181 -0
  75. package/lib/bufferBrowser.mjs.map +1 -0
  76. package/lib/bufferNode.d.mts +62 -0
  77. package/lib/bufferNode.d.mts.map +1 -0
  78. package/lib/bufferNode.mjs +53 -0
  79. package/lib/bufferNode.mjs.map +1 -0
  80. package/lib/bufferShared.d.mts +12 -0
  81. package/lib/bufferShared.d.mts.map +1 -0
  82. package/lib/bufferShared.mjs +17 -0
  83. package/lib/bufferShared.mjs.map +1 -0
  84. package/lib/client-utils-alpha.d.mts +82 -0
  85. package/lib/client-utils-beta.d.mts +73 -0
  86. package/lib/client-utils-public.d.mts +73 -0
  87. package/lib/client-utils-untrimmed.d.mts +247 -0
  88. package/lib/eventForwarder.d.mts +34 -0
  89. package/lib/eventForwarder.d.mts.map +1 -0
  90. package/lib/eventForwarder.mjs +94 -0
  91. package/lib/eventForwarder.mjs.map +1 -0
  92. package/lib/hashFileBrowser.d.mts +30 -0
  93. package/lib/hashFileBrowser.d.mts.map +1 -0
  94. package/lib/hashFileBrowser.mjs +71 -0
  95. package/lib/hashFileBrowser.mjs.map +1 -0
  96. package/lib/hashFileNode.d.mts +30 -0
  97. package/lib/hashFileNode.d.mts.map +1 -0
  98. package/lib/hashFileNode.mjs +51 -0
  99. package/lib/hashFileNode.mjs.map +1 -0
  100. package/lib/index.d.mts +12 -0
  101. package/lib/index.d.mts.map +1 -0
  102. package/lib/index.mjs +11 -0
  103. package/lib/index.mjs.map +1 -0
  104. package/lib/indexBrowser.d.mts +8 -0
  105. package/lib/indexBrowser.d.mts.map +1 -0
  106. package/lib/indexBrowser.mjs +8 -0
  107. package/lib/indexBrowser.mjs.map +1 -0
  108. package/lib/indexNode.d.mts +8 -0
  109. package/lib/indexNode.d.mts.map +1 -0
  110. package/lib/indexNode.mjs +8 -0
  111. package/lib/indexNode.mjs.map +1 -0
  112. package/lib/performanceIsomorphic.d.mts +21 -0
  113. package/lib/performanceIsomorphic.d.mts.map +1 -0
  114. package/lib/performanceIsomorphic.mjs +14 -0
  115. package/lib/performanceIsomorphic.mjs.map +1 -0
  116. package/lib/trace.d.mts +40 -0
  117. package/lib/trace.d.mts.map +1 -0
  118. package/lib/trace.mjs +32 -0
  119. package/lib/trace.mjs.map +1 -0
  120. package/lib/typedEventEmitter.d.mts +36 -0
  121. package/lib/typedEventEmitter.d.mts.map +1 -0
  122. package/lib/typedEventEmitter.mjs +22 -0
  123. package/lib/typedEventEmitter.mjs.map +1 -0
  124. package/package.json +138 -0
  125. package/prettier.config.cjs +8 -0
  126. package/src/base64Encoding.ts +45 -0
  127. package/src/bufferBrowser.ts +208 -0
  128. package/src/bufferNode.ts +89 -0
  129. package/src/bufferShared.ts +17 -0
  130. package/src/eventForwarder.ts +122 -0
  131. package/src/hashFileBrowser.ts +84 -0
  132. package/src/hashFileNode.ts +59 -0
  133. package/src/index.ts +22 -0
  134. package/src/indexBrowser.ts +14 -0
  135. package/src/indexNode.ts +14 -0
  136. package/src/performanceIsomorphic.ts +23 -0
  137. package/src/trace.ts +58 -0
  138. package/src/typedEventEmitter.ts +79 -0
  139. package/tsc-multi.test.json +4 -0
  140. package/tsconfig.json +13 -0
@@ -0,0 +1,181 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import * as base64js from "base64-js";
6
+ /**
7
+ * Converts a Uint8Array to a string of the provided encoding
8
+ * Useful when the array might be an {@link IsoBuffer}.
9
+ *
10
+ * @param arr - The array to convert.
11
+ * @param encoding - Optional target encoding; only "utf8" and "base64" are
12
+ * supported, with "utf8" being default.
13
+ * @returns The converted string.
14
+ *
15
+ * @internal
16
+ */
17
+ export function Uint8ArrayToString(arr,
18
+ // eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
19
+ encoding) {
20
+ switch (encoding) {
21
+ case "base64": {
22
+ return base64js.fromByteArray(arr);
23
+ }
24
+ case "utf8":
25
+ // eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
26
+ case "utf-8":
27
+ case undefined: {
28
+ return new TextDecoder().decode(arr);
29
+ }
30
+ default: {
31
+ throw new Error("invalid/unsupported encoding");
32
+ }
33
+ }
34
+ }
35
+ /**
36
+ * Converts a {@link https://en.wikipedia.org/wiki/Base64 | base64} or
37
+ * {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8} string to array buffer.
38
+ *
39
+ * @param encoding - The input string's encoding.
40
+ *
41
+ * @internal
42
+ */
43
+ export const stringToBuffer = (input, encoding) => IsoBuffer.from(input, encoding).buffer;
44
+ /**
45
+ * Convert binary blob to string format
46
+ *
47
+ * @param blob - the binary blob
48
+ * @param encoding - output string's encoding
49
+ * @returns the blob in string format
50
+ *
51
+ * @alpha
52
+ */
53
+ export const bufferToString = (blob,
54
+ // eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
55
+ encoding) => IsoBuffer.from(blob).toString(encoding);
56
+ /**
57
+ * Determines if an object is an array buffer.
58
+ *
59
+ * @remarks Will detect and reject TypedArrays, like Uint8Array.
60
+ * Reason - they can be viewport into Array, they can be accepted, but caller has to deal with
61
+ * math properly (i.e. Take into account byteOffset at minimum).
62
+ * For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or
63
+ * new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and
64
+ * ignoring byteOffice, length).
65
+ *
66
+ * @param obj - The object to determine if it is an ArrayBuffer.
67
+ *
68
+ * @internal
69
+ */
70
+ export function isArrayBuffer(obj) {
71
+ const maybe = obj;
72
+ return (obj instanceof ArrayBuffer ||
73
+ (typeof maybe === "object" &&
74
+ maybe !== null &&
75
+ typeof maybe.byteLength === "number" &&
76
+ typeof maybe.slice === "function" &&
77
+ maybe.byteOffset === undefined &&
78
+ maybe.buffer === undefined));
79
+ }
80
+ /**
81
+ * Minimal implementation of Buffer for our usages in the browser environment.
82
+ *
83
+ * @internal
84
+ */
85
+ export class IsoBuffer extends Uint8Array {
86
+ /**
87
+ * Convert the buffer to a string.
88
+ * Only supports encoding the whole string (unlike the Node Buffer equivalent)
89
+ * and only utf8 and base64 encodings.
90
+ *
91
+ * @param encoding - The encoding to use.
92
+ */
93
+ // eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
94
+ toString(encoding) {
95
+ return Uint8ArrayToString(this, encoding);
96
+ }
97
+ /**
98
+ * Static constructor
99
+ * @param value - (string | ArrayBuffer)
100
+ * @param encodingOrOffset - (string | number)
101
+ * @param length - (number)
102
+ *
103
+ * @privateRemarks TODO: Use actual types
104
+ */
105
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
106
+ static from(value, encodingOrOffset, length) {
107
+ if (typeof value === "string") {
108
+ return IsoBuffer.fromString(value, encodingOrOffset);
109
+ // Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!)
110
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
111
+ }
112
+ else if (value !== null && typeof value === "object" && isArrayBuffer(value.buffer)) {
113
+ // The version of the from function for the node buffer, which takes a buffer or typed array
114
+ // as first parameter, does not have any offset or length parameters. Those are just silently
115
+ // ignored and not taken into account
116
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
117
+ return IsoBuffer.fromArrayBuffer(value.buffer, value.byteOffset, value.byteLength);
118
+ }
119
+ else if (isArrayBuffer(value)) {
120
+ return IsoBuffer.fromArrayBuffer(value, encodingOrOffset, length);
121
+ }
122
+ else {
123
+ throw new TypeError("Input value was neither a string nor an ArrayBuffer.");
124
+ }
125
+ }
126
+ static fromArrayBuffer(arrayBuffer, byteOffset, byteLength) {
127
+ const offset = byteOffset ?? 0;
128
+ const validLength = byteLength ?? arrayBuffer.byteLength - offset;
129
+ if (offset < 0 ||
130
+ offset > arrayBuffer.byteLength ||
131
+ validLength < 0 ||
132
+ validLength + offset > arrayBuffer.byteLength) {
133
+ throw new RangeError("Invalid range specified.");
134
+ }
135
+ return new IsoBuffer(arrayBuffer, offset, validLength);
136
+ }
137
+ static fromString(str, encoding) {
138
+ switch (encoding) {
139
+ case "base64": {
140
+ const sanitizedString = this.sanitizeBase64(str);
141
+ const encoded = base64js.toByteArray(sanitizedString);
142
+ return new IsoBuffer(encoded.buffer);
143
+ }
144
+ case "utf8":
145
+ // eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
146
+ case "utf-8":
147
+ case undefined: {
148
+ const encoded = new TextEncoder().encode(str);
149
+ return new IsoBuffer(encoded.buffer);
150
+ }
151
+ default: {
152
+ throw new Error("invalid/unsupported encoding");
153
+ }
154
+ }
155
+ }
156
+ static isBuffer(obj) {
157
+ throw new Error("unimplemented");
158
+ }
159
+ /**
160
+ * Sanitize a base64 string to provide to base64-js library.
161
+ * {@link https://www.npmjs.com/package/base64-js} is not as tolerant of the same malformed base64 as Node'
162
+ * Buffer is.
163
+ */
164
+ static sanitizeBase64(str) {
165
+ let sanitizedStr = str;
166
+ // Remove everything after padding - Node buffer ignores everything
167
+ // after any padding whereas base64-js does not
168
+ sanitizedStr = sanitizedStr.split("=")[0];
169
+ // Remove invalid characters - Node buffer strips invalid characters
170
+ // whereas base64-js replaces them with "A"
171
+ sanitizedStr = sanitizedStr.replace(/[^\w+-/]/g, "");
172
+ // Check for missing padding - Node buffer tolerates missing padding
173
+ // whereas base64-js does not
174
+ if (sanitizedStr.length % 4 !== 0) {
175
+ const paddingArray = ["", "===", "==", "="];
176
+ sanitizedStr += paddingArray[sanitizedStr.length % 4];
177
+ }
178
+ return sanitizedStr;
179
+ }
180
+ }
181
+ //# sourceMappingURL=bufferBrowser.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bufferBrowser.mjs","sourceRoot":"","sources":["../src/bufferBrowser.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,KAAK,QAAQ,MAAM,WAAW;AAErC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CACjC,GAAe;AACf,8GAA8G;AAC9G,QAAsC;IAEtC,QAAQ,QAAQ,EAAE;QACjB,KAAK,QAAQ,CAAC,CAAC;YACd,OAAO,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;SACnC;QACD,KAAK,MAAM,CAAC;QACZ,8GAA8G;QAC9G,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soft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as base64js from \"base64-js\";\n\n/**\n * Converts a Uint8Array to a string of the provided encoding\n * Useful when the array might be an {@link IsoBuffer}.\n *\n * @param arr - The array to convert.\n * @param encoding - Optional target encoding; only \"utf8\" and \"base64\" are\n * supported, with \"utf8\" being default.\n * @returns The converted string.\n *\n * @internal\n */\nexport function Uint8ArrayToString(\n\tarr: Uint8Array,\n\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\tencoding?: \"utf8\" | \"utf-8\" | \"base64\",\n): string {\n\tswitch (encoding) {\n\t\tcase \"base64\": {\n\t\t\treturn base64js.fromByteArray(arr);\n\t\t}\n\t\tcase \"utf8\":\n\t\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\t\tcase \"utf-8\":\n\t\tcase undefined: {\n\t\t\treturn new TextDecoder().decode(arr);\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new Error(\"invalid/unsupported encoding\");\n\t\t}\n\t}\n}\n\n/**\n * Converts a {@link https://en.wikipedia.org/wiki/Base64 | base64} or\n * {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8} string to array buffer.\n *\n * @param encoding - The input string's encoding.\n *\n * @internal\n */\nexport const stringToBuffer = (input: string, encoding: string): ArrayBufferLike =>\n\tIsoBuffer.from(input, encoding).buffer;\n\n/**\n * Convert binary blob to string format\n *\n * @param blob - the binary blob\n * @param encoding - output string's encoding\n * @returns the blob in string format\n *\n * @alpha\n */\nexport const bufferToString = (\n\tblob: ArrayBufferLike,\n\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\tencoding: \"utf8\" | \"utf-8\" | \"base64\",\n): string => IsoBuffer.from(blob).toString(encoding);\n\n/**\n * Determines if an object is an array buffer.\n *\n * @remarks Will detect and reject TypedArrays, like Uint8Array.\n * Reason - they can be viewport into Array, they can be accepted, but caller has to deal with\n * math properly (i.e. Take into account byteOffset at minimum).\n * For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or\n * new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and\n * ignoring byteOffice, length).\n *\n * @param obj - The object to determine if it is an ArrayBuffer.\n *\n * @internal\n */\nexport function isArrayBuffer(obj: unknown): obj is ArrayBuffer {\n\tconst maybe = obj as (Partial<ArrayBuffer> & Partial<Uint8Array>) | undefined;\n\treturn (\n\t\tobj instanceof ArrayBuffer ||\n\t\t(typeof maybe === \"object\" &&\n\t\t\tmaybe !== null &&\n\t\t\ttypeof maybe.byteLength === \"number\" &&\n\t\t\ttypeof maybe.slice === \"function\" &&\n\t\t\tmaybe.byteOffset === undefined &&\n\t\t\tmaybe.buffer === undefined)\n\t);\n}\n\n/**\n * Minimal implementation of Buffer for our usages in the browser environment.\n *\n * @internal\n */\nexport class IsoBuffer extends Uint8Array {\n\t/**\n\t * Convert the buffer to a string.\n\t * Only supports encoding the whole string (unlike the Node Buffer equivalent)\n\t * and only utf8 and base64 encodings.\n\t *\n\t * @param encoding - The encoding to use.\n\t */\n\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\tpublic toString(encoding?: \"utf8\" | \"utf-8\" | \"base64\"): string {\n\t\treturn Uint8ArrayToString(this, encoding);\n\t}\n\n\t/**\n\t * Static constructor\n\t * @param value - (string | ArrayBuffer)\n\t * @param encodingOrOffset - (string | number)\n\t * @param length - (number)\n\t *\n\t * @privateRemarks TODO: Use actual types\n\t */\n\t// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any\n\tstatic from(value: any, encodingOrOffset?: any, length?: any): IsoBuffer {\n\t\tif (typeof value === \"string\") {\n\t\t\treturn IsoBuffer.fromString(value, encodingOrOffset as string | undefined);\n\t\t\t// Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!)\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t} else if (value !== null && typeof value === \"object\" && isArrayBuffer(value.buffer)) {\n\t\t\t// The version of the from function for the node buffer, which takes a buffer or typed array\n\t\t\t// as first parameter, does not have any offset or length parameters. Those are just silently\n\t\t\t// ignored and not taken into account\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access\n\t\t\treturn IsoBuffer.fromArrayBuffer(value.buffer, value.byteOffset, value.byteLength);\n\t\t} else if (isArrayBuffer(value)) {\n\t\t\treturn IsoBuffer.fromArrayBuffer(\n\t\t\t\tvalue,\n\t\t\t\tencodingOrOffset as number | undefined,\n\t\t\t\tlength as number,\n\t\t\t);\n\t\t} else {\n\t\t\tthrow new TypeError(\"Input value was neither a string nor an ArrayBuffer.\");\n\t\t}\n\t}\n\n\tstatic fromArrayBuffer(\n\t\tarrayBuffer: ArrayBuffer,\n\t\tbyteOffset?: number,\n\t\tbyteLength?: number,\n\t): IsoBuffer {\n\t\tconst offset = byteOffset ?? 0;\n\t\tconst validLength = byteLength ?? arrayBuffer.byteLength - offset;\n\t\tif (\n\t\t\toffset < 0 ||\n\t\t\toffset > arrayBuffer.byteLength ||\n\t\t\tvalidLength < 0 ||\n\t\t\tvalidLength + offset > arrayBuffer.byteLength\n\t\t) {\n\t\t\tthrow new RangeError(\"Invalid range specified.\");\n\t\t}\n\n\t\treturn new IsoBuffer(arrayBuffer, offset, validLength);\n\t}\n\n\tstatic fromString(str: string, encoding?: string): IsoBuffer {\n\t\tswitch (encoding) {\n\t\t\tcase \"base64\": {\n\t\t\t\tconst sanitizedString = this.sanitizeBase64(str);\n\t\t\t\tconst encoded = base64js.toByteArray(sanitizedString);\n\t\t\t\treturn new IsoBuffer(encoded.buffer);\n\t\t\t}\n\t\t\tcase \"utf8\":\n\t\t\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\t\t\tcase \"utf-8\":\n\t\t\tcase undefined: {\n\t\t\t\tconst encoded = new TextEncoder().encode(str);\n\t\t\t\treturn new IsoBuffer(encoded.buffer);\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new Error(\"invalid/unsupported encoding\");\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic isBuffer(obj: unknown): boolean {\n\t\tthrow new Error(\"unimplemented\");\n\t}\n\n\t/**\n\t * Sanitize a base64 string to provide to base64-js library.\n\t * {@link https://www.npmjs.com/package/base64-js} is not as tolerant of the same malformed base64 as Node'\n\t * Buffer is.\n\t */\n\tprivate static sanitizeBase64(str: string): string {\n\t\tlet sanitizedStr = str;\n\t\t// Remove everything after padding - Node buffer ignores everything\n\t\t// after any padding whereas base64-js does not\n\t\tsanitizedStr = sanitizedStr.split(\"=\")[0];\n\n\t\t// Remove invalid characters - Node buffer strips invalid characters\n\t\t// whereas base64-js replaces them with \"A\"\n\t\tsanitizedStr = sanitizedStr.replace(/[^\\w+-/]/g, \"\");\n\n\t\t// Check for missing padding - Node buffer tolerates missing padding\n\t\t// whereas base64-js does not\n\t\tif (sanitizedStr.length % 4 !== 0) {\n\t\t\tconst paddingArray = [\"\", \"===\", \"==\", \"=\"];\n\t\t\tsanitizedStr += paddingArray[sanitizedStr.length % 4];\n\t\t}\n\t\treturn sanitizedStr;\n\t}\n}\n"]}
@@ -0,0 +1,62 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * Declare the subset of Buffer functionality we want to make available instead of
7
+ * exposing the entirely of Node's typings. This should match the public interface
8
+ * of the browser implementation, so any changes made in one should be made in both.
9
+ *
10
+ * @internal
11
+ */
12
+ export declare class Buffer extends Uint8Array {
13
+ toString(encoding?: "utf8" | "utf-8" | "base64"): string;
14
+ /**
15
+ * Static constructor
16
+ *
17
+ * @param value - (string | ArrayBuffer).
18
+ * @param encodingOrOffset - (string | number).
19
+ * @param length - (number).
20
+ *
21
+ * @privateRemarks TODO: Use actual types
22
+ */
23
+ static from(value: unknown, encodingOrOffset?: unknown, length?: unknown): IsoBuffer;
24
+ static isBuffer(obj: unknown): obj is Buffer;
25
+ }
26
+ /**
27
+ * @internal
28
+ */
29
+ export declare const IsoBuffer: typeof Buffer;
30
+ /**
31
+ * @internal
32
+ */
33
+ export type IsoBuffer = Buffer;
34
+ /**
35
+ * Converts a Uint8Array to a string of the provided encoding.
36
+ * @remarks Useful when the array might be an IsoBuffer.
37
+ * @param arr - The array to convert.
38
+ * @param encoding - Optional target encoding; only "utf8" and "base64" are
39
+ * supported, with "utf8" being default.
40
+ * @returns The converted string.
41
+ *
42
+ * @internal
43
+ */
44
+ export declare function Uint8ArrayToString(arr: Uint8Array, encoding?: "utf8" | "utf-8" | "base64"): string;
45
+ /**
46
+ * Convert base64 or utf8 string to array buffer.
47
+ * @param encoding - The input string's encoding.
48
+ *
49
+ * @internal
50
+ */
51
+ export declare function stringToBuffer(input: string, encoding: string): ArrayBufferLike;
52
+ /**
53
+ * Convert binary blob to string format
54
+ *
55
+ * @param blob - The binary blob
56
+ * @param encoding - Output string's encoding
57
+ * @returns The blob in string format
58
+ *
59
+ * @alpha
60
+ */
61
+ export declare const bufferToString: (blob: ArrayBufferLike, encoding: "utf8" | "utf-8" | "base64") => string;
62
+ //# sourceMappingURL=bufferNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bufferNode.d.ts","sourceRoot":"","sources":["../src/bufferNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,UAAU;IAE7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM;IAExD;;;;;;;;OAQG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,gBAAgB,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS;IACpF,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM;CAC5C;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,eAAS,CAAC;AAEhC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CACjC,GAAG,EAAE,UAAU,EAEf,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GACpC,MAAM,CAIR;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,eAAe,CAQ/E;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,SACpB,eAAe,YAEX,MAAM,GAAG,OAAO,GAAG,QAAQ,KACnC,MAAiD,CAAC"}
@@ -0,0 +1,53 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * @internal
7
+ */
8
+ export const IsoBuffer = Buffer;
9
+ /**
10
+ * Converts a Uint8Array to a string of the provided encoding.
11
+ * @remarks Useful when the array might be an IsoBuffer.
12
+ * @param arr - The array to convert.
13
+ * @param encoding - Optional target encoding; only "utf8" and "base64" are
14
+ * supported, with "utf8" being default.
15
+ * @returns The converted string.
16
+ *
17
+ * @internal
18
+ */
19
+ export function Uint8ArrayToString(arr,
20
+ // eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
21
+ encoding) {
22
+ // Buffer extends Uint8Array. Therefore, 'arr' may already be a Buffer, in
23
+ // which case we can avoid copying the Uint8Array into a new Buffer instance.
24
+ return (Buffer.isBuffer(arr) ? arr : Buffer.from(arr)).toString(encoding);
25
+ }
26
+ /**
27
+ * Convert base64 or utf8 string to array buffer.
28
+ * @param encoding - The input string's encoding.
29
+ *
30
+ * @internal
31
+ */
32
+ export function stringToBuffer(input, encoding) {
33
+ const iso = IsoBuffer.from(input, encoding);
34
+ // In a Node environment, IsoBuffer may be a Node.js Buffer. Node.js will
35
+ // pool multiple small Buffer instances into a single ArrayBuffer, in which
36
+ // case we need to slice the appropriate span of bytes.
37
+ return iso.byteLength === iso.buffer.byteLength
38
+ ? iso.buffer
39
+ : iso.buffer.slice(iso.byteOffset, iso.byteOffset + iso.byteLength);
40
+ }
41
+ /**
42
+ * Convert binary blob to string format
43
+ *
44
+ * @param blob - The binary blob
45
+ * @param encoding - Output string's encoding
46
+ * @returns The blob in string format
47
+ *
48
+ * @alpha
49
+ */
50
+ export const bufferToString = (blob,
51
+ // eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
52
+ encoding) => IsoBuffer.from(blob).toString(encoding);
53
+ //# sourceMappingURL=bufferNode.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bufferNode.mjs","sourceRoot":"","sources":["../src/bufferNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA0BH;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC;AAOhC;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CACjC,GAAe;AACf,8GAA8G;AAC9G,QAAsC;IAEtC,2EAA2E;IAC3E,6EAA6E;IAC7E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,QAAgB;IAC7D,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC5C,0EAA0E;IAC1E,2EAA2E;IAC3E,uDAAuD;IACvD,OAAO,GAAG,CAAC,UAAU,KAAK,GAAG,CAAC,MAAM,CAAC,UAAU;QAC9C,CAAC,CAAC,GAAG,CAAC,MAAM;QACZ,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC;AACtE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC7B,IAAqB;AACrB,8GAA8G;AAC9G,QAAqC,EAC5B,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Declare the subset of Buffer functionality we want to make available instead of\n * exposing the entirely of Node's typings. This should match the public interface\n * of the browser implementation, so any changes made in one should be made in both.\n *\n * @internal\n */\nexport declare class Buffer extends Uint8Array {\n\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\ttoString(encoding?: \"utf8\" | \"utf-8\" | \"base64\"): string;\n\n\t/**\n\t * Static constructor\n\t *\n\t * @param value - (string | ArrayBuffer).\n\t * @param encodingOrOffset - (string | number).\n\t * @param length - (number).\n\t *\n\t * @privateRemarks TODO: Use actual types\n\t */\n\tstatic from(value: unknown, encodingOrOffset?: unknown, length?: unknown): IsoBuffer;\n\tstatic isBuffer(obj: unknown): obj is Buffer;\n}\n\n/**\n * @internal\n */\nexport const IsoBuffer = Buffer;\n\n/**\n * @internal\n */\nexport type IsoBuffer = Buffer;\n\n/**\n * Converts a Uint8Array to a string of the provided encoding.\n * @remarks Useful when the array might be an IsoBuffer.\n * @param arr - The array to convert.\n * @param encoding - Optional target encoding; only \"utf8\" and \"base64\" are\n * supported, with \"utf8\" being default.\n * @returns The converted string.\n *\n * @internal\n */\nexport function Uint8ArrayToString(\n\tarr: Uint8Array,\n\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\tencoding?: \"utf8\" | \"utf-8\" | \"base64\",\n): string {\n\t// Buffer extends Uint8Array. Therefore, 'arr' may already be a Buffer, in\n\t// which case we can avoid copying the Uint8Array into a new Buffer instance.\n\treturn (Buffer.isBuffer(arr) ? arr : Buffer.from(arr)).toString(encoding);\n}\n\n/**\n * Convert base64 or utf8 string to array buffer.\n * @param encoding - The input string's encoding.\n *\n * @internal\n */\nexport function stringToBuffer(input: string, encoding: string): ArrayBufferLike {\n\tconst iso = IsoBuffer.from(input, encoding);\n\t// In a Node environment, IsoBuffer may be a Node.js Buffer. Node.js will\n\t// pool multiple small Buffer instances into a single ArrayBuffer, in which\n\t// case we need to slice the appropriate span of bytes.\n\treturn iso.byteLength === iso.buffer.byteLength\n\t\t? iso.buffer\n\t\t: iso.buffer.slice(iso.byteOffset, iso.byteOffset + iso.byteLength);\n}\n\n/**\n * Convert binary blob to string format\n *\n * @param blob - The binary blob\n * @param encoding - Output string's encoding\n * @returns The blob in string format\n *\n * @alpha\n */\nexport const bufferToString = (\n\tblob: ArrayBufferLike,\n\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\tencoding: \"utf8\" | \"utf-8\" | \"base64\",\n): string => IsoBuffer.from(blob).toString(encoding);\n"]}
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * Converts a Uint8Array array to an ArrayBuffer.
7
+ * @param array - Array to convert to ArrayBuffer.
8
+ *
9
+ * @internal
10
+ */
11
+ export declare function Uint8ArrayToArrayBuffer(array: Uint8Array): ArrayBuffer;
12
+ //# sourceMappingURL=bufferShared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bufferShared.d.ts","sourceRoot":"","sources":["../src/bufferShared.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAKtE"}
@@ -0,0 +1,17 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * Converts a Uint8Array array to an ArrayBuffer.
7
+ * @param array - Array to convert to ArrayBuffer.
8
+ *
9
+ * @internal
10
+ */
11
+ export function Uint8ArrayToArrayBuffer(array) {
12
+ if (array.byteOffset === 0 && array.byteLength === array.buffer.byteLength) {
13
+ return array.buffer;
14
+ }
15
+ return array.buffer.slice(array.byteOffset, array.byteOffset + array.byteLength);
16
+ }
17
+ //# sourceMappingURL=bufferShared.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bufferShared.mjs","sourceRoot":"","sources":["../src/bufferShared.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAiB;IACxD,IAAI,KAAK,CAAC,UAAU,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,KAAK,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE;QAC3E,OAAO,KAAK,CAAC,MAAM,CAAC;KACpB;IACD,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;AAClF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Converts a Uint8Array array to an ArrayBuffer.\n * @param array - Array to convert to ArrayBuffer.\n *\n * @internal\n */\nexport function Uint8ArrayToArrayBuffer(array: Uint8Array): ArrayBuffer {\n\tif (array.byteOffset === 0 && array.byteLength === array.buffer.byteLength) {\n\t\treturn array.buffer;\n\t}\n\treturn array.buffer.slice(array.byteOffset, array.byteOffset + array.byteLength);\n}\n"]}
@@ -0,0 +1,82 @@
1
+ /// <reference types="node" />
2
+
3
+ import { EventEmitter } from 'events';
4
+ import { IDisposable } from '@fluidframework/core-interfaces';
5
+ import { IEvent } from '@fluidframework/core-interfaces';
6
+ import { IEventProvider } from '@fluidframework/core-interfaces';
7
+ import { IEventTransformer } from '@fluidframework/core-interfaces';
8
+ import { TransformedEvent } from '@fluidframework/core-interfaces';
9
+
10
+ /* Excluded from this release type: Buffer_2 */
11
+
12
+ /**
13
+ * Convert binary blob to string format
14
+ *
15
+ * @param blob - The binary blob
16
+ * @param encoding - Output string's encoding
17
+ * @returns The blob in string format
18
+ *
19
+ * @alpha
20
+ */
21
+ export declare const bufferToString: (blob: ArrayBufferLike, encoding: "utf8" | "utf-8" | "base64") => string;
22
+
23
+ /**
24
+ * The event emitter polyfill and the node event emitter have different event types:
25
+ * string | symbol vs. string | number
26
+ *
27
+ * This type allow us to correctly handle either type
28
+ * @public
29
+ */
30
+ export declare type EventEmitterEventType = EventEmitter extends {
31
+ on(event: infer E, listener: any): any;
32
+ } ? E : never;
33
+
34
+ /* Excluded from this release type: EventForwarder */
35
+
36
+ /* Excluded from this release type: fromBase64ToUtf8 */
37
+
38
+ /* Excluded from this release type: fromUtf8ToBase64 */
39
+
40
+ /* Excluded from this release type: gitHashFile */
41
+
42
+ /* Excluded from this release type: hashFile */
43
+
44
+ /* Excluded from this release type: IsoBuffer */
45
+
46
+ /* Excluded from this release type: IsomorphicPerformance */
47
+
48
+ /* Excluded from this release type: ITraceEvent */
49
+
50
+ /* Excluded from this release type: performance_2 */
51
+
52
+ /* Excluded from this release type: stringToBuffer */
53
+
54
+ /* Excluded from this release type: toUtf8 */
55
+
56
+ /* Excluded from this release type: Trace */
57
+
58
+ /**
59
+ * Event Emitter helper class the supports emitting typed events
60
+ * @public
61
+ */
62
+ export declare class TypedEventEmitter<TEvent> extends EventEmitter implements IEventProvider<TEvent & IEvent> {
63
+ constructor();
64
+ readonly addListener: TypedEventTransform<this, TEvent>;
65
+ readonly on: TypedEventTransform<this, TEvent>;
66
+ readonly once: TypedEventTransform<this, TEvent>;
67
+ readonly prependListener: TypedEventTransform<this, TEvent>;
68
+ readonly prependOnceListener: TypedEventTransform<this, TEvent>;
69
+ readonly removeListener: TypedEventTransform<this, TEvent>;
70
+ readonly off: TypedEventTransform<this, TEvent>;
71
+ }
72
+
73
+ /**
74
+ * @public
75
+ */
76
+ export declare type TypedEventTransform<TThis, TEvent> = TransformedEvent<TThis, "newListener" | "removeListener", Parameters<(event: string, listener: (...args: any[]) => void) => void>> & IEventTransformer<TThis, TEvent & IEvent> & TransformedEvent<TThis, EventEmitterEventType, any[]>;
77
+
78
+ /* Excluded from this release type: Uint8ArrayToArrayBuffer */
79
+
80
+ /* Excluded from this release type: Uint8ArrayToString */
81
+
82
+ export { }
@@ -0,0 +1,73 @@
1
+ /// <reference types="node" />
2
+
3
+ import { EventEmitter } from 'events';
4
+ import { IDisposable } from '@fluidframework/core-interfaces';
5
+ import { IEvent } from '@fluidframework/core-interfaces';
6
+ import { IEventProvider } from '@fluidframework/core-interfaces';
7
+ import { IEventTransformer } from '@fluidframework/core-interfaces';
8
+ import { TransformedEvent } from '@fluidframework/core-interfaces';
9
+
10
+ /* Excluded from this release type: Buffer_2 */
11
+
12
+ /* Excluded from this release type: bufferToString */
13
+
14
+ /**
15
+ * The event emitter polyfill and the node event emitter have different event types:
16
+ * string | symbol vs. string | number
17
+ *
18
+ * This type allow us to correctly handle either type
19
+ * @public
20
+ */
21
+ export declare type EventEmitterEventType = EventEmitter extends {
22
+ on(event: infer E, listener: any): any;
23
+ } ? E : never;
24
+
25
+ /* Excluded from this release type: EventForwarder */
26
+
27
+ /* Excluded from this release type: fromBase64ToUtf8 */
28
+
29
+ /* Excluded from this release type: fromUtf8ToBase64 */
30
+
31
+ /* Excluded from this release type: gitHashFile */
32
+
33
+ /* Excluded from this release type: hashFile */
34
+
35
+ /* Excluded from this release type: IsoBuffer */
36
+
37
+ /* Excluded from this release type: IsomorphicPerformance */
38
+
39
+ /* Excluded from this release type: ITraceEvent */
40
+
41
+ /* Excluded from this release type: performance_2 */
42
+
43
+ /* Excluded from this release type: stringToBuffer */
44
+
45
+ /* Excluded from this release type: toUtf8 */
46
+
47
+ /* Excluded from this release type: Trace */
48
+
49
+ /**
50
+ * Event Emitter helper class the supports emitting typed events
51
+ * @public
52
+ */
53
+ export declare class TypedEventEmitter<TEvent> extends EventEmitter implements IEventProvider<TEvent & IEvent> {
54
+ constructor();
55
+ readonly addListener: TypedEventTransform<this, TEvent>;
56
+ readonly on: TypedEventTransform<this, TEvent>;
57
+ readonly once: TypedEventTransform<this, TEvent>;
58
+ readonly prependListener: TypedEventTransform<this, TEvent>;
59
+ readonly prependOnceListener: TypedEventTransform<this, TEvent>;
60
+ readonly removeListener: TypedEventTransform<this, TEvent>;
61
+ readonly off: TypedEventTransform<this, TEvent>;
62
+ }
63
+
64
+ /**
65
+ * @public
66
+ */
67
+ export declare type TypedEventTransform<TThis, TEvent> = TransformedEvent<TThis, "newListener" | "removeListener", Parameters<(event: string, listener: (...args: any[]) => void) => void>> & IEventTransformer<TThis, TEvent & IEvent> & TransformedEvent<TThis, EventEmitterEventType, any[]>;
68
+
69
+ /* Excluded from this release type: Uint8ArrayToArrayBuffer */
70
+
71
+ /* Excluded from this release type: Uint8ArrayToString */
72
+
73
+ export { }
@@ -0,0 +1,73 @@
1
+ /// <reference types="node" />
2
+
3
+ import { EventEmitter } from 'events';
4
+ import { IDisposable } from '@fluidframework/core-interfaces';
5
+ import { IEvent } from '@fluidframework/core-interfaces';
6
+ import { IEventProvider } from '@fluidframework/core-interfaces';
7
+ import { IEventTransformer } from '@fluidframework/core-interfaces';
8
+ import { TransformedEvent } from '@fluidframework/core-interfaces';
9
+
10
+ /* Excluded from this release type: Buffer_2 */
11
+
12
+ /* Excluded from this release type: bufferToString */
13
+
14
+ /**
15
+ * The event emitter polyfill and the node event emitter have different event types:
16
+ * string | symbol vs. string | number
17
+ *
18
+ * This type allow us to correctly handle either type
19
+ * @public
20
+ */
21
+ export declare type EventEmitterEventType = EventEmitter extends {
22
+ on(event: infer E, listener: any): any;
23
+ } ? E : never;
24
+
25
+ /* Excluded from this release type: EventForwarder */
26
+
27
+ /* Excluded from this release type: fromBase64ToUtf8 */
28
+
29
+ /* Excluded from this release type: fromUtf8ToBase64 */
30
+
31
+ /* Excluded from this release type: gitHashFile */
32
+
33
+ /* Excluded from this release type: hashFile */
34
+
35
+ /* Excluded from this release type: IsoBuffer */
36
+
37
+ /* Excluded from this release type: IsomorphicPerformance */
38
+
39
+ /* Excluded from this release type: ITraceEvent */
40
+
41
+ /* Excluded from this release type: performance_2 */
42
+
43
+ /* Excluded from this release type: stringToBuffer */
44
+
45
+ /* Excluded from this release type: toUtf8 */
46
+
47
+ /* Excluded from this release type: Trace */
48
+
49
+ /**
50
+ * Event Emitter helper class the supports emitting typed events
51
+ * @public
52
+ */
53
+ export declare class TypedEventEmitter<TEvent> extends EventEmitter implements IEventProvider<TEvent & IEvent> {
54
+ constructor();
55
+ readonly addListener: TypedEventTransform<this, TEvent>;
56
+ readonly on: TypedEventTransform<this, TEvent>;
57
+ readonly once: TypedEventTransform<this, TEvent>;
58
+ readonly prependListener: TypedEventTransform<this, TEvent>;
59
+ readonly prependOnceListener: TypedEventTransform<this, TEvent>;
60
+ readonly removeListener: TypedEventTransform<this, TEvent>;
61
+ readonly off: TypedEventTransform<this, TEvent>;
62
+ }
63
+
64
+ /**
65
+ * @public
66
+ */
67
+ export declare type TypedEventTransform<TThis, TEvent> = TransformedEvent<TThis, "newListener" | "removeListener", Parameters<(event: string, listener: (...args: any[]) => void) => void>> & IEventTransformer<TThis, TEvent & IEvent> & TransformedEvent<TThis, EventEmitterEventType, any[]>;
68
+
69
+ /* Excluded from this release type: Uint8ArrayToArrayBuffer */
70
+
71
+ /* Excluded from this release type: Uint8ArrayToString */
72
+
73
+ export { }