Skip to content

Commit

Permalink
Merge pull request #6 from Vestaboard/feature/case-for-bracket-single…
Browse files Browse the repository at this point in the history
…-digit

case for brackets single digit
  • Loading branch information
jottenlips authored Jul 10, 2024
2 parents f4c1a55 + e571f78 commit 6590763
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 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.2.2",
"version": "1.2.3",
"description": "The Vestaboard markup language",
"main": "lib/index.js",
"scripts": {
Expand Down
53 changes: 43 additions & 10 deletions src/__tests__/classic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ describe("Classic", () => {
});

it("Should convert string to classic board", () => {
// should be 3 lines
// 57 characters
const string = "reallylongwordthatismorethantwentytwocharcters";
const classicBoard = classic(string);
expect(classicBoard).toEqual([
Expand All @@ -64,8 +62,6 @@ describe("Classic", () => {
});

it("Should convert string to classic board", () => {
// should be 3 lines
// 57 characters
const string = "reallylongwordthatismorethan22charcters";
const classicBoard = classic(string);
expect(classicBoard).toEqual([
Expand All @@ -85,8 +81,6 @@ describe("Classic", () => {
});

it("Should convert string to classic board", () => {
// should be 3 lines
// 57 characters
const string = `hello
world`;
const classicBoard = classic(string);
Expand All @@ -101,15 +95,11 @@ describe("Classic", () => {
});

it("Should convert string to classic board", () => {
// should be 3 lines
// 57 characters
const string = `hello\n\nworld`;
const classicBoard = classic(string);
expect(classicBoard).toEqual([[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,8,5,12,12,15,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,23,15,18,12,4,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]);
});
it("Should convert string to classic board", () => {
// should be 3 lines
// 57 characters
const string = ``;
const classicBoard = classic(string);
const emptyRow = new Array(22).fill(0);
Expand All @@ -123,4 +113,47 @@ describe("Classic", () => {
emptyRow,
]);
});

it("Should convert string to classic board", () => {
const string = `{1}`;
const classicBoard = classic(string);
expect(classicBoard).toEqual( [
[
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0
],
[
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0
],
[
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0
],
[
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0
],
[
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0
],
[
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0
]
]);
});
});
4 changes: 2 additions & 2 deletions src/classic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ export function classic(text: string, extraHPadding = 0): Array<Array<number>> {
}

const lines = text.split("\n");
const wordCharCodeRegex = /[a-zA-Z]+|\{.\d\}+|\d+|\s+|[^\w\s]/g;
const wordCharCodeRegex = /[a-zA-Z]+|\{.\d\}+|\{\d\}+|\d+|\s+|[^\w\s]/g;

const chunkedLines = lines.map((line) => {
const words = line.match(wordCharCodeRegex);
return words;
});

const vestaboardCharsLines = chunkedLines
.map((line) => {
return line?.flatMap((word) => {
Expand Down

0 comments on commit 6590763

Please sign in to comment.