@fluidframework/common-utils
Advanced tools
Comparing version 0.28.0-16189 to 0.28.0-18295
@@ -26,6 +26,16 @@ /*! | ||
/** | ||
* 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 declare function isArrayBuffer(obj: any): obj is ArrayBuffer; | ||
/** | ||
* Minimal implementation of Buffer for our usages in the browser environment. | ||
*/ | ||
export declare class IsoBuffer extends Uint8Array { | ||
constructor(buffer: ArrayBufferLike, byteOffset?: number, length?: number); | ||
/** | ||
@@ -32,0 +42,0 @@ * Convert the buffer to a string. |
@@ -26,4 +26,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.IsoBuffer = exports.bufferToString = exports.stringToBuffer = exports.Uint8ArrayToString = void 0; | ||
exports.IsoBuffer = exports.isArrayBuffer = exports.bufferToString = exports.stringToBuffer = exports.Uint8ArrayToString = void 0; | ||
const base64js = __importStar(require("base64-js")); | ||
const assert_1 = require("./assert"); | ||
/** | ||
@@ -67,9 +68,26 @@ * 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 | ||
*/ | ||
function isArrayBuffer(obj) { | ||
const maybe = obj; | ||
return obj instanceof ArrayBuffer | ||
|| (typeof maybe === "object" | ||
&& maybe !== null | ||
&& typeof maybe.byteLength === "number" | ||
&& typeof maybe.slice === "function" | ||
&& maybe.byteOffset === undefined | ||
&& maybe.buffer === undefined); | ||
} | ||
exports.isArrayBuffer = isArrayBuffer; | ||
/** | ||
* Minimal implementation of Buffer for our usages in the browser environment. | ||
*/ | ||
class IsoBuffer extends Uint8Array { | ||
// Need to have ctor for it to be in proto chain for instanceof check in from() method to work | ||
constructor(buffer, byteOffset, length) { | ||
super(buffer, byteOffset, length); | ||
} | ||
/** | ||
@@ -92,7 +110,11 @@ * Convert the buffer to a string. | ||
return IsoBuffer.fromString(value, encodingOrOffset); | ||
// Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!) | ||
} | ||
else if (value instanceof IsoBuffer) { | ||
return value; | ||
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 (value instanceof ArrayBuffer) { | ||
else if (isArrayBuffer(value)) { | ||
return IsoBuffer.fromArrayBuffer(value, encodingOrOffset, length); | ||
@@ -99,0 +121,0 @@ } |
@@ -8,3 +8,3 @@ /*! | ||
export declare const pkgName = "@fluidframework/common-utils"; | ||
export declare const pkgVersion = "0.28.0-16189"; | ||
export declare const pkgVersion = "0.28.0-18295"; | ||
//# sourceMappingURL=packageVersion.d.ts.map |
@@ -11,3 +11,3 @@ "use strict"; | ||
exports.pkgName = "@fluidframework/common-utils"; | ||
exports.pkgVersion = "0.28.0-16189"; | ||
exports.pkgVersion = "0.28.0-18295"; | ||
//# sourceMappingURL=packageVersion.js.map |
@@ -26,6 +26,16 @@ /*! | ||
/** | ||
* 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 declare function isArrayBuffer(obj: any): obj is ArrayBuffer; | ||
/** | ||
* Minimal implementation of Buffer for our usages in the browser environment. | ||
*/ | ||
export declare class IsoBuffer extends Uint8Array { | ||
constructor(buffer: ArrayBufferLike, byteOffset?: number, length?: number); | ||
/** | ||
@@ -32,0 +42,0 @@ * Convert the buffer to a string. |
@@ -6,2 +6,3 @@ /*! | ||
import * as base64js from "base64-js"; | ||
import { assert } from "./assert"; | ||
/** | ||
@@ -42,9 +43,25 @@ * 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 | ||
*/ | ||
export function isArrayBuffer(obj) { | ||
const maybe = obj; | ||
return obj instanceof ArrayBuffer | ||
|| (typeof maybe === "object" | ||
&& maybe !== null | ||
&& typeof maybe.byteLength === "number" | ||
&& typeof maybe.slice === "function" | ||
&& maybe.byteOffset === undefined | ||
&& maybe.buffer === undefined); | ||
} | ||
/** | ||
* Minimal implementation of Buffer for our usages in the browser environment. | ||
*/ | ||
export class IsoBuffer extends Uint8Array { | ||
// Need to have ctor for it to be in proto chain for instanceof check in from() method to work | ||
constructor(buffer, byteOffset, length) { | ||
super(buffer, byteOffset, length); | ||
} | ||
/** | ||
@@ -67,7 +84,11 @@ * Convert the buffer to a string. | ||
return IsoBuffer.fromString(value, encodingOrOffset); | ||
// Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!) | ||
} | ||
else if (value instanceof IsoBuffer) { | ||
return value; | ||
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 (value instanceof ArrayBuffer) { | ||
else if (isArrayBuffer(value)) { | ||
return IsoBuffer.fromArrayBuffer(value, encodingOrOffset, length); | ||
@@ -74,0 +95,0 @@ } |
@@ -8,3 +8,3 @@ /*! | ||
export declare const pkgName = "@fluidframework/common-utils"; | ||
export declare const pkgVersion = "0.28.0-16189"; | ||
export declare const pkgVersion = "0.28.0-18295"; | ||
//# sourceMappingURL=packageVersion.d.ts.map |
@@ -8,3 +8,3 @@ /*! | ||
export const pkgName = "@fluidframework/common-utils"; | ||
export const pkgVersion = "0.28.0-16189"; | ||
export const pkgVersion = "0.28.0-18295"; | ||
//# sourceMappingURL=packageVersion.js.map |
{ | ||
"name": "@fluidframework/common-utils", | ||
"version": "0.28.0-16189", | ||
"version": "0.28.0-18295", | ||
"description": "Collection of utility functions for Fluid", | ||
@@ -44,3 +44,3 @@ "homepage": "https://fluidframework.com", | ||
"test:mocha": "mocha --unhandled-rejections=strict --recursive dist/test/mocha/**/*.spec.js --exit --project test/tsconfig.json", | ||
"test:mocha:report": "npm run test:mocha -- -- --reporter mocha-junit-reporter --reporter-options mochaFile=nyc/mocha-junit-report.xml", | ||
"test:mocha:report": "npm run test:mocha -- -- --reporter xunit --reporter-option output=nyc/mocha-junit-report.xml", | ||
"test:report": "npm run test:mocha:report && npm run test:jest:report", | ||
@@ -77,9 +77,9 @@ "tsc": "tsc", | ||
"events": "^3.1.0", | ||
"lodash": "^4.17.19", | ||
"lodash": "^4.17.21", | ||
"sha.js": "^2.4.11" | ||
}, | ||
"devDependencies": { | ||
"@fluidframework/build-common": "^0.20.0-0", | ||
"@fluidframework/eslint-config-fluid": "^0.22.1-0", | ||
"@microsoft/api-extractor": "^7.7.2", | ||
"@fluidframework/build-common": "^0.20.0", | ||
"@fluidframework/eslint-config-fluid": "^0.23.0", | ||
"@microsoft/api-extractor": "^7.13.1", | ||
"@types/assert": "^1.5.2", | ||
@@ -109,3 +109,2 @@ "@types/base64-js": "^1.3.0", | ||
"mocha": "^8.1.1", | ||
"mocha-junit-reporter": "^1.18.0", | ||
"nyc": "^15.0.0", | ||
@@ -112,0 +111,0 @@ "puppeteer": "^2.1.0", |
@@ -7,2 +7,3 @@ /*! | ||
import * as base64js from "base64-js"; | ||
import { assert } from "./assert"; | ||
@@ -49,10 +50,26 @@ /** | ||
/** | ||
* 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> & Partial<Uint8Array>) | undefined; | ||
return obj instanceof ArrayBuffer | ||
|| (typeof maybe === "object" | ||
&& maybe !== null | ||
&& typeof maybe.byteLength === "number" | ||
&& typeof maybe.slice === "function" | ||
&& maybe.byteOffset === undefined | ||
&& maybe.buffer === undefined); | ||
} | ||
/** | ||
* Minimal implementation of Buffer for our usages in the browser environment. | ||
*/ | ||
export class IsoBuffer extends Uint8Array { | ||
// Need to have ctor for it to be in proto chain for instanceof check in from() method to work | ||
public constructor(buffer: ArrayBufferLike, byteOffset?: number, length?: number) { | ||
super(buffer, byteOffset, length); | ||
} | ||
/** | ||
@@ -76,5 +93,9 @@ * Convert the buffer to a string. | ||
return IsoBuffer.fromString(value, encodingOrOffset as string | undefined); | ||
} else if (value instanceof IsoBuffer) { | ||
return value; | ||
} else if (value instanceof ArrayBuffer) { | ||
// 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)) { | ||
return IsoBuffer.fromArrayBuffer(value, encodingOrOffset as number | undefined, length); | ||
@@ -81,0 +102,0 @@ } else { |
@@ -9,2 +9,2 @@ /*! | ||
export const pkgName = "@fluidframework/common-utils"; | ||
export const pkgVersion = "0.28.0-16189"; | ||
export const pkgVersion = "0.28.0-18295"; |
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
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
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
459358
35
6425
Updatedlodash@^4.17.21