@fluid-internal/client-utils 2.0.0-internal.6.3.1

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 (149) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +3 -0
  4. package/LICENSE +21 -0
  5. package/README.md +70 -0
  6. package/api-extractor.json +16 -0
  7. package/dist/base64Encoding.d.ts +28 -0
  8. package/dist/base64Encoding.d.ts.map +1 -0
  9. package/dist/base64Encoding.js +43 -0
  10. package/dist/base64Encoding.js.map +1 -0
  11. package/dist/bufferBrowser.d.ts +81 -0
  12. package/dist/bufferBrowser.d.ts.map +1 -0
  13. package/dist/bufferBrowser.js +195 -0
  14. package/dist/bufferBrowser.js.map +1 -0
  15. package/dist/bufferNode.d.ts +58 -0
  16. package/dist/bufferNode.d.ts.map +1 -0
  17. package/dist/bufferNode.js +54 -0
  18. package/dist/bufferNode.js.map +1 -0
  19. package/dist/bufferShared.d.ts +12 -0
  20. package/dist/bufferShared.d.ts.map +1 -0
  21. package/dist/bufferShared.js +21 -0
  22. package/dist/bufferShared.js.map +1 -0
  23. package/dist/eventForwarder.d.ts +33 -0
  24. package/dist/eventForwarder.d.ts.map +1 -0
  25. package/dist/eventForwarder.js +98 -0
  26. package/dist/eventForwarder.js.map +1 -0
  27. package/dist/hashFileBrowser.d.ts +30 -0
  28. package/dist/hashFileBrowser.d.ts.map +1 -0
  29. package/dist/hashFileBrowser.js +95 -0
  30. package/dist/hashFileBrowser.js.map +1 -0
  31. package/dist/hashFileNode.d.ts +30 -0
  32. package/dist/hashFileNode.d.ts.map +1 -0
  33. package/dist/hashFileNode.js +60 -0
  34. package/dist/hashFileNode.js.map +1 -0
  35. package/dist/index.d.ts +20 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +41 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/indexBrowser.d.ts +8 -0
  40. package/dist/indexBrowser.d.ts.map +1 -0
  41. package/dist/indexBrowser.js +19 -0
  42. package/dist/indexBrowser.js.map +1 -0
  43. package/dist/indexNode.d.ts +8 -0
  44. package/dist/indexNode.d.ts.map +1 -0
  45. package/dist/indexNode.js +19 -0
  46. package/dist/indexNode.js.map +1 -0
  47. package/dist/performanceBrowser.d.ts +10 -0
  48. package/dist/performanceBrowser.d.ts.map +1 -0
  49. package/dist/performanceBrowser.js +12 -0
  50. package/dist/performanceBrowser.js.map +1 -0
  51. package/dist/performanceIsomorphic.d.ts +12 -0
  52. package/dist/performanceIsomorphic.d.ts.map +1 -0
  53. package/dist/performanceIsomorphic.js +7 -0
  54. package/dist/performanceIsomorphic.js.map +1 -0
  55. package/dist/performanceNode.d.ts +10 -0
  56. package/dist/performanceNode.d.ts.map +1 -0
  57. package/dist/performanceNode.js +14 -0
  58. package/dist/performanceNode.js.map +1 -0
  59. package/dist/trace.d.ts +40 -0
  60. package/dist/trace.d.ts.map +1 -0
  61. package/dist/trace.js +36 -0
  62. package/dist/trace.js.map +1 -0
  63. package/dist/tsdoc-metadata.json +11 -0
  64. package/dist/typedEventEmitter.d.ts +37 -0
  65. package/dist/typedEventEmitter.d.ts.map +1 -0
  66. package/dist/typedEventEmitter.js +27 -0
  67. package/dist/typedEventEmitter.js.map +1 -0
  68. package/jest-puppeteer.config.js +13 -0
  69. package/jest.config.js +20 -0
  70. package/lib/base64Encoding.d.ts +28 -0
  71. package/lib/base64Encoding.d.ts.map +1 -0
  72. package/lib/base64Encoding.js +37 -0
  73. package/lib/base64Encoding.js.map +1 -0
  74. package/lib/bufferBrowser.d.ts +81 -0
  75. package/lib/bufferBrowser.d.ts.map +1 -0
  76. package/lib/bufferBrowser.js +168 -0
  77. package/lib/bufferBrowser.js.map +1 -0
  78. package/lib/bufferNode.d.ts +58 -0
  79. package/lib/bufferNode.d.ts.map +1 -0
  80. package/lib/bufferNode.js +48 -0
  81. package/lib/bufferNode.js.map +1 -0
  82. package/lib/bufferShared.d.ts +12 -0
  83. package/lib/bufferShared.d.ts.map +1 -0
  84. package/lib/bufferShared.js +17 -0
  85. package/lib/bufferShared.js.map +1 -0
  86. package/lib/eventForwarder.d.ts +33 -0
  87. package/lib/eventForwarder.d.ts.map +1 -0
  88. package/lib/eventForwarder.js +94 -0
  89. package/lib/eventForwarder.js.map +1 -0
  90. package/lib/hashFileBrowser.d.ts +30 -0
  91. package/lib/hashFileBrowser.d.ts.map +1 -0
  92. package/lib/hashFileBrowser.js +71 -0
  93. package/lib/hashFileBrowser.js.map +1 -0
  94. package/lib/hashFileNode.d.ts +30 -0
  95. package/lib/hashFileNode.d.ts.map +1 -0
  96. package/lib/hashFileNode.js +52 -0
  97. package/lib/hashFileNode.js.map +1 -0
  98. package/lib/index.d.ts +20 -0
  99. package/lib/index.d.ts.map +1 -0
  100. package/lib/index.js +21 -0
  101. package/lib/index.js.map +1 -0
  102. package/lib/indexBrowser.d.ts +8 -0
  103. package/lib/indexBrowser.d.ts.map +1 -0
  104. package/lib/indexBrowser.js +8 -0
  105. package/lib/indexBrowser.js.map +1 -0
  106. package/lib/indexNode.d.ts +8 -0
  107. package/lib/indexNode.d.ts.map +1 -0
  108. package/lib/indexNode.js +8 -0
  109. package/lib/indexNode.js.map +1 -0
  110. package/lib/performanceBrowser.d.ts +10 -0
  111. package/lib/performanceBrowser.d.ts.map +1 -0
  112. package/lib/performanceBrowser.js +9 -0
  113. package/lib/performanceBrowser.js.map +1 -0
  114. package/lib/performanceIsomorphic.d.ts +12 -0
  115. package/lib/performanceIsomorphic.d.ts.map +1 -0
  116. package/lib/performanceIsomorphic.js +6 -0
  117. package/lib/performanceIsomorphic.js.map +1 -0
  118. package/lib/performanceNode.d.ts +10 -0
  119. package/lib/performanceNode.d.ts.map +1 -0
  120. package/lib/performanceNode.js +11 -0
  121. package/lib/performanceNode.js.map +1 -0
  122. package/lib/trace.d.ts +40 -0
  123. package/lib/trace.d.ts.map +1 -0
  124. package/lib/trace.js +32 -0
  125. package/lib/trace.js.map +1 -0
  126. package/lib/typedEventEmitter.d.ts +37 -0
  127. package/lib/typedEventEmitter.d.ts.map +1 -0
  128. package/lib/typedEventEmitter.js +23 -0
  129. package/lib/typedEventEmitter.js.map +1 -0
  130. package/package.json +140 -0
  131. package/prettier.config.cjs +8 -0
  132. package/src/base64Encoding.ts +42 -0
  133. package/src/bufferBrowser.ts +188 -0
  134. package/src/bufferNode.ts +75 -0
  135. package/src/bufferShared.ts +17 -0
  136. package/src/eventForwarder.ts +120 -0
  137. package/src/hashFileBrowser.ts +82 -0
  138. package/src/hashFileNode.ts +59 -0
  139. package/src/index.ts +22 -0
  140. package/src/indexBrowser.ts +14 -0
  141. package/src/indexNode.ts +14 -0
  142. package/src/performanceBrowser.ts +11 -0
  143. package/src/performanceIsomorphic.ts +13 -0
  144. package/src/performanceNode.ts +13 -0
  145. package/src/trace.ts +58 -0
  146. package/src/typedEventEmitter.ts +76 -0
  147. package/tsconfig.esnext.json +7 -0
  148. package/tsconfig.json +14 -0
  149. package/types/perf_hooks.d.ts +10 -0
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.performance = void 0;
8
+ /**
9
+ * @internal
10
+ */
11
+ exports.performance = globalThis.performance;
12
+ //# sourceMappingURL=performanceBrowser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"performanceBrowser.js","sourceRoot":"","sources":["../src/performanceBrowser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH;;GAEG;AACU,QAAA,WAAW,GAA0B,UAAU,CAAC,WAAW,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IsomorphicPerformance } from \"./performanceIsomorphic\";\n\n/**\n * @internal\n */\nexport const performance: IsomorphicPerformance = globalThis.performance;\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
+ * This type contains all browser performance properties as optional, and some
7
+ * of the intersecting properties of node and browser performance as required.
8
+ *
9
+ * @internal
10
+ */
11
+ export declare type IsomorphicPerformance = Partial<Performance> & Pick<Performance, "clearMarks" | "mark" | "measure" | "now">;
12
+ //# sourceMappingURL=performanceIsomorphic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"performanceIsomorphic.d.ts","sourceRoot":"","sources":["../src/performanceIsomorphic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,oBAAY,qBAAqB,GAAG,OAAO,CAAC,WAAW,CAAC,GACvD,IAAI,CAAC,WAAW,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=performanceIsomorphic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"performanceIsomorphic.js","sourceRoot":"","sources":["../src/performanceIsomorphic.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * This type contains all browser performance properties as optional, and some\n * of the intersecting properties of node and browser performance as required.\n *\n * @internal\n */\nexport type IsomorphicPerformance = Partial<Performance> &\n\tPick<Performance, \"clearMarks\" | \"mark\" | \"measure\" | \"now\">;\n"]}
@@ -0,0 +1,10 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IsomorphicPerformance } from "./performanceIsomorphic";
6
+ /**
7
+ * @internal
8
+ */
9
+ export declare const performance: IsomorphicPerformance;
10
+ //# sourceMappingURL=performanceNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"performanceNode.d.ts","sourceRoot":"","sources":["../src/performanceNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,qBAAuC,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.performance = void 0;
8
+ // eslint-disable-next-line import/no-nodejs-modules
9
+ const perf_hooks_1 = require("perf_hooks");
10
+ /**
11
+ * @internal
12
+ */
13
+ exports.performance = perf_hooks_1.performance;
14
+ //# sourceMappingURL=performanceNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"performanceNode.js","sourceRoot":"","sources":["../src/performanceNode.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,oDAAoD;AACpD,2CAA4D;AAG5D;;GAEG;AACU,QAAA,WAAW,GAA0B,wBAAe,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// eslint-disable-next-line import/no-nodejs-modules\nimport { performance as nodePerformance } from \"perf_hooks\";\nimport { IsomorphicPerformance } from \"./performanceIsomorphic\";\n\n/**\n * @internal\n */\nexport const performance: IsomorphicPerformance = nodePerformance;\n"]}
@@ -0,0 +1,40 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * Helper class for tracing performance of events
7
+ * Time measurements are in milliseconds as a floating point with a decimal
8
+ *
9
+ * @internal
10
+ */
11
+ export declare class Trace {
12
+ readonly startTick: number;
13
+ static start(): Trace;
14
+ protected lastTick: number;
15
+ protected constructor(startTick: number);
16
+ trace(): ITraceEvent;
17
+ }
18
+ /**
19
+ * Event in a performance trace including time elapsed.
20
+ *
21
+ * @internal
22
+ */
23
+ export interface ITraceEvent {
24
+ /**
25
+ * Total time elapsed since the start of the Trace.
26
+ * Measured in milliseconds as a floating point with a decimal
27
+ */
28
+ readonly totalTimeElapsed: number;
29
+ /**
30
+ * Time elapsed since the last trace event.
31
+ * Measured in milliseconds as a floating point with a decimal
32
+ */
33
+ readonly duration: number;
34
+ /**
35
+ * This number represents a relative time which should
36
+ * be consistent for all trace ticks.
37
+ */
38
+ readonly tick: number;
39
+ }
40
+ //# sourceMappingURL=trace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../src/trace.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;GAKG;AACH,qBAAa,KAAK;aAOqB,SAAS,EAAE,MAAM;WANzC,KAAK,IAAI,KAAK;IAK5B,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC3B,SAAS,aAA6B,SAAS,EAAE,MAAM;IAIhD,KAAK,IAAI,WAAW;CAU3B;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC3B;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB"}
package/dist/trace.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.Trace = void 0;
8
+ const indexNode_1 = require("./indexNode");
9
+ /**
10
+ * Helper class for tracing performance of events
11
+ * Time measurements are in milliseconds as a floating point with a decimal
12
+ *
13
+ * @internal
14
+ */
15
+ class Trace {
16
+ constructor(startTick) {
17
+ this.startTick = startTick;
18
+ this.lastTick = startTick;
19
+ }
20
+ static start() {
21
+ const startTick = indexNode_1.performance.now();
22
+ return new Trace(startTick);
23
+ }
24
+ trace() {
25
+ const tick = indexNode_1.performance.now();
26
+ const event = {
27
+ totalTimeElapsed: tick - this.startTick,
28
+ duration: tick - this.lastTick,
29
+ tick,
30
+ };
31
+ this.lastTick = tick;
32
+ return event;
33
+ }
34
+ }
35
+ exports.Trace = Trace;
36
+ //# sourceMappingURL=trace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace.js","sourceRoot":"","sources":["../src/trace.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2CAA0C;AAE1C;;;;;GAKG;AACH,MAAa,KAAK;IAOjB,YAAsC,SAAiB;QAAjB,cAAS,GAAT,SAAS,CAAQ;QACtD,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;IAC3B,CAAC;IARM,MAAM,CAAC,KAAK;QAClB,MAAM,SAAS,GAAG,uBAAW,CAAC,GAAG,EAAE,CAAC;QACpC,OAAO,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;IAOM,KAAK;QACX,MAAM,IAAI,GAAG,uBAAW,CAAC,GAAG,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAG;YACb,gBAAgB,EAAE,IAAI,GAAG,IAAI,CAAC,SAAS;YACvC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC,QAAQ;YAC9B,IAAI;SACJ,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,OAAO,KAAK,CAAC;IACd,CAAC;CACD;AArBD,sBAqBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performance } from \"./indexNode\";\n\n/**\n * Helper class for tracing performance of events\n * Time measurements are in milliseconds as a floating point with a decimal\n *\n * @internal\n */\nexport class Trace {\n\tpublic static start(): Trace {\n\t\tconst startTick = performance.now();\n\t\treturn new Trace(startTick);\n\t}\n\n\tprotected lastTick: number;\n\tprotected constructor(public readonly startTick: number) {\n\t\tthis.lastTick = startTick;\n\t}\n\n\tpublic trace(): ITraceEvent {\n\t\tconst tick = performance.now();\n\t\tconst event = {\n\t\t\ttotalTimeElapsed: tick - this.startTick,\n\t\t\tduration: tick - this.lastTick,\n\t\t\ttick,\n\t\t};\n\t\tthis.lastTick = tick;\n\t\treturn event;\n\t}\n}\n\n/**\n * Event in a performance trace including time elapsed.\n *\n * @internal\n */\nexport interface ITraceEvent {\n\t/**\n\t * Total time elapsed since the start of the Trace.\n\t * Measured in milliseconds as a floating point with a decimal\n\t */\n\treadonly totalTimeElapsed: number;\n\t/**\n\t * Time elapsed since the last trace event.\n\t * Measured in milliseconds as a floating point with a decimal\n\t */\n\treadonly duration: number;\n\t/**\n\t * This number represents a relative time which should\n\t * be consistent for all trace ticks.\n\t */\n\treadonly tick: number;\n}\n"]}
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.34.9"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,37 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { EventEmitter } from "events";
6
+ import { IEvent, TransformedEvent, IEventTransformer, IEventProvider } from "@fluidframework/core-interfaces";
7
+ /**
8
+ * The event emitter polyfill and the node event emitter have different event types:
9
+ * string | symbol vs. string | number
10
+ *
11
+ * This type allow us to correctly handle either type
12
+ *
13
+ * @internal
14
+ */
15
+ export declare type EventEmitterEventType = EventEmitter extends {
16
+ on(event: infer E, listener: any): any;
17
+ } ? E : never;
18
+ /**
19
+ * @internal
20
+ */
21
+ 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[]>;
22
+ /**
23
+ * Event Emitter helper class the supports emitting typed events
24
+ *
25
+ * @internal
26
+ */
27
+ export declare class TypedEventEmitter<TEvent> extends EventEmitter implements IEventProvider<TEvent & IEvent> {
28
+ constructor();
29
+ readonly addListener: TypedEventTransform<this, TEvent>;
30
+ readonly on: TypedEventTransform<this, TEvent>;
31
+ readonly once: TypedEventTransform<this, TEvent>;
32
+ readonly prependListener: TypedEventTransform<this, TEvent>;
33
+ readonly prependOnceListener: TypedEventTransform<this, TEvent>;
34
+ readonly removeListener: TypedEventTransform<this, TEvent>;
35
+ readonly off: TypedEventTransform<this, TEvent>;
36
+ }
37
+ //# sourceMappingURL=typedEventEmitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typedEventEmitter.d.ts","sourceRoot":"","sources":["../src/typedEventEmitter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EACN,MAAM,EACN,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,MAAM,iCAAiC,CAAC;AAEzC;;;;;;;GAOG;AACH,oBAAY,qBAAqB,GAAG,YAAY,SAAS;IAAE,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,GAAG,OAAC;CAAE,GAC3F,CAAC,GACD,KAAK,CAAC;AAET;;GAEG;AACH,oBAAY,mBAAmB,CAAC,KAAK,EAAE,MAAM,IAK5C,gBAAgB,CACf,KAAK,EACL,aAAa,GAAG,gBAAgB,EAChC,UAAU,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,KAAK,IAAI,CAAC,CACvE,GAEA,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,GAEzC,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,EAAE,GAAG,EAAE,CAAC,CAAC;AAExD;;;;GAIG;AACH,qBAAa,iBAAiB,CAAC,MAAM,CACpC,SAAQ,YACR,YAAW,cAAc,CAAC,MAAM,GAAG,MAAM,CAAC;;IAkB1C,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACxD,QAAQ,CAAC,EAAE,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC/C,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACjD,QAAQ,CAAC,eAAe,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5D,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAChE,QAAQ,CAAC,cAAc,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC3D,QAAQ,CAAC,GAAG,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;CAChD"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.TypedEventEmitter = void 0;
8
+ const events_1 = require("events");
9
+ /**
10
+ * Event Emitter helper class the supports emitting typed events
11
+ *
12
+ * @internal
13
+ */
14
+ class TypedEventEmitter extends events_1.EventEmitter {
15
+ constructor() {
16
+ super();
17
+ this.addListener = super.addListener.bind(this);
18
+ this.on = super.on.bind(this);
19
+ this.once = super.once.bind(this);
20
+ this.prependListener = super.prependListener.bind(this);
21
+ this.prependOnceListener = super.prependOnceListener.bind(this);
22
+ this.removeListener = super.removeListener.bind(this);
23
+ this.off = super.off.bind(this);
24
+ }
25
+ }
26
+ exports.TypedEventEmitter = TypedEventEmitter;
27
+ //# sourceMappingURL=typedEventEmitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typedEventEmitter.js","sourceRoot":"","sources":["../src/typedEventEmitter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,mCAAsC;AAsCtC;;;;GAIG;AACH,MAAa,iBACZ,SAAQ,qBAAY;IAGpB;QACC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;QACrF,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;QACnE,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;QACvE,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAGrD,CAAC;QACF,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAG7D,CAAC;QACF,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;QAC3F,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;IACtE,CAAC;CAQD;AA3BD,8CA2BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"events\";\nimport {\n\tIEvent,\n\tTransformedEvent,\n\tIEventTransformer,\n\tIEventProvider,\n} from \"@fluidframework/core-interfaces\";\n\n/**\n * The event emitter polyfill and the node event emitter have different event types:\n * string | symbol vs. string | number\n *\n * This type allow us to correctly handle either type\n *\n * @internal\n */\nexport type EventEmitterEventType = EventEmitter extends { on(event: infer E, listener: any) }\n\t? E\n\t: never;\n\n/**\n * @internal\n */\nexport type TypedEventTransform<TThis, TEvent> =\n\t// Event emitter supports some special events for the emitter itself to use\n\t// this exposes those events for the TypedEventEmitter.\n\t// Since we know what the shape of these events are, we can describe them directly via a TransformedEvent\n\t// which easier than trying to extend TEvent directly\n\tTransformedEvent<\n\t\tTThis,\n\t\t\"newListener\" | \"removeListener\",\n\t\tParameters<(event: string, listener: (...args: any[]) => void) => void>\n\t> &\n\t\t// Expose all the events provides by TEvent\n\t\tIEventTransformer<TThis, TEvent & IEvent> &\n\t\t// Add the default overload so this is covertable to EventEmitter regardless of environment\n\t\tTransformedEvent<TThis, EventEmitterEventType, any[]>;\n\n/**\n * Event Emitter helper class the supports emitting typed events\n *\n * @internal\n */\nexport class TypedEventEmitter<TEvent>\n\textends EventEmitter\n\timplements IEventProvider<TEvent & IEvent>\n{\n\tconstructor() {\n\t\tsuper();\n\t\tthis.addListener = super.addListener.bind(this) as TypedEventTransform<this, TEvent>;\n\t\tthis.on = super.on.bind(this) as TypedEventTransform<this, TEvent>;\n\t\tthis.once = super.once.bind(this) as TypedEventTransform<this, TEvent>;\n\t\tthis.prependListener = super.prependListener.bind(this) as TypedEventTransform<\n\t\t\tthis,\n\t\t\tTEvent\n\t\t>;\n\t\tthis.prependOnceListener = super.prependOnceListener.bind(this) as TypedEventTransform<\n\t\t\tthis,\n\t\t\tTEvent\n\t\t>;\n\t\tthis.removeListener = super.removeListener.bind(this) as TypedEventTransform<this, TEvent>;\n\t\tthis.off = super.off.bind(this) as TypedEventTransform<this, TEvent>;\n\t}\n\treadonly addListener: TypedEventTransform<this, TEvent>;\n\treadonly on: TypedEventTransform<this, TEvent>;\n\treadonly once: TypedEventTransform<this, TEvent>;\n\treadonly prependListener: TypedEventTransform<this, TEvent>;\n\treadonly prependOnceListener: TypedEventTransform<this, TEvent>;\n\treadonly removeListener: TypedEventTransform<this, TEvent>;\n\treadonly off: TypedEventTransform<this, TEvent>;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ module.exports = {
7
+ launch: {
8
+ args: ["--no-sandbox", "--disable-setuid-sandbox"], // https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md#setting-up-chrome-linux-sandbox
9
+ dumpio: true, // output browser console to cmd line
10
+ // slowMo: 500, // slows down process for easier viewing
11
+ // headless: false, // run in the browser
12
+ },
13
+ };
package/jest.config.js ADDED
@@ -0,0 +1,20 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ module.exports = {
7
+ preset: "jest-puppeteer",
8
+ reporters: [
9
+ "default",
10
+ [
11
+ "jest-junit",
12
+ {
13
+ outputDirectory: "nyc",
14
+ outputName: "jest-junit-report.xml",
15
+ },
16
+ ],
17
+ ],
18
+ testMatch: ["**/dist/test/jest/?(*.)+(spec|test).js"],
19
+ testPathIgnorePatterns: ["/node_modules/"],
20
+ };
@@ -0,0 +1,28 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * Converts the provided {@link https://en.wikipedia.org/wiki/Base64 | base64}-encoded string
7
+ * to {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}.
8
+ *
9
+ * @internal
10
+ */
11
+ export declare const fromBase64ToUtf8: (input: string) => string;
12
+ /**
13
+ * Converts the provided {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}-encoded string
14
+ * to {@link https://en.wikipedia.org/wiki/Base64 | base64}.
15
+ *
16
+ * @internal
17
+ */
18
+ export declare const fromUtf8ToBase64: (input: string) => string;
19
+ /**
20
+ * Convenience function to convert unknown encoding to utf8 that avoids
21
+ * buffer copies/encode ops when no conversion is needed.
22
+ * @param input - The source string to convert.
23
+ * @param encoding - The source string's encoding.
24
+ *
25
+ * @internal
26
+ */
27
+ export declare const toUtf8: (input: string, encoding: string) => string;
28
+ //# sourceMappingURL=base64Encoding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64Encoding.d.ts","sourceRoot":"","sources":["../src/base64Encoding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,UAAW,MAAM,KAAG,MACC,CAAC;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,UAAW,MAAM,KAAG,MACA,CAAC;AAElD;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,UAAW,MAAM,YAAY,MAAM,KAAG,MAQxD,CAAC"}
@@ -0,0 +1,37 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IsoBuffer } from "./indexNode";
6
+ /**
7
+ * Converts the provided {@link https://en.wikipedia.org/wiki/Base64 | base64}-encoded string
8
+ * to {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}.
9
+ *
10
+ * @internal
11
+ */
12
+ export const fromBase64ToUtf8 = (input) => IsoBuffer.from(input, "base64").toString("utf-8");
13
+ /**
14
+ * Converts the provided {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}-encoded string
15
+ * to {@link https://en.wikipedia.org/wiki/Base64 | base64}.
16
+ *
17
+ * @internal
18
+ */
19
+ export const fromUtf8ToBase64 = (input) => IsoBuffer.from(input, "utf8").toString("base64");
20
+ /**
21
+ * Convenience function to convert unknown encoding to utf8 that avoids
22
+ * buffer copies/encode ops when no conversion is needed.
23
+ * @param input - The source string to convert.
24
+ * @param encoding - The source string's encoding.
25
+ *
26
+ * @internal
27
+ */
28
+ export const toUtf8 = (input, encoding) => {
29
+ switch (encoding) {
30
+ case "utf8":
31
+ case "utf-8":
32
+ return input;
33
+ default:
34
+ return IsoBuffer.from(input, encoding).toString();
35
+ }
36
+ };
37
+ //# sourceMappingURL=base64Encoding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64Encoding.js","sourceRoot":"","sources":["../src/base64Encoding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAU,EAAE,CACzD,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAU,EAAE,CACzD,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,QAAgB,EAAU,EAAE;IACjE,QAAQ,QAAQ,EAAE;QACjB,KAAK,MAAM,CAAC;QACZ,KAAK,OAAO;YACX,OAAO,KAAK,CAAC;QACd;YACC,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;KACnD;AACF,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IsoBuffer } from \"./indexNode\";\n\n/**\n * Converts the provided {@link https://en.wikipedia.org/wiki/Base64 | base64}-encoded string\n * to {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}.\n *\n * @internal\n */\nexport const fromBase64ToUtf8 = (input: string): string =>\n\tIsoBuffer.from(input, \"base64\").toString(\"utf-8\");\n\n/**\n * Converts the provided {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}-encoded string\n * to {@link https://en.wikipedia.org/wiki/Base64 | base64}.\n *\n * @internal\n */\nexport const fromUtf8ToBase64 = (input: string): string =>\n\tIsoBuffer.from(input, \"utf8\").toString(\"base64\");\n\n/**\n * Convenience function to convert unknown encoding to utf8 that avoids\n * buffer copies/encode ops when no conversion is needed.\n * @param input - The source string to convert.\n * @param encoding - The source string's encoding.\n *\n * @internal\n */\nexport const toUtf8 = (input: string, encoding: string): string => {\n\tswitch (encoding) {\n\t\tcase \"utf8\":\n\t\tcase \"utf-8\":\n\t\t\treturn input;\n\t\tdefault:\n\t\t\treturn IsoBuffer.from(input, encoding).toString();\n\t}\n};\n"]}
@@ -0,0 +1,81 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * Converts a Uint8Array to a string of the provided encoding
7
+ * Useful when the array might be an {@link IsoBuffer}.
8
+ *
9
+ * @param arr - The array to convert.
10
+ * @param encoding - Optional target encoding; only "utf8" and "base64" are
11
+ * supported, with "utf8" being default.
12
+ * @returns The converted string.
13
+ *
14
+ * @internal
15
+ */
16
+ export declare function Uint8ArrayToString(arr: Uint8Array, encoding?: string): string;
17
+ /**
18
+ * Converts a {@link https://en.wikipedia.org/wiki/Base64 | base64} or
19
+ * {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8} string to array buffer.
20
+ *
21
+ * @param encoding - The input string's encoding.
22
+ *
23
+ * @internal
24
+ */
25
+ export declare const stringToBuffer: (input: string, encoding: string) => ArrayBufferLike;
26
+ /**
27
+ * Convert binary blob to string format
28
+ *
29
+ * @param blob - the binary blob
30
+ * @param encoding - output string's encoding
31
+ * @returns the blob in string format
32
+ *
33
+ * @internal
34
+ */
35
+ export declare const bufferToString: (blob: ArrayBufferLike, encoding: string) => string;
36
+ /**
37
+ * Determines if an object is an array buffer.
38
+ *
39
+ * @remarks Will detect and reject TypedArrays, like Uint8Array.
40
+ * Reason - they can be viewport into Array, they can be accepted, but caller has to deal with
41
+ * math properly (i.e. Take into account byteOffset at minimum).
42
+ * For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or
43
+ * new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and
44
+ * ignoring byteOffice, length).
45
+ *
46
+ * @param obj - The object to determine if it is an ArrayBuffer.
47
+ *
48
+ * @internal
49
+ */
50
+ export declare function isArrayBuffer(obj: any): obj is ArrayBuffer;
51
+ /**
52
+ * Minimal implementation of Buffer for our usages in the browser environment.
53
+ *
54
+ * @internal
55
+ */
56
+ export declare class IsoBuffer extends Uint8Array {
57
+ /**
58
+ * Convert the buffer to a string.
59
+ * Only supports encoding the whole string (unlike the Node Buffer equivalent)
60
+ * and only utf8 and base64 encodings.
61
+ *
62
+ * @param encoding - The encoding to use.
63
+ */
64
+ toString(encoding?: string): string;
65
+ /**
66
+ * @param value - (string | ArrayBuffer)
67
+ * @param encodingOrOffset - (string | number)
68
+ * @param length - (number)
69
+ */
70
+ static from(value: any, encodingOrOffset?: any, length?: any): IsoBuffer;
71
+ static fromArrayBuffer(arrayBuffer: ArrayBuffer, byteOffset?: number, byteLength?: number): IsoBuffer;
72
+ static fromString(str: string, encoding?: string): IsoBuffer;
73
+ static isBuffer(obj: any): boolean;
74
+ /**
75
+ * Sanitize a base64 string to provide to base64-js library.
76
+ * {@link https://www.npmjs.com/package/base64-js} is not as tolerant of the same malformed base64 as Node'
77
+ * Buffer is.
78
+ */
79
+ private static sanitizeBase64;
80
+ }
81
+ //# sourceMappingURL=bufferBrowser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bufferBrowser.d.ts","sourceRoot":"","sources":["../src/bufferBrowser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAc7E;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,UAAW,MAAM,YAAY,MAAM,KAAG,eAC1B,CAAC;AAExC;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,SAAU,eAAe,YAAY,MAAM,KAAG,MACjC,CAAC;AAEzC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,WAAW,CAW1D;AAED;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,UAAU;IACxC;;;;;;OAMG;IACI,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;IAI1C;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,KAAA,EAAE,gBAAgB,CAAC,KAAA,EAAE,MAAM,CAAC,KAAA,GAAG,SAAS;IAgBzD,MAAM,CAAC,eAAe,CACrB,WAAW,EAAE,WAAW,EACxB,UAAU,CAAC,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GACjB,SAAS;IAeZ,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS;IAmB5D,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO;IAIlC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;CAkB7B"}
@@ -0,0 +1,168 @@
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, encoding) {
18
+ switch (encoding) {
19
+ case "base64": {
20
+ return base64js.fromByteArray(arr);
21
+ }
22
+ case "utf8":
23
+ case "utf-8":
24
+ case undefined: {
25
+ return new TextDecoder().decode(arr);
26
+ }
27
+ default: {
28
+ throw new Error("invalid/unsupported encoding");
29
+ }
30
+ }
31
+ }
32
+ /**
33
+ * Converts a {@link https://en.wikipedia.org/wiki/Base64 | base64} or
34
+ * {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8} string to array buffer.
35
+ *
36
+ * @param encoding - The input string's encoding.
37
+ *
38
+ * @internal
39
+ */
40
+ export const stringToBuffer = (input, encoding) => IsoBuffer.from(input, encoding).buffer;
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
+ * @internal
49
+ */
50
+ export const bufferToString = (blob, encoding) => IsoBuffer.from(blob).toString(encoding);
51
+ /**
52
+ * Determines if an object is an array buffer.
53
+ *
54
+ * @remarks Will detect and reject TypedArrays, like Uint8Array.
55
+ * Reason - they can be viewport into Array, they can be accepted, but caller has to deal with
56
+ * math properly (i.e. Take into account byteOffset at minimum).
57
+ * For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or
58
+ * new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and
59
+ * ignoring byteOffice, length).
60
+ *
61
+ * @param obj - The object to determine if it is an ArrayBuffer.
62
+ *
63
+ * @internal
64
+ */
65
+ export function isArrayBuffer(obj) {
66
+ const maybe = obj;
67
+ return (obj instanceof ArrayBuffer ||
68
+ (typeof maybe === "object" &&
69
+ maybe !== null &&
70
+ typeof maybe.byteLength === "number" &&
71
+ typeof maybe.slice === "function" &&
72
+ maybe.byteOffset === undefined &&
73
+ maybe.buffer === undefined));
74
+ }
75
+ /**
76
+ * Minimal implementation of Buffer for our usages in the browser environment.
77
+ *
78
+ * @internal
79
+ */
80
+ export class IsoBuffer extends Uint8Array {
81
+ /**
82
+ * Convert the buffer to a string.
83
+ * Only supports encoding the whole string (unlike the Node Buffer equivalent)
84
+ * and only utf8 and base64 encodings.
85
+ *
86
+ * @param encoding - The encoding to use.
87
+ */
88
+ toString(encoding) {
89
+ return Uint8ArrayToString(this, encoding);
90
+ }
91
+ /**
92
+ * @param value - (string | ArrayBuffer)
93
+ * @param encodingOrOffset - (string | number)
94
+ * @param length - (number)
95
+ */
96
+ static from(value, encodingOrOffset, length) {
97
+ if (typeof value === "string") {
98
+ return IsoBuffer.fromString(value, encodingOrOffset);
99
+ // Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!)
100
+ }
101
+ else if (value !== null && typeof value === "object" && isArrayBuffer(value.buffer)) {
102
+ // The version of the from function for the node buffer, which takes a buffer or typed array
103
+ // as first parameter, does not have any offset or length parameters. Those are just silently
104
+ // ignored and not taken into account
105
+ return IsoBuffer.fromArrayBuffer(value.buffer, value.byteOffset, value.byteLength);
106
+ }
107
+ else if (isArrayBuffer(value)) {
108
+ return IsoBuffer.fromArrayBuffer(value, encodingOrOffset, length);
109
+ }
110
+ else {
111
+ throw new TypeError();
112
+ }
113
+ }
114
+ static fromArrayBuffer(arrayBuffer, byteOffset, byteLength) {
115
+ const offset = byteOffset ?? 0;
116
+ const validLength = byteLength ?? arrayBuffer.byteLength - offset;
117
+ if (offset < 0 ||
118
+ offset > arrayBuffer.byteLength ||
119
+ validLength < 0 ||
120
+ validLength + offset > arrayBuffer.byteLength) {
121
+ throw new RangeError();
122
+ }
123
+ return new IsoBuffer(arrayBuffer, offset, validLength);
124
+ }
125
+ static fromString(str, encoding) {
126
+ switch (encoding) {
127
+ case "base64": {
128
+ const sanitizedString = this.sanitizeBase64(str);
129
+ const encoded = base64js.toByteArray(sanitizedString);
130
+ return new IsoBuffer(encoded.buffer);
131
+ }
132
+ case "utf8":
133
+ case "utf-8":
134
+ case undefined: {
135
+ const encoded = new TextEncoder().encode(str);
136
+ return new IsoBuffer(encoded.buffer);
137
+ }
138
+ default: {
139
+ throw new Error("invalid/unsupported encoding");
140
+ }
141
+ }
142
+ }
143
+ static isBuffer(obj) {
144
+ throw new Error("unimplemented");
145
+ }
146
+ /**
147
+ * Sanitize a base64 string to provide to base64-js library.
148
+ * {@link https://www.npmjs.com/package/base64-js} is not as tolerant of the same malformed base64 as Node'
149
+ * Buffer is.
150
+ */
151
+ static sanitizeBase64(str) {
152
+ let sanitizedStr = str;
153
+ // Remove everything after padding - Node buffer ignores everything
154
+ // after any padding whereas base64-js does not
155
+ sanitizedStr = sanitizedStr.split("=")[0];
156
+ // Remove invalid characters - Node buffer strips invalid characters
157
+ // whereas base64-js replaces them with "A"
158
+ sanitizedStr = sanitizedStr.replace(/[^\w+-/]/g, "");
159
+ // Check for missing padding - Node buffer tolerates missing padding
160
+ // whereas base64-js does not
161
+ if (sanitizedStr.length % 4 !== 0) {
162
+ const paddingArray = ["", "===", "==", "="];
163
+ sanitizedStr += paddingArray[sanitizedStr.length % 4];
164
+ }
165
+ return sanitizedStr;
166
+ }
167
+ }
168
+ //# sourceMappingURL=bufferBrowser.js.map