From b78350078856422e9f455e5f5fdb8befdc4732f6 Mon Sep 17 00:00:00 2001 From: noahdarveau-MSFT <109628470+noahdarveau-MSFT@users.noreply.github.com> Date: Thu, 7 Nov 2024 09:37:48 -0800 Subject: [PATCH] noahdarveau/buffer removal (#2598) * replaced buffer with uint8array-extras --- ...-7805c977-c283-42e2-9e37-bbbf82239930.json | 7 + package.json | 1 - packages/teams-js/jest-setup.cjs | 10 + packages/teams-js/jest.config.cjs | 1 + .../src/internal/uint8array-extras/README.md | 1 + .../src/internal/uint8array-extras/license | 9 + .../uint8array-extras/uint8array-extras.ts | 82 ++ packages/teams-js/src/internal/utils.ts | 6 +- packages/teams-js/tsconfig.json | 4 +- packages/teams-js/webpack.config.cjs | 7 - pnpm-lock.yaml | 179 ++-- skeleton-buffer/index.d.ts | 94 -- skeleton-buffer/index.js | 860 ------------------ skeleton-buffer/package.json | 63 -- 14 files changed, 181 insertions(+), 1143 deletions(-) create mode 100644 change/@microsoft-teams-js-7805c977-c283-42e2-9e37-bbbf82239930.json create mode 100644 packages/teams-js/jest-setup.cjs create mode 100644 packages/teams-js/src/internal/uint8array-extras/README.md create mode 100644 packages/teams-js/src/internal/uint8array-extras/license create mode 100644 packages/teams-js/src/internal/uint8array-extras/uint8array-extras.ts delete mode 100644 skeleton-buffer/index.d.ts delete mode 100644 skeleton-buffer/index.js delete mode 100644 skeleton-buffer/package.json diff --git a/change/@microsoft-teams-js-7805c977-c283-42e2-9e37-bbbf82239930.json b/change/@microsoft-teams-js-7805c977-c283-42e2-9e37-bbbf82239930.json new file mode 100644 index 0000000000..b11f7ec8d3 --- /dev/null +++ b/change/@microsoft-teams-js-7805c977-c283-42e2-9e37-bbbf82239930.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "Replaced `Buffer` with `uint8array-extras` to allow for `buffer` polyfill removal", + "packageName": "@microsoft/teams-js", + "email": "109628470+noahdarveau-MSFT@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/package.json b/package.json index 254623d1f6..cf71cf041f 100644 --- a/package.json +++ b/package.json @@ -146,7 +146,6 @@ } }, "dependencies": { - "skeleton-buffer": "file:./skeleton-buffer", "uuid": "^9.0.1" } } diff --git a/packages/teams-js/jest-setup.cjs b/packages/teams-js/jest-setup.cjs new file mode 100644 index 0000000000..c29acb64c6 --- /dev/null +++ b/packages/teams-js/jest-setup.cjs @@ -0,0 +1,10 @@ +/* eslint-disable strict-null-checks/all */ +/* eslint-disable @typescript-eslint/no-var-requires */ + +/** + * This while TextDecoder is supported in both browser and Node environments, it is not supported in jsdom, which we use for our jest environment. + * To resolve this issue, we polyfill TextDecoder with the node implementation prior to rujnning the tests. + */ + +const TextDecoder = require('util').TextDecoder; +global.TextDecoder = TextDecoder; diff --git a/packages/teams-js/jest.config.cjs b/packages/teams-js/jest.config.cjs index 18927534a2..9580ce9390 100644 --- a/packages/teams-js/jest.config.cjs +++ b/packages/teams-js/jest.config.cjs @@ -7,4 +7,5 @@ module.exports = { globals: { PACKAGE_VERSION: packageVersion, }, + setupFilesAfterEnv: ['./jest-setup.cjs'], }; diff --git a/packages/teams-js/src/internal/uint8array-extras/README.md b/packages/teams-js/src/internal/uint8array-extras/README.md new file mode 100644 index 0000000000..56f2135e4f --- /dev/null +++ b/packages/teams-js/src/internal/uint8array-extras/README.md @@ -0,0 +1 @@ +This package is a stripped out version of the [uint8arrays-extras](https://www.npmjs.com/package/uint8array-extras) package, containing only the functionality used by teams-js. It is being directly included in the library instead of an NPM package due to a Jest issue preventing its usage, which is solved by transpiling the file ourselves. This package is used to replace the `Buffer` package as this is both treeshakable and browser-compatible, so we no longer need to polyfill `Buffer`, which is quite size intensive. This provides a much more space-efficient method to providing the needed functionality. To update our `uint8array-extras` package if a new version is released, we will need to look at the new version of the package published to npm and manually copy the contents to our package here. diff --git a/packages/teams-js/src/internal/uint8array-extras/license b/packages/teams-js/src/internal/uint8array-extras/license new file mode 100644 index 0000000000..fa7ceba3eb --- /dev/null +++ b/packages/teams-js/src/internal/uint8array-extras/license @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Sindre Sorhus (https://sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/teams-js/src/internal/uint8array-extras/uint8array-extras.ts b/packages/teams-js/src/internal/uint8array-extras/uint8array-extras.ts new file mode 100644 index 0000000000..7f050f215f --- /dev/null +++ b/packages/teams-js/src/internal/uint8array-extras/uint8array-extras.ts @@ -0,0 +1,82 @@ +const objectToString = Object.prototype.toString; +const uint8ArrayStringified = '[object Uint8Array]'; +const arrayBufferStringified = '[object ArrayBuffer]'; + +const cachedDecoders = { + utf8: new globalThis.TextDecoder('utf8'), +}; + +export type TypedArray = + | Int8Array + | Uint8Array + | Uint8ClampedArray + | Int16Array + | Uint16Array + | Int32Array + | Uint32Array + | Float32Array + | Float64Array + | BigInt64Array + | BigUint64Array; + +function isType(value, typeConstructor, typeStringified): boolean { + if (!value) { + return false; + } + + if (value.constructor === typeConstructor) { + return true; + } + + return objectToString.call(value) === typeStringified; +} + +export function isUint8Array(value: unknown): value is Uint8Array { + return isType(value, Uint8Array, uint8ArrayStringified); +} + +function isArrayBuffer(value): boolean { + return isType(value, ArrayBuffer, arrayBufferStringified); +} + +function assertString(value): void { + if (typeof value !== 'string') { + throw new TypeError(`Expected \`string\`, got \`${typeof value}\``); + } +} + +export function base64ToUint8Array(base64String: string): Uint8Array { + assertString(base64String); + return Uint8Array.from(globalThis.atob(base64UrlToBase64(base64String)), (x) => { + const codePoint = x.codePointAt(0); + if (codePoint === undefined) { + throw new Error('Invalid character encountered'); + } + return codePoint; + }); +} + +function base64UrlToBase64(base64url: string): string { + return base64url.replaceAll('-', '+').replaceAll('_', '/'); +} + +export function uint8ArrayToString(array: Uint8Array | ArrayBuffer, encoding = 'utf8'): string { + assertUint8ArrayOrArrayBuffer(array); + cachedDecoders[encoding] ??= new globalThis.TextDecoder(encoding); + return cachedDecoders[encoding].decode(array); +} + +export function base64ToString(base64String: string): string { + assertString(base64String); + return uint8ArrayToString(base64ToUint8Array(base64String)); +} + +export function assertUint8ArrayOrArrayBuffer(value): void { + if (!isUint8ArrayOrArrayBuffer(value)) { + throw new TypeError(`Expected \`Uint8Array\` or \`ArrayBuffer\`, got \`${typeof value}\``); + } +} + +function isUint8ArrayOrArrayBuffer(value): boolean { + return isUint8Array(value) || isArrayBuffer(value); +} diff --git a/packages/teams-js/src/internal/utils.ts b/packages/teams-js/src/internal/utils.ts index 652871eaad..3599baf885 100644 --- a/packages/teams-js/src/internal/utils.ts +++ b/packages/teams-js/src/internal/utils.ts @@ -1,11 +1,11 @@ /* eslint-disable @typescript-eslint/ban-types */ /* eslint-disable @typescript-eslint/no-unused-vars */ -import { Buffer } from 'buffer'; import * as uuid from 'uuid'; import { minAdaptiveCardVersion } from '../public/constants'; import { AdaptiveCardVersion, SdkError } from '../public/interfaces'; import * as pages from '../public/pages/pages'; +import { base64ToString } from './uint8array-extras/uint8array-extras'; /** * @internal @@ -348,14 +348,14 @@ export function base64ToBlob(mimeType: string, base64String: string): Promise=8'} @@ -7830,7 +7824,7 @@ snapshots: '@jest/console@29.7.0': dependencies: '@jest/types': 29.6.3 - '@types/node': 18.19.39 + '@types/node': 17.0.45 chalk: 4.1.2 jest-message-util: 29.7.0 jest-util: 29.7.0 @@ -7843,14 +7837,14 @@ snapshots: '@jest/test-result': 29.7.0 '@jest/transform': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 18.19.39 + '@types/node': 17.0.45 ansi-escapes: 4.3.2 chalk: 4.1.2 ci-info: 3.9.0 exit: 0.1.2 graceful-fs: 4.2.11 jest-changed-files: 29.7.0 - jest-config: 29.7.0(@types/node@18.19.39)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@16.18.101)(typescript@4.9.5)) + jest-config: 29.7.0(@types/node@17.0.45)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@16.18.101)(typescript@4.9.5)) jest-haste-map: 29.7.0 jest-message-util: 29.7.0 jest-regex-util: 29.6.3 @@ -7875,7 +7869,7 @@ snapshots: dependencies: '@jest/fake-timers': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 18.19.39 + '@types/node': 17.0.45 jest-mock: 29.7.0 '@jest/expect-utils@29.7.0': @@ -7893,7 +7887,7 @@ snapshots: dependencies: '@jest/types': 29.6.3 '@sinonjs/fake-timers': 10.3.0 - '@types/node': 18.19.39 + '@types/node': 17.0.45 jest-message-util: 29.7.0 jest-mock: 29.7.0 jest-util: 29.7.0 @@ -7915,7 +7909,7 @@ snapshots: '@jest/transform': 29.7.0 '@jest/types': 29.6.3 '@jridgewell/trace-mapping': 0.3.25 - '@types/node': 18.19.39 + '@types/node': 17.0.45 chalk: 4.1.2 collect-v8-coverage: 1.0.2 exit: 0.1.2 @@ -7985,7 +7979,7 @@ snapshots: '@jest/schemas': 29.6.3 '@types/istanbul-lib-coverage': 2.0.6 '@types/istanbul-reports': 3.0.4 - '@types/node': 18.19.39 + '@types/node': 17.0.45 '@types/yargs': 17.0.32 chalk: 4.1.2 @@ -8718,20 +8712,20 @@ snapshots: '@types/body-parser@1.19.5': dependencies: '@types/connect': 3.4.38 - '@types/node': 18.19.39 + '@types/node': 17.0.45 '@types/bonjour@3.5.13': dependencies: - '@types/node': 18.19.39 + '@types/node': 17.0.45 '@types/connect-history-api-fallback@1.5.4': dependencies: '@types/express-serve-static-core': 4.19.5 - '@types/node': 18.19.39 + '@types/node': 17.0.45 '@types/connect@3.4.38': dependencies: - '@types/node': 18.19.39 + '@types/node': 17.0.45 '@types/debug@4.1.12': dependencies: @@ -8753,7 +8747,7 @@ snapshots: '@types/express-serve-static-core@4.19.5': dependencies: - '@types/node': 18.19.39 + '@types/node': 17.0.45 '@types/qs': 6.9.15 '@types/range-parser': 1.2.7 '@types/send': 0.17.4 @@ -8771,7 +8765,7 @@ snapshots: '@types/graceful-fs@4.1.9': dependencies: - '@types/node': 18.19.39 + '@types/node': 17.0.45 '@types/html-minifier-terser@6.1.0': {} @@ -8803,7 +8797,7 @@ snapshots: '@types/jsdom@20.0.1': dependencies: - '@types/node': 18.19.39 + '@types/node': 17.0.45 '@types/tough-cookie': 4.0.5 parse5: 7.1.2 @@ -8823,7 +8817,7 @@ snapshots: '@types/node-forge@1.3.11': dependencies: - '@types/node': 18.19.39 + '@types/node': 17.0.45 '@types/node@16.18.101': {} @@ -8867,7 +8861,7 @@ snapshots: '@types/readdir-glob@1.1.5': dependencies: - '@types/node': 18.19.39 + '@types/node': 17.0.45 '@types/resolve@1.20.2': {} @@ -8880,7 +8874,7 @@ snapshots: '@types/send@0.17.4': dependencies: '@types/mime': 1.3.5 - '@types/node': 18.19.39 + '@types/node': 17.0.45 '@types/serve-index@1.9.4': dependencies: @@ -8889,12 +8883,12 @@ snapshots: '@types/serve-static@1.15.7': dependencies: '@types/http-errors': 2.0.4 - '@types/node': 18.19.39 + '@types/node': 17.0.45 '@types/send': 0.17.4 '@types/sockjs@0.3.36': dependencies: - '@types/node': 18.19.39 + '@types/node': 17.0.45 '@types/source-list-map@0.1.6': {} @@ -8925,7 +8919,7 @@ snapshots: '@types/ws@8.5.10': dependencies: - '@types/node': 18.19.39 + '@types/node': 17.0.45 '@types/yargs-parser@21.0.3': {} @@ -9184,34 +9178,17 @@ snapshots: '@webassemblyjs/ast': 1.12.1 '@xtuc/long': 4.2.2 - '@webpack-cli/configtest@2.1.1(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4))': - dependencies: - webpack: 5.96.1(webpack-cli@5.1.4) - webpack-cli: 5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1) - - '@webpack-cli/configtest@2.1.1(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0)(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4))': + '@webpack-cli/configtest@2.1.1(webpack-cli@5.1.4)(webpack@5.96.1)': dependencies: webpack: 5.96.1(webpack-cli@5.1.4) webpack-cli: 5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0)(webpack@5.96.1) - '@webpack-cli/info@2.0.2(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4))': - dependencies: - webpack: 5.96.1(webpack-cli@5.1.4) - webpack-cli: 5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1) - - '@webpack-cli/info@2.0.2(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0)(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4))': + '@webpack-cli/info@2.0.2(webpack-cli@5.1.4)(webpack@5.96.1)': dependencies: webpack: 5.96.1(webpack-cli@5.1.4) webpack-cli: 5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0)(webpack@5.96.1) - '@webpack-cli/serve@2.0.5(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1))(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4))': - dependencies: - webpack: 5.96.1(webpack-cli@5.1.4) - webpack-cli: 5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1) - optionalDependencies: - webpack-dev-server: 5.1.0(webpack-cli@5.1.4)(webpack@5.96.1) - - '@webpack-cli/serve@2.0.5(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0)(webpack@5.96.1))(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4))': + '@webpack-cli/serve@2.0.5(webpack-cli@5.1.4)(webpack-dev-server@5.1.0)(webpack@5.96.1)': dependencies: webpack: 5.96.1(webpack-cli@5.1.4) webpack-cli: 5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0)(webpack@5.96.1) @@ -9489,7 +9466,7 @@ snapshots: transitivePeerDependencies: - supports-color - babel-loader@9.2.1(@babel/core@7.24.7)(webpack@5.96.1(webpack-cli@5.1.4)): + babel-loader@9.2.1(@babel/core@7.24.7)(webpack@5.96.1): dependencies: '@babel/core': 7.24.7 find-cache-dir: 4.0.0 @@ -9663,7 +9640,7 @@ snapshots: browserslist@4.24.2: dependencies: caniuse-lite: 1.0.30001677 - electron-to-chromium: 1.5.50 + electron-to-chromium: 1.5.51 node-releases: 2.0.18 update-browserslist-db: 1.1.1(browserslist@4.24.2) @@ -9988,7 +9965,7 @@ snapshots: cookie@1.0.1: {} - copy-webpack-plugin@12.0.2(webpack@5.96.1(webpack-cli@5.1.4)): + copy-webpack-plugin@12.0.2(webpack@5.96.1): dependencies: fast-glob: 3.3.2 glob-parent: 5.1.2 @@ -10056,7 +10033,7 @@ snapshots: shebang-command: 2.0.0 which: 2.0.2 - css-loader@6.11.0(webpack@5.96.1(webpack-cli@5.1.4)): + css-loader@6.11.0(webpack@5.96.1): dependencies: icss-utils: 5.1.0(postcss@8.4.38) postcss: 8.4.38 @@ -10274,7 +10251,7 @@ snapshots: electron-to-chromium@1.4.812: {} - electron-to-chromium@1.5.50: {} + electron-to-chromium@1.5.51: {} emittery@0.13.1: {} @@ -10753,7 +10730,7 @@ snapshots: dependencies: minimatch: 5.1.6 - filemanager-webpack-plugin@8.0.0(webpack@5.96.1(webpack-cli@5.1.4)): + filemanager-webpack-plugin@8.0.0(webpack@5.96.1): dependencies: '@types/archiver': 5.3.4 archiver: 5.3.2 @@ -11105,7 +11082,7 @@ snapshots: relateurl: 0.2.7 terser: 5.31.1 - html-webpack-plugin@5.6.3(webpack@5.96.1(webpack-cli@5.1.4)): + html-webpack-plugin@5.6.3(webpack@5.96.1): dependencies: '@types/html-minifier-terser': 6.1.0 html-minifier-terser: 6.1.0 @@ -11539,7 +11516,7 @@ snapshots: '@jest/expect': 29.7.0 '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 18.19.39 + '@types/node': 17.0.45 chalk: 4.1.2 co: 4.6.0 dedent: 1.5.3(babel-plugin-macros@3.1.0) @@ -11609,7 +11586,7 @@ snapshots: - babel-plugin-macros - supports-color - jest-config@29.7.0(@types/node@18.19.39)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@16.18.101)(typescript@4.9.5)): + jest-config@29.7.0(@types/node@17.0.45)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@16.18.101)(typescript@4.9.5)): dependencies: '@babel/core': 7.24.7 '@jest/test-sequencer': 29.7.0 @@ -11634,7 +11611,7 @@ snapshots: slash: 3.0.0 strip-json-comments: 3.1.1 optionalDependencies: - '@types/node': 18.19.39 + '@types/node': 17.0.45 ts-node: 10.9.2(@types/node@16.18.101)(typescript@4.9.5) transitivePeerDependencies: - babel-plugin-macros @@ -11686,7 +11663,7 @@ snapshots: '@jest/environment': 29.7.0 '@jest/fake-timers': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 18.19.39 + '@types/node': 17.0.45 jest-mock: 29.7.0 jest-util: 29.7.0 @@ -11698,7 +11675,7 @@ snapshots: dependencies: '@jest/types': 29.6.3 '@types/graceful-fs': 4.1.9 - '@types/node': 18.19.39 + '@types/node': 17.0.45 anymatch: 3.1.3 fb-watchman: 2.0.2 graceful-fs: 4.2.11 @@ -11751,7 +11728,7 @@ snapshots: jest-mock@29.7.0: dependencies: '@jest/types': 29.6.3 - '@types/node': 18.19.39 + '@types/node': 17.0.45 jest-util: 29.7.0 jest-pnp-resolver@1.2.3(jest-resolve@29.7.0): @@ -11786,7 +11763,7 @@ snapshots: '@jest/test-result': 29.7.0 '@jest/transform': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 18.19.39 + '@types/node': 17.0.45 chalk: 4.1.2 emittery: 0.13.1 graceful-fs: 4.2.11 @@ -11814,7 +11791,7 @@ snapshots: '@jest/test-result': 29.7.0 '@jest/transform': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 18.19.39 + '@types/node': 17.0.45 chalk: 4.1.2 cjs-module-lexer: 1.3.1 collect-v8-coverage: 1.0.2 @@ -11860,7 +11837,7 @@ snapshots: jest-util@29.7.0: dependencies: '@jest/types': 29.6.3 - '@types/node': 18.19.39 + '@types/node': 17.0.45 chalk: 4.1.2 ci-info: 3.9.0 graceful-fs: 4.2.11 @@ -11879,7 +11856,7 @@ snapshots: dependencies: '@jest/test-result': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 18.19.39 + '@types/node': 17.0.45 ansi-escapes: 4.3.2 chalk: 4.1.2 emittery: 0.13.1 @@ -11894,7 +11871,7 @@ snapshots: jest-worker@29.7.0: dependencies: - '@types/node': 18.19.39 + '@types/node': 17.0.45 jest-util: 29.7.0 merge-stream: 2.0.0 supports-color: 8.1.1 @@ -13615,10 +13592,6 @@ snapshots: sisteransi@1.0.5: {} - skeleton-buffer@file:skeleton-buffer: - dependencies: - base64-js: 1.5.1 - slash@3.0.0: {} slash@5.1.0: {} @@ -13812,7 +13785,7 @@ snapshots: minimist: 0.2.4 through: 2.3.8 - style-loader@3.3.4(webpack@5.96.1(webpack-cli@5.1.4)): + style-loader@3.3.4(webpack@5.96.1): dependencies: webpack: 5.96.1(webpack-cli@5.1.4) @@ -13866,7 +13839,7 @@ snapshots: temp-dir@1.0.0: {} - terser-webpack-plugin@5.3.10(webpack@5.96.1(webpack-cli@5.1.4)): + terser-webpack-plugin@5.3.10(webpack@5.96.1): dependencies: '@jridgewell/trace-mapping': 0.3.25 jest-worker: 27.5.1 @@ -13972,7 +13945,7 @@ snapshots: '@jest/types': 29.6.3 babel-jest: 29.7.0(@babel/core@7.24.7) - ts-loader@9.5.1(typescript@4.9.5)(webpack@5.96.1(webpack-cli@5.1.4)): + ts-loader@9.5.1(typescript@4.9.5)(webpack@5.96.1): dependencies: chalk: 4.1.2 enhanced-resolve: 5.17.0 @@ -14234,7 +14207,7 @@ snapshots: webidl-conversions@7.0.0: {} - webpack-assets-manifest@5.2.1(webpack@5.96.1(webpack-cli@5.1.4)): + webpack-assets-manifest@5.2.1(webpack@5.96.1): dependencies: chalk: 4.1.2 deepmerge: 4.3.1 @@ -14263,32 +14236,12 @@ snapshots: - bufferutil - utf-8-validate - webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1): - dependencies: - '@discoveryjs/json-ext': 0.5.7 - '@webpack-cli/configtest': 2.1.1(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4)) - '@webpack-cli/info': 2.0.2(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4)) - '@webpack-cli/serve': 2.0.5(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1))(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4)) - colorette: 2.0.20 - commander: 10.0.1 - cross-spawn: 7.0.3 - envinfo: 7.13.0 - fastest-levenshtein: 1.0.16 - import-local: 3.1.0 - interpret: 3.1.1 - rechoir: 0.8.0 - webpack: 5.96.1(webpack-cli@5.1.4) - webpack-merge: 5.10.0 - optionalDependencies: - webpack-bundle-analyzer: 4.10.2 - webpack-dev-server: 5.1.0(webpack-cli@5.1.4)(webpack@5.96.1) - webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0)(webpack@5.96.1): dependencies: '@discoveryjs/json-ext': 0.5.7 - '@webpack-cli/configtest': 2.1.1(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0)(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4)) - '@webpack-cli/info': 2.0.2(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0)(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4)) - '@webpack-cli/serve': 2.0.5(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0)(webpack@5.96.1))(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1(webpack-cli@5.1.4)) + '@webpack-cli/configtest': 2.1.1(webpack-cli@5.1.4)(webpack@5.96.1) + '@webpack-cli/info': 2.0.2(webpack-cli@5.1.4)(webpack@5.96.1) + '@webpack-cli/serve': 2.0.5(webpack-cli@5.1.4)(webpack-dev-server@5.1.0)(webpack@5.96.1) colorette: 2.0.20 commander: 10.0.1 cross-spawn: 7.0.3 @@ -14303,7 +14256,7 @@ snapshots: webpack-bundle-analyzer: 4.10.2 webpack-dev-server: 5.1.0(webpack-cli@5.1.4)(webpack@5.96.1) - webpack-dev-middleware@7.4.2(webpack@5.96.1(webpack-cli@5.1.4)): + webpack-dev-middleware@7.4.2(webpack@5.96.1): dependencies: colorette: 2.0.20 memfs: 4.9.3 @@ -14342,7 +14295,7 @@ snapshots: serve-index: 1.9.1 sockjs: 0.3.24 spdy: 4.0.2 - webpack-dev-middleware: 7.4.2(webpack@5.96.1(webpack-cli@5.1.4)) + webpack-dev-middleware: 7.4.2(webpack@5.96.1) ws: 8.18.0 optionalDependencies: webpack: 5.96.1(webpack-cli@5.1.4) @@ -14366,12 +14319,12 @@ snapshots: webpack-sources@3.2.3: {} - webpack-subresource-integrity@5.1.0(html-webpack-plugin@5.6.3(webpack@5.96.1(webpack-cli@5.1.4)))(webpack@5.96.1(webpack-cli@5.1.4)): + webpack-subresource-integrity@5.1.0(html-webpack-plugin@5.6.3(webpack@5.96.1))(webpack@5.96.1): dependencies: typed-assert: 1.0.9 webpack: 5.96.1(webpack-cli@5.1.4) optionalDependencies: - html-webpack-plugin: 5.6.3(webpack@5.96.1(webpack-cli@5.1.4)) + html-webpack-plugin: 5.6.3(webpack@5.96.1) webpack@5.96.1(webpack-cli@5.1.4): dependencies: @@ -14395,11 +14348,11 @@ snapshots: neo-async: 2.6.2 schema-utils: 3.3.0 tapable: 2.2.1 - terser-webpack-plugin: 5.3.10(webpack@5.96.1(webpack-cli@5.1.4)) + terser-webpack-plugin: 5.3.10(webpack@5.96.1) watchpack: 2.4.1 webpack-sources: 3.2.3 optionalDependencies: - webpack-cli: 5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0(webpack-cli@5.1.4)(webpack@5.96.1))(webpack@5.96.1) + webpack-cli: 5.1.4(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@5.1.0)(webpack@5.96.1) transitivePeerDependencies: - '@swc/core' - esbuild diff --git a/skeleton-buffer/index.d.ts b/skeleton-buffer/index.d.ts deleted file mode 100644 index df5fc12e55..0000000000 --- a/skeleton-buffer/index.d.ts +++ /dev/null @@ -1,94 +0,0 @@ -export class Buffer extends Uint8Array { - length: number; - write(string: string, offset?: number, length?: number, encoding?: string): number; - toString(encoding?: string, start?: number, end?: number): string; - slice(start?: number, end?: number): Buffer; - - /** - * Allocates a new buffer containing the given {str}. - * - * @param str String to store in buffer. - * @param encoding encoding to use, optional. Default is 'utf8' - */ - constructor(str: string, encoding?: string); - /** - * Allocates a new buffer of {size} octets. - * - * @param size count of octets to allocate. - */ - constructor(size: number); - /** - * Allocates a new buffer containing the given {array} of octets. - * - * @param array The octets to store. - */ - constructor(array: Uint8Array); - /** - * Produces a Buffer backed by the same allocated memory as - * the given {ArrayBuffer}. - * - * - * @param arrayBuffer The ArrayBuffer with which to share memory. - */ - constructor(arrayBuffer: ArrayBuffer); - /** - * Allocates a new buffer containing the given {array} of octets. - * - * @param array The octets to store. - */ - constructor(array: any[]); - /** - * Copies the passed {buffer} data onto a new {Buffer} instance. - * - * @param buffer The buffer to copy. - */ - constructor(buffer: Buffer); - prototype: Buffer; - /** - * When passed a reference to the .buffer property of a TypedArray instance, - * the newly created Buffer will share the same allocated memory as the TypedArray. - * The optional {byteOffset} and {length} arguments specify a memory range - * within the {arrayBuffer} that will be shared by the Buffer. - * - * @param arrayBuffer The .buffer property of a TypedArray or a new ArrayBuffer() - * @param byteOffset - * @param length - */ - static from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer; - /** - * Creates a new Buffer containing the given JavaScript string {str}. - * If provided, the {encoding} parameter identifies the character encoding. - * If not provided, {encoding} defaults to 'utf8'. - * - * @param str - */ - static from(str: string, encoding?: string): Buffer; - /** - * Returns true if {obj} is a Buffer - * - * @param obj object to test. - */ - static isBuffer(obj: any): obj is Buffer; - /** - * Returns true if {encoding} is a valid encoding argument. - * Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' - * - * @param encoding string to test. - */ - static isEncoding(encoding: string): boolean; - /** - * Gives the actual byte length of a string. encoding defaults to 'utf8'. - * This is not the same as String.prototype.length since that returns the number of characters in a string. - * - * @param string string to test. - * @param encoding encoding used to evaluate (defaults to 'utf8') - */ - static byteLength(string: string, encoding?: string): number; - /** - * Allocates a new buffer of {size} octets, leaving memory not initialized, so the contents - * of the newly created Buffer are unknown and may contain sensitive data. - * - * @param size count of octets to allocate - */ - static allocUnsafe(size: number): Buffer; -} diff --git a/skeleton-buffer/index.js b/skeleton-buffer/index.js deleted file mode 100644 index 1df4ec0a0c..0000000000 --- a/skeleton-buffer/index.js +++ /dev/null @@ -1,860 +0,0 @@ -import base64 from 'base64-js'; - -const _Buffer = Buffer; -export { _Buffer as Buffer }; - -const K_MAX_LENGTH = 0x7fffffff; - -/** - * If `Buffer.TYPED_ARRAY_SUPPORT`: - * === true Use Uint8Array implementation (fastest) - * === false Print warning and recommend using `buffer` v4.x which has an Object - * implementation (most compatible, even IE6) - * - * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, - * Opera 11.6+, iOS 4.2+. - * - * We report that the browser does not support typed arrays if the are not subclassable - * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` - * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support - * for __proto__ and has a buggy typed array implementation. - */ -Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport(); - -if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && typeof console.error === 'function') { - console.error('This browser lacks typed array (Uint8Array) support which is required'); -} - -function typedArraySupport() { - // Can typed array instances can be augmented? - try { - const arr = new Uint8Array(1); - const proto = { - foo: function () { - return 42; - }, - }; - Object.setPrototypeOf(proto, Uint8Array.prototype); - Object.setPrototypeOf(arr, proto); - return arr.foo() === 42; - } catch (e) { - return false; - } -} - -/** - * The Buffer constructor returns instances of `Uint8Array` that have their - * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of - * `Uint8Array`, so the returned instances will have all the node `Buffer` methods - * and the `Uint8Array` methods. Square bracket notation works as expected -- it - * returns a single octet. - * - * The `Uint8Array` prototype remains unmodified. - */ - -function Buffer(arg, encodingOrOffset, length) { - // Common case. - if (typeof arg === 'number') { - if (typeof encodingOrOffset === 'string') { - throw new TypeError('The "string" argument must be of type string. Received type number'); - } - return allocUnsafe(arg); - } - return from(arg, encodingOrOffset, length); -} - -/** - * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError - * if value is a number. - * Buffer.from(str[, encoding]) - * Buffer.from(array) - * Buffer.from(buffer) - * Buffer.from(arrayBuffer[, byteOffset[, length]]) - **/ -Buffer.from = function (value, encodingOrOffset, length) { - return from(value, encodingOrOffset, length); -}; - -// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: -// https://github.com/feross/buffer/pull/148 -Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype); -Object.setPrototypeOf(Buffer, Uint8Array); - -function from(value, encodingOrOffset, length) { - if (typeof value === 'string') { - return fromString(value, encodingOrOffset); - } - - if (ArrayBuffer.isView(value)) { - return fromArrayView(value); - } - - if (value == null) { - throw new TypeError( - 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + - 'or Array-like Object. Received type ' + - typeof value, - ); - } - - if (isInstance(value, ArrayBuffer) || (value && isInstance(value.buffer, ArrayBuffer))) { - return fromArrayBuffer(value, encodingOrOffset, length); - } - - if ( - typeof SharedArrayBuffer !== 'undefined' && - (isInstance(value, SharedArrayBuffer) || (value && isInstance(value.buffer, SharedArrayBuffer))) - ) { - return fromArrayBuffer(value, encodingOrOffset, length); - } - - if (typeof value === 'number') { - throw new TypeError('The "value" argument must not be of type number. Received type number'); - } - - const valueOf = value.valueOf && value.valueOf(); - if (valueOf != null && valueOf !== value) { - return Buffer.from(valueOf, encodingOrOffset, length); - } - - const b = fromObject(value); - if (b) { - return b; - } - - if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === 'function') { - return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length); - } - - throw new TypeError( - 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + - 'or Array-like Object. Received type ' + - typeof value, - ); -} - -function allocUnsafe(size) { - assertSize(size); - return createBuffer(size < 0 ? 0 : checked(size) | 0); -} - -function assertSize(size) { - if (typeof size !== 'number') { - throw new TypeError('"size" argument must be of type number'); - } else if (size < 0) { - throw new RangeError('The value "' + size + '" is invalid for option "size"'); - } -} - -function createBuffer(length) { - if (length > K_MAX_LENGTH) { - throw new RangeError('The value "' + length + '" is invalid for option "size"'); - } - // Return an augmented `Uint8Array` instance - const buf = new Uint8Array(length); - Object.setPrototypeOf(buf, Buffer.prototype); - return buf; -} - -function checked(length) { - // Note: cannot use `length < K_MAX_LENGTH` here because that fails when - // length is NaN (which is otherwise coerced to zero.) - if (length >= K_MAX_LENGTH) { - throw new RangeError( - 'Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes', - ); - } - return length | 0; -} - -function fromString(string, encoding) { - if (typeof encoding !== 'string' || encoding === '') { - encoding = 'utf8'; - } - - if (!Buffer.isEncoding(encoding)) { - throw new TypeError('Unknown encoding: ' + encoding); - } - - const length = byteLength(string, encoding) | 0; - let buf = createBuffer(length); - - const actual = buf.write(string, encoding); - - if (actual !== length) { - // Writing a hex string, for example, that contains invalid characters will - // cause everything after the first invalid character to be ignored. (e.g. - // 'abxxcd' will be treated as 'ab') - buf = buf.slice(0, actual); - } - - return buf; -} - -Buffer.isEncoding = function isEncoding(encoding) { - switch (String(encoding).toLowerCase()) { - case 'hex': - case 'utf8': - case 'utf-8': - case 'ascii': - case 'latin1': - case 'binary': - case 'base64': - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return true; - default: - return false; - } -}; - -function byteLength(string, encoding) { - if (Buffer.isBuffer(string)) { - return string.length; - } - if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { - return string.byteLength; - } - if (typeof string !== 'string') { - throw new TypeError( - 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + 'Received type ' + typeof string, - ); - } - - const len = string.length; - const mustMatch = arguments.length > 2 && arguments[2] === true; - if (!mustMatch && len === 0) { - return 0; - } - - // Use a for loop to avoid recursion - let loweredCase = false; - for (;;) { - switch (encoding) { - case 'ascii': - case 'latin1': - case 'binary': - return len; - case 'utf8': - case 'utf-8': - return utf8ToBytes(string).length; - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return len * 2; - case 'hex': - return len >>> 1; - case 'base64': - return base64ToBytes(string).length; - default: - if (loweredCase) { - return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8 - } - encoding = ('' + encoding).toLowerCase(); - loweredCase = true; - } - } -} - -Buffer.isBuffer = function isBuffer(b) { - return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false -}; - -// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass -// the `instanceof` check but they should be treated as of that type. -// See: https://github.com/feross/buffer/issues/166 -function isInstance(obj, type) { - return ( - obj instanceof type || - (obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name) - ); -} - -function utf8ToBytes(string, units) { - units = units || Infinity; - let codePoint; - const length = string.length; - let leadSurrogate = null; - const bytes = []; - - for (let i = 0; i < length; ++i) { - codePoint = string.charCodeAt(i); - - // is surrogate component - if (codePoint > 0xd7ff && codePoint < 0xe000) { - // last char was a lead - if (!leadSurrogate) { - // no lead yet - if (codePoint > 0xdbff) { - // unexpected trail - if ((units -= 3) > -1) { - bytes.push(0xef, 0xbf, 0xbd); - } - continue; - } else if (i + 1 === length) { - // unpaired lead - if ((units -= 3) > -1) { - bytes.push(0xef, 0xbf, 0xbd); - } - continue; - } - - // valid lead - leadSurrogate = codePoint; - - continue; - } - - // 2 leads in a row - if (codePoint < 0xdc00) { - if ((units -= 3) > -1) { - bytes.push(0xef, 0xbf, 0xbd); - } - leadSurrogate = codePoint; - continue; - } - - // valid surrogate pair - codePoint = (((leadSurrogate - 0xd800) << 10) | (codePoint - 0xdc00)) + 0x10000; - } else if (leadSurrogate) { - // valid bmp char, but last char was a lead - if ((units -= 3) > -1) { - bytes.push(0xef, 0xbf, 0xbd); - } - } - - leadSurrogate = null; - - // encode utf8 - if (codePoint < 0x80) { - if ((units -= 1) < 0) { - break; - } - bytes.push(codePoint); - } else if (codePoint < 0x800) { - if ((units -= 2) < 0) { - break; - } - bytes.push((codePoint >> 0x6) | 0xc0, (codePoint & 0x3f) | 0x80); - } else if (codePoint < 0x10000) { - if ((units -= 3) < 0) { - break; - } - bytes.push((codePoint >> 0xc) | 0xe0, ((codePoint >> 0x6) & 0x3f) | 0x80, (codePoint & 0x3f) | 0x80); - } else if (codePoint < 0x110000) { - if ((units -= 4) < 0) { - break; - } - bytes.push( - (codePoint >> 0x12) | 0xf0, - ((codePoint >> 0xc) & 0x3f) | 0x80, - ((codePoint >> 0x6) & 0x3f) | 0x80, - (codePoint & 0x3f) | 0x80, - ); - } else { - throw new Error('Invalid code point'); - } - } - - return bytes; -} - -function base64ToBytes(str) { - return base64.toByteArray(base64clean(str)); -} - -const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g; - -function base64clean(str) { - // Node takes equal signs as end of the Base64 encoding - str = str.split('=')[0]; - // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = str.trim().replace(INVALID_BASE64_RE, ''); - // Node converts strings with length < 2 to '' - if (str.length < 2) { - return ''; - } - // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not - while (str.length % 4 !== 0) { - str = str + '='; - } - return str; -} - -function fromArrayView(arrayView) { - if (isInstance(arrayView, Uint8Array)) { - const copy = new Uint8Array(arrayView); - return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength); - } - return fromArrayLike(arrayView); -} - -function fromArrayBuffer(array, byteOffset, length) { - if (byteOffset < 0 || array.byteLength < byteOffset) { - throw new RangeError('"offset" is outside of buffer bounds'); - } - - if (array.byteLength < byteOffset + (length || 0)) { - throw new RangeError('"length" is outside of buffer bounds'); - } - - let buf; - if (byteOffset === undefined && length === undefined) { - buf = new Uint8Array(array); - } else if (length === undefined) { - buf = new Uint8Array(array, byteOffset); - } else { - buf = new Uint8Array(array, byteOffset, length); - } - - // Return an augmented `Uint8Array` instance - Object.setPrototypeOf(buf, Buffer.prototype); - - return buf; -} - -function fromArrayLike(array) { - const length = array.length < 0 ? 0 : checked(array.length) | 0; - const buf = createBuffer(length); - for (let i = 0; i < length; i += 1) { - buf[i] = array[i] & 255; - } - return buf; -} - -Buffer.prototype.toString = function toString() { - const length = this.length; - if (length === 0) { - return ''; - } - if (arguments.length === 0) { - return utf8Slice(this, 0, length); - } - return slowToString.apply(this, arguments); -}; - -function utf8Slice(buf, start, end) { - end = Math.min(buf.length, end); - const res = []; - - let i = start; - while (i < end) { - const firstByte = buf[i]; - let codePoint = null; - let bytesPerSequence = firstByte > 0xef ? 4 : firstByte > 0xdf ? 3 : firstByte > 0xbf ? 2 : 1; - - if (i + bytesPerSequence <= end) { - let secondByte, thirdByte, fourthByte, tempCodePoint; - - switch (bytesPerSequence) { - case 1: - if (firstByte < 0x80) { - codePoint = firstByte; - } - break; - case 2: - secondByte = buf[i + 1]; - if ((secondByte & 0xc0) === 0x80) { - tempCodePoint = ((firstByte & 0x1f) << 0x6) | (secondByte & 0x3f); - if (tempCodePoint > 0x7f) { - codePoint = tempCodePoint; - } - } - break; - case 3: - secondByte = buf[i + 1]; - thirdByte = buf[i + 2]; - if ((secondByte & 0xc0) === 0x80 && (thirdByte & 0xc0) === 0x80) { - tempCodePoint = ((firstByte & 0xf) << 0xc) | ((secondByte & 0x3f) << 0x6) | (thirdByte & 0x3f); - if (tempCodePoint > 0x7ff && (tempCodePoint < 0xd800 || tempCodePoint > 0xdfff)) { - codePoint = tempCodePoint; - } - } - break; - case 4: - secondByte = buf[i + 1]; - thirdByte = buf[i + 2]; - fourthByte = buf[i + 3]; - if ((secondByte & 0xc0) === 0x80 && (thirdByte & 0xc0) === 0x80 && (fourthByte & 0xc0) === 0x80) { - tempCodePoint = - ((firstByte & 0xf) << 0x12) | - ((secondByte & 0x3f) << 0xc) | - ((thirdByte & 0x3f) << 0x6) | - (fourthByte & 0x3f); - if (tempCodePoint > 0xffff && tempCodePoint < 0x110000) { - codePoint = tempCodePoint; - } - } - } - } - - if (codePoint === null) { - // we did not generate a valid codePoint so insert a - // replacement char (U+FFFD) and advance only 1 byte - codePoint = 0xfffd; - bytesPerSequence = 1; - } else if (codePoint > 0xffff) { - // encode to utf16 (surrogate pair dance) - codePoint -= 0x10000; - res.push(((codePoint >>> 10) & 0x3ff) | 0xd800); - codePoint = 0xdc00 | (codePoint & 0x3ff); - } - - res.push(codePoint); - i += bytesPerSequence; - } - - return decodeCodePointsArray(res); -} - -function slowToString(encoding, start, end) { - let loweredCase = false; - - // No need to verify that "this.length <= MAX_UINT32" since it's a read-only - // property of a typed array. - - // This behaves neither like String nor Uint8Array in that we set start/end - // to their upper/lower bounds if the value passed is out of range. - // undefined is handled specially as per ECMA-262 6th Edition, - // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. - if (start === undefined || start < 0) { - start = 0; - } - // Return early if start > this.length. Done here to prevent potential uint32 - // coercion fail below. - if (start > this.length) { - return ''; - } - - if (end === undefined || end > this.length) { - end = this.length; - } - - if (end <= 0) { - return ''; - } - - // Force coercion to uint32. This will also coerce falsey/NaN values to 0. - end >>>= 0; - start >>>= 0; - - if (end <= start) { - return ''; - } - - if (!encoding) { - encoding = 'utf8'; - } - - // eslint-disable-next-line no-constant-condition - while (true) { - switch (encoding) { - case 'hex': - return hexSlice(this, start, end); - - case 'utf8': - case 'utf-8': - return utf8Slice(this, start, end); - - case 'ascii': - return asciiSlice(this, start, end); - - case 'latin1': - case 'binary': - return latin1Slice(this, start, end); - - case 'base64': - return base64Slice(this, start, end); - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return utf16leSlice(this, start, end); - - default: - if (loweredCase) { - throw new TypeError('Unknown encoding: ' + encoding); - } - encoding = (encoding + '').toLowerCase(); - loweredCase = true; - } - } -} - -// Based on http://stackoverflow.com/a/22747272/680742, the browser with -// the lowest limit is Chrome, with 0x10000 args. -// We go 1 magnitude less, for safety -const MAX_ARGUMENTS_LENGTH = 0x1000; - -function decodeCodePointsArray(codePoints) { - const len = codePoints.length; - if (len <= MAX_ARGUMENTS_LENGTH) { - return String.fromCharCode.apply(String, codePoints); // avoid extra slice() - } - - // Decode in chunks to avoid "call stack size exceeded". - let res = ''; - let i = 0; - while (i < len) { - res += String.fromCharCode.apply(String, codePoints.slice(i, (i += MAX_ARGUMENTS_LENGTH))); - } - return res; -} - -function hexSlice(buf, start, end) { - const len = buf.length; - - if (!start || start < 0) { - start = 0; - } - if (!end || end < 0 || end > len) { - end = len; - } - - let out = ''; - for (let i = start; i < end; ++i) { - out += hexSliceLookupTable[buf[i]]; - } - return out; -} - -function asciiSlice(buf, start, end) { - let ret = ''; - end = Math.min(buf.length, end); - - for (let i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i] & 0x7f); - } - return ret; -} - -function latin1Slice(buf, start, end) { - let ret = ''; - end = Math.min(buf.length, end); - - for (let i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i]); - } - return ret; -} - -function base64Slice(buf, start, end) { - if (start === 0 && end === buf.length) { - return base64.fromByteArray(buf); - } else { - return base64.fromByteArray(buf.slice(start, end)); - } -} - -function utf16leSlice(buf, start, end) { - const bytes = buf.slice(start, end); - let res = ''; - // If bytes.length is odd, the last 8 bits must be ignored (same as node.js) - for (let i = 0; i < bytes.length - 1; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); - } - return res; -} - -Buffer.prototype.write = function write(string, offset, length, encoding) { - // Buffer#write(string) - if (offset === undefined) { - encoding = 'utf8'; - length = this.length; - offset = 0; - // Buffer#write(string, encoding) - } else if (length === undefined && typeof offset === 'string') { - encoding = offset; - length = this.length; - offset = 0; - // Buffer#write(string, offset[, length][, encoding]) - } else if (isFinite(offset)) { - offset = offset >>> 0; - if (isFinite(length)) { - length = length >>> 0; - if (encoding === undefined) { - encoding = 'utf8'; - } - } else { - encoding = length; - length = undefined; - } - } else { - throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported'); - } - - const remaining = this.length - offset; - if (length === undefined || length > remaining) { - length = remaining; - } - - if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { - throw new RangeError('Attempt to write outside buffer bounds'); - } - - if (!encoding) { - encoding = 'utf8'; - } - - let loweredCase = false; - for (;;) { - switch (encoding) { - case 'hex': - return hexWrite(this, string, offset, length); - - case 'utf8': - case 'utf-8': - return utf8Write(this, string, offset, length); - - case 'ascii': - case 'latin1': - case 'binary': - return asciiWrite(this, string, offset, length); - - case 'base64': - // Warning: maxLength not taken into account in base64Write - return base64Write(this, string, offset, length); - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return ucs2Write(this, string, offset, length); - - default: - if (loweredCase) { - throw new TypeError('Unknown encoding: ' + encoding); - } - encoding = ('' + encoding).toLowerCase(); - loweredCase = true; - } - } -}; - -function hexWrite(buf, string, offset, length) { - offset = Number(offset) || 0; - const remaining = buf.length - offset; - if (!length) { - length = remaining; - } else { - length = Number(length); - if (length > remaining) { - length = remaining; - } - } - - const strLen = string.length; - - if (length > strLen / 2) { - length = strLen / 2; - } - let i; - for (i = 0; i < length; ++i) { - const parsed = parseInt(string.substr(i * 2, 2), 16); - if (numberIsNaN(parsed)) { - return i; - } - buf[offset + i] = parsed; - } - return i; -} - -function utf8Write(buf, string, offset, length) { - return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length); -} - -function asciiWrite(buf, string, offset, length) { - return blitBuffer(asciiToBytes(string), buf, offset, length); -} - -function base64Write(buf, string, offset, length) { - return blitBuffer(base64ToBytes(string), buf, offset, length); -} - -function ucs2Write(buf, string, offset, length) { - return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length); -} - -function asciiToBytes(str) { - const byteArray = []; - for (let i = 0; i < str.length; ++i) { - // Node's code seems to be doing this and not & 0x7F.. - byteArray.push(str.charCodeAt(i) & 0xff); - } - return byteArray; -} - -function utf16leToBytes(str, units) { - let c, hi, lo; - const byteArray = []; - for (let i = 0; i < str.length; ++i) { - if ((units -= 2) < 0) { - break; - } - - c = str.charCodeAt(i); - hi = c >> 8; - lo = c % 256; - byteArray.push(lo); - byteArray.push(hi); - } - - return byteArray; -} - -function blitBuffer(src, dst, offset, length) { - let i; - for (i = 0; i < length; ++i) { - if (i + offset >= dst.length || i >= src.length) { - break; - } - dst[i + offset] = src[i]; - } - return i; -} - -function numberIsNaN(obj) { - // For IE11 support - return obj !== obj; // eslint-disable-line no-self-compare -} - -const hexSliceLookupTable = (function () { - const alphabet = '0123456789abcdef'; - const table = new Array(256); - for (let i = 0; i < 16; ++i) { - const i16 = i * 16; - for (let j = 0; j < 16; ++j) { - table[i16 + j] = alphabet[i] + alphabet[j]; - } - } - return table; -})(); - -function fromObject(obj) { - if (Buffer.isBuffer(obj)) { - const len = checked(obj.length) | 0; - const buf = createBuffer(len); - - if (buf.length === 0) { - return buf; - } - - obj.copy(buf, 0, 0, len); - return buf; - } - - if (obj.length !== undefined) { - if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { - return createBuffer(0); - } - return fromArrayLike(obj); - } - - if (obj.type === 'Buffer' && Array.isArray(obj.data)) { - return fromArrayLike(obj.data); - } -} diff --git a/skeleton-buffer/package.json b/skeleton-buffer/package.json deleted file mode 100644 index 3f3c270468..0000000000 --- a/skeleton-buffer/package.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "name": "skeleton-buffer", - "description": "Node.js Buffer API, for the browser, with only the teams-js functionality", - "version": "0.0.1", - "dependencies": { - "base64-js": "^1.3.1" - }, - "devDependencies": { - "airtap": "^3.0.0", - "benchmark": "^2.1.4", - "browserify": "^17.0.0", - "concat-stream": "^2.0.0", - "hyperquest": "^2.1.3", - "is-buffer": "^2.0.5", - "is-nan": "^1.3.0", - "split": "^1.0.1", - "standard": "*", - "tape": "^5.0.1", - "through2": "^4.0.2", - "uglify-js": "^3.11.5" - }, - "jspm": { - "map": { - "./index.js": { - "node": "@node/buffer" - } - } - }, - "keywords": [ - "arraybuffer", - "browser", - "browserify", - "buffer", - "compatible", - "dataview", - "uint8array" - ], - "license": "MIT", - "main": "index.js", - "type": "module", - "module": "index.js", - "types": "index.d.ts", - "scripts": { - "perf": "browserify --debug perf/bracket-notation.js > perf/bundle.js && open perf/index.html", - "perf-node": "node perf/bracket-notation.js && node perf/concat.js && node perf/copy-big.js && node perf/copy.js && node perf/new-big.js && node perf/new.js && node perf/readDoubleBE.js && node perf/readFloatBE.js && node perf/readUInt32LE.js && node perf/slice.js && node perf/writeFloatBE.js", - "size": "browserify -r ./ | uglifyjs -c -m | gzip | wc -c", - "test": "standard && node ./bin/test.js", - "test-browser-old": "airtap -- test/*.js", - "test-browser-old-local": "airtap --local -- test/*.js", - "test-browser-new": "airtap -- test/*.js test/node/*.js", - "test-browser-new-local": "airtap --local -- test/*.js test/node/*.js", - "test-node": "tape test/*.js test/node/*.js", - "update-authors": "./bin/update-authors.sh" - }, - "standard": { - "ignore": [ - "test/node/**/*.js", - "test/common.js", - "test/_polyfill.js", - "perf/**/*.js" - ] - } -}