@xylabs/buffer
Advanced tools
Comparing version 2.8.1 to 2.9.0-rc.1
@@ -5,9 +5,13 @@ "use strict"; | ||
const Buffer_1 = require("./Buffer"); | ||
const isBrowser = () => { | ||
return typeof window !== 'undefined' && typeof (window === null || window === void 0 ? void 0 : window.document) !== 'undefined'; | ||
}; | ||
const isWebworker = () => { | ||
var _a; | ||
return typeof self === 'object' && ((_a = self.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'DedicatedWorkerGlobalScope'; | ||
}; | ||
const bufferPolyfillBrowser = () => { | ||
if (window !== undefined) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const global = window; | ||
if (global.Buffer === undefined) { | ||
global.Buffer = Buffer_1.BrowserBuffer; | ||
} | ||
const global = isBrowser() ? window : isWebworker() ? self : undefined; | ||
if (global && global.Buffer === undefined) { | ||
global.Buffer = Buffer_1.BrowserBuffer; | ||
} | ||
@@ -14,0 +18,0 @@ }; |
@@ -18,5 +18,5 @@ { | ||
"fileName": "browser/bufferPolyfill.ts", | ||
"line": 3, | ||
"line": 13, | ||
"character": 13, | ||
"url": "https://github.com/xylabs/sdk-js/blob/7940a22/packages/buffer/src/browser/bufferPolyfill.ts#L3" | ||
"url": "https://github.com/xylabs/sdk-js/blob/238bcfa/packages/buffer/src/browser/bufferPolyfill.ts#L13" | ||
} | ||
@@ -35,5 +35,5 @@ ], | ||
"fileName": "browser/bufferPolyfill.ts", | ||
"line": 3, | ||
"line": 13, | ||
"character": 13, | ||
"url": "https://github.com/xylabs/sdk-js/blob/7940a22/packages/buffer/src/browser/bufferPolyfill.ts#L3" | ||
"url": "https://github.com/xylabs/sdk-js/blob/238bcfa/packages/buffer/src/browser/bufferPolyfill.ts#L13" | ||
} | ||
@@ -66,3 +66,3 @@ ], | ||
"character": 13, | ||
"url": "https://github.com/xylabs/sdk-js/blob/7940a22/packages/buffer/src/node/bufferPolyfill.ts#L1" | ||
"url": "https://github.com/xylabs/sdk-js/blob/238bcfa/packages/buffer/src/node/bufferPolyfill.ts#L1" | ||
} | ||
@@ -105,5 +105,5 @@ ], | ||
"character": 0, | ||
"url": "https://github.com/xylabs/sdk-js/blob/7940a22/packages/buffer/src/index.ts#L1" | ||
"url": "https://github.com/xylabs/sdk-js/blob/238bcfa/packages/buffer/src/index.ts#L1" | ||
} | ||
] | ||
} |
import { BrowserBuffer } from './Buffer'; | ||
const isBrowser = () => { | ||
return typeof window !== 'undefined' && typeof window?.document !== 'undefined'; | ||
}; | ||
const isWebworker = () => { | ||
return typeof self === 'object' && self.constructor?.name === 'DedicatedWorkerGlobalScope'; | ||
}; | ||
export const bufferPolyfillBrowser = () => { | ||
if (window !== undefined) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const global = window; | ||
if (global.Buffer === undefined) { | ||
global.Buffer = BrowserBuffer; | ||
} | ||
const global = isBrowser() ? window : isWebworker() ? self : undefined; | ||
if (global && global.Buffer === undefined) { | ||
global.Buffer = BrowserBuffer; | ||
} | ||
}; | ||
//# sourceMappingURL=bufferPolyfill.js.map |
@@ -59,3 +59,4 @@ { | ||
"sideEffects": false, | ||
"version": "2.8.1" | ||
"version": "2.9.0-rc.1", | ||
"stableVersion": "2.8.1" | ||
} |
import { BrowserBuffer } from './Buffer' | ||
type WithOptionalBuffer = { Buffer?: typeof BrowserBuffer } | ||
const isBrowser = () => { | ||
return typeof window !== 'undefined' && typeof window?.document !== 'undefined' | ||
} | ||
const isWebworker = () => { | ||
return typeof self === 'object' && self.constructor?.name === 'DedicatedWorkerGlobalScope' | ||
} | ||
export const bufferPolyfillBrowser = () => { | ||
if (window !== undefined) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const global = window as any | ||
if (global.Buffer === undefined) { | ||
global.Buffer = BrowserBuffer | ||
} | ||
const global = isBrowser() ? (window as unknown as WithOptionalBuffer) : isWebworker() ? (self as unknown as WithOptionalBuffer) : undefined | ||
if (global && global.Buffer === undefined) { | ||
global.Buffer = BrowserBuffer | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
103829
343
1