Skip to content

Commit

Permalink
fix(uint32ArrayFrom): increment index & polyfill for Uint32Array (#270)
Browse files Browse the repository at this point in the history
increment index and polyfill for Uint32Array instead of Array
  • Loading branch information
texastony authored Dec 1, 2021
1 parent c63b577 commit a70d603
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/util/src/uint32ArrayFrom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

// IE 11 does not support Array.from, so we do it manually
export function uint32ArrayFrom(a_lookUpTable: Array<number>): Uint32Array {
if (!Array.from) {
if (!Uint32Array.from) {
const return_array = new Uint32Array(a_lookUpTable.length)
let a_index = 0
while (a_index < a_lookUpTable.length) {
return_array[a_index] = a_lookUpTable[a_index]
a_index += 1
}
return return_array
}
Expand Down
20 changes: 20 additions & 0 deletions packages/util/test/uint32ArrayFrom.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { expect } from "chai";
import "mocha";
import { uint32ArrayFrom } from "../src/uint32ArrayFrom";

describe("uint32ArrayFrom", () =>{
it("When given an empty array, should return an empty array", () => {
expect(uint32ArrayFrom(Array.of(0)))
.to
.eql(Uint32Array.of(0))
})

it("Given a populated array, returns a valid Uint32 Array", () => {
expect(uint32ArrayFrom(Array.of(0x00000000, 0xF26B8303, 0xE13B70F7)))
.to
.eql(Uint32Array.of(0, 4067132163, 3778769143))
})
})

0 comments on commit a70d603

Please sign in to comment.