@fluidframework/common-utils
Advanced tools
Comparing version 0.27.1 to 0.27.2
@@ -27,2 +27,8 @@ /*! | ||
* Determines if an object is an array buffer | ||
* Will detect and reject TypedArrays, like Uint8Array. | ||
* Reason - they can be viewport into Array, they can be accepted, but caller has to deal with | ||
* math properly (i.e. take into account byteOffset at minimum). | ||
* For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or | ||
* new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and | ||
* ignoring byteOffice, length) | ||
* @param obj - The object to determine if it is an ArrayBuffer | ||
@@ -29,0 +35,0 @@ */ |
@@ -15,2 +15,3 @@ "use strict"; | ||
const base64js = __importStar(require("base64-js")); | ||
const assert_1 = require("./assert"); | ||
/** | ||
@@ -53,2 +54,8 @@ * Converts a Uint8Array to a string of the provided encoding | ||
* Determines if an object is an array buffer | ||
* Will detect and reject TypedArrays, like Uint8Array. | ||
* Reason - they can be viewport into Array, they can be accepted, but caller has to deal with | ||
* math properly (i.e. take into account byteOffset at minimum). | ||
* For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or | ||
* new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and | ||
* ignoring byteOffice, length) | ||
* @param obj - The object to determine if it is an ArrayBuffer | ||
@@ -60,4 +67,7 @@ */ | ||
|| (typeof maybe === "object" | ||
&& maybe !== null | ||
&& typeof maybe.byteLength === "number" | ||
&& typeof maybe.slice === "function"); | ||
&& typeof maybe.slice === "function" | ||
&& maybe.byteOffset === undefined | ||
&& maybe.buffer === undefined); | ||
} | ||
@@ -86,3 +96,10 @@ exports.isArrayBuffer = isArrayBuffer; | ||
return IsoBuffer.fromString(value, encodingOrOffset); | ||
// Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!) | ||
} | ||
else if (value !== null && typeof value === "object" && isArrayBuffer(value.buffer)) { | ||
// Support currently for full array, no view ports! (though it can be added in future) | ||
assert_1.assert(value.byteOffset === 0); | ||
assert_1.assert(value.byteLength === value.buffer.byteLength); | ||
return IsoBuffer.fromArrayBuffer(value.buffer, encodingOrOffset, length); | ||
} | ||
else if (isArrayBuffer(value)) { | ||
@@ -89,0 +106,0 @@ return IsoBuffer.fromArrayBuffer(value, encodingOrOffset, length); |
@@ -8,3 +8,3 @@ /*! | ||
export declare const pkgName = "@fluidframework/common-utils"; | ||
export declare const pkgVersion = "0.27.1"; | ||
export declare const pkgVersion = "0.27.2"; | ||
//# sourceMappingURL=packageVersion.d.ts.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
exports.pkgName = "@fluidframework/common-utils"; | ||
exports.pkgVersion = "0.27.1"; | ||
exports.pkgVersion = "0.27.2"; | ||
//# sourceMappingURL=packageVersion.js.map |
@@ -27,2 +27,8 @@ /*! | ||
* Determines if an object is an array buffer | ||
* Will detect and reject TypedArrays, like Uint8Array. | ||
* Reason - they can be viewport into Array, they can be accepted, but caller has to deal with | ||
* math properly (i.e. take into account byteOffset at minimum). | ||
* For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or | ||
* new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and | ||
* ignoring byteOffice, length) | ||
* @param obj - The object to determine if it is an ArrayBuffer | ||
@@ -29,0 +35,0 @@ */ |
@@ -6,2 +6,3 @@ /*! | ||
import * as base64js from "base64-js"; | ||
import { assert } from "./assert"; | ||
/** | ||
@@ -43,2 +44,8 @@ * Converts a Uint8Array to a string of the provided encoding | ||
* Determines if an object is an array buffer | ||
* Will detect and reject TypedArrays, like Uint8Array. | ||
* Reason - they can be viewport into Array, they can be accepted, but caller has to deal with | ||
* math properly (i.e. take into account byteOffset at minimum). | ||
* For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or | ||
* new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and | ||
* ignoring byteOffice, length) | ||
* @param obj - The object to determine if it is an ArrayBuffer | ||
@@ -50,4 +57,7 @@ */ | ||
|| (typeof maybe === "object" | ||
&& maybe !== null | ||
&& typeof maybe.byteLength === "number" | ||
&& typeof maybe.slice === "function"); | ||
&& typeof maybe.slice === "function" | ||
&& maybe.byteOffset === undefined | ||
&& maybe.buffer === undefined); | ||
} | ||
@@ -75,3 +85,10 @@ /** | ||
return IsoBuffer.fromString(value, encodingOrOffset); | ||
// Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!) | ||
} | ||
else if (value !== null && typeof value === "object" && isArrayBuffer(value.buffer)) { | ||
// Support currently for full array, no view ports! (though it can be added in future) | ||
assert(value.byteOffset === 0); | ||
assert(value.byteLength === value.buffer.byteLength); | ||
return IsoBuffer.fromArrayBuffer(value.buffer, encodingOrOffset, length); | ||
} | ||
else if (isArrayBuffer(value)) { | ||
@@ -78,0 +95,0 @@ return IsoBuffer.fromArrayBuffer(value, encodingOrOffset, length); |
@@ -8,3 +8,3 @@ /*! | ||
export declare const pkgName = "@fluidframework/common-utils"; | ||
export declare const pkgVersion = "0.27.1"; | ||
export declare const pkgVersion = "0.27.2"; | ||
//# sourceMappingURL=packageVersion.d.ts.map |
@@ -8,3 +8,3 @@ /*! | ||
export const pkgName = "@fluidframework/common-utils"; | ||
export const pkgVersion = "0.27.1"; | ||
export const pkgVersion = "0.27.2"; | ||
//# sourceMappingURL=packageVersion.js.map |
{ | ||
"name": "@fluidframework/common-utils", | ||
"version": "0.27.1", | ||
"version": "0.27.2", | ||
"description": "Collection of utility functions for Fluid", | ||
@@ -5,0 +5,0 @@ "homepage": "https://fluidframework.com", |
@@ -7,2 +7,3 @@ /*! | ||
import * as base64js from "base64-js"; | ||
import { assert } from "./assert"; | ||
@@ -50,10 +51,19 @@ /** | ||
* Determines if an object is an array buffer | ||
* Will detect and reject TypedArrays, like Uint8Array. | ||
* Reason - they can be viewport into Array, they can be accepted, but caller has to deal with | ||
* math properly (i.e. take into account byteOffset at minimum). | ||
* For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or | ||
* new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and | ||
* ignoring byteOffice, length) | ||
* @param obj - The object to determine if it is an ArrayBuffer | ||
*/ | ||
export function isArrayBuffer(obj: any): obj is ArrayBuffer { | ||
const maybe = obj as Partial<ArrayBuffer> | undefined; | ||
const maybe = obj as (Partial<ArrayBuffer> & Partial<Uint8Array>) | undefined; | ||
return obj instanceof ArrayBuffer | ||
|| (typeof maybe === "object" | ||
&& maybe !== null | ||
&& typeof maybe.byteLength === "number" | ||
&& typeof maybe.slice === "function"); | ||
&& typeof maybe.slice === "function" | ||
&& maybe.byteOffset === undefined | ||
&& maybe.buffer === undefined); | ||
} | ||
@@ -83,2 +93,8 @@ | ||
return IsoBuffer.fromString(value, encodingOrOffset as string | undefined); | ||
// Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!) | ||
} else if (value !== null && typeof value === "object" && isArrayBuffer(value.buffer)) { | ||
// Support currently for full array, no view ports! (though it can be added in future) | ||
assert(value.byteOffset === 0); | ||
assert(value.byteLength === value.buffer.byteLength); | ||
return IsoBuffer.fromArrayBuffer(value.buffer, encodingOrOffset as number | undefined, length); | ||
} else if (isArrayBuffer(value)) { | ||
@@ -85,0 +101,0 @@ return IsoBuffer.fromArrayBuffer(value, encodingOrOffset as number | undefined, length); |
@@ -9,2 +9,2 @@ /*! | ||
export const pkgName = "@fluidframework/common-utils"; | ||
export const pkgVersion = "0.27.1"; | ||
export const pkgVersion = "0.27.2"; |
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
Sorry, the diff of this file is not supported yet
846814
8650