Skip to content

Commit

Permalink
Method to deep copy characters
Browse files Browse the repository at this point in the history
  • Loading branch information
tysoncadenhead committed Feb 1, 2024
1 parent cf027a2 commit 7e3d89b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vestaboard/vbml",
"version": "1.0.12",
"version": "1.0.13",
"description": "The Vestaboard markup language",
"main": "lib/index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/characterCodesToString.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ describe("Convert array of array of characters to a string", () => {
it("Should handle line breaks", () => {
const result = characterCodesToString(
[
[1, 1, 0, 0, 0],
[2, 2, 0, 0, 0],
[1, 2, 0, 0, 0],
[3, 4, 0, 0, 0],
],
{
allowLineBreaks: true,
}
);

expect(result).toEqual("AA\nBB");
expect(result).toEqual("AB\nCD");
});

it("Should assume there is no line break if the first word can fit on the previous line", () => {
Expand Down
13 changes: 13 additions & 0 deletions src/__tests__/copyCharacterCodes.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { copyCharacterCodes } from "../copyCharacterCodes";

describe("Copy character codes", () => {
it("Should deep copy character codes", () => {
const characters = [[1, 2]];
const result = copyCharacterCodes(characters);
expect(result).toEqual([[1, 2]]);
expect(result).not.toBe(characters);

characters[0][0] = 3;
expect(result[0][0]).toEqual(1);
});
});
4 changes: 4 additions & 0 deletions src/copyCharacterCodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Returns a deep copy of the character codes array
export const copyCharacterCodes = (characters: number[][]) => [
...characters.map((row) => [...row]),
];
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { parseComponent } from "./parseComponent";
import { IVBML } from "./types";
import { characterCodesToString } from "./characterCodesToString";
import { characterCodesToAscii } from "./characterCodesToAscii";
import { copyCharacterCodes } from "./copyCharacterCodes";

// Flagship size
const BOARD_ROWS = 6;
Expand All @@ -24,6 +25,7 @@ export const vbml = {
},
characterCodesToString,
characterCodesToAscii,
copyCharacterCodes,
};

export * from "./types";

0 comments on commit 7e3d89b

Please sign in to comment.