Skip to content

Commit

Permalink
Merge pull request #3 from Vestaboard/feature/emoji-character-codes
Browse files Browse the repository at this point in the history
Convert emoji colors to character codes
  • Loading branch information
tysoncadenhead committed Apr 16, 2024
2 parents 621af56 + d771f35 commit a8a3f9d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 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.1.0",
"version": "1.2.0",
"description": "The Vestaboard markup language",
"main": "lib/index.js",
"scripts": {
Expand Down
8 changes: 8 additions & 0 deletions src/__tests__/parseComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,12 @@ describe("Parse Component", () => {
[3, 4],
]);
});

it("Should convert emoji characters to character codes", () => {
const input: IVBMLComponent = {
template: "🟥🟧🟨🟩🟦🟪⬜⬛",
};
const result = parseComponent(1, 8)(input);
expect(result).toEqual([[63, 64, 65, 66, 67, 68, 69, 70]]);
});
});
10 changes: 10 additions & 0 deletions src/emojisToCharacterCodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const emojisToCharacterCodes = (template: string) =>
template
.replace(/🟥/g, "{63}")
.replace(/🟧/g, "{64}")
.replace(/🟨/g, "{65}")
.replace(/🟩/g, "{66}")
.replace(/🟦/g, "{67}")
.replace(/🟪/g, "{68}")
.replace(//g, "{69}")
.replace(//g, "{70}");
7 changes: 6 additions & 1 deletion src/parseComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { parseProps } from "./parseProps";
import { splitWords } from "./splitWords";
import pipe from "lodash/fp/pipe";
import map from "lodash/fp/map";
import { emojisToCharacterCodes } from "./emojisToCharacterCodes";

export const parseComponent =
(defaultHeight: number, defaultWidth: number, props?: VBMLProps) =>
(component: IVBMLComponent) => {
Expand All @@ -18,15 +20,18 @@ export const parseComponent =
const height = component?.style?.height || defaultHeight;
const emptyComponent = createEmptyBoard(height, width);

const template = "template" in component ? component.template : "";

return pipe(
emojisToCharacterCodes,
parseProps(props || {}),
splitWords(width),
getLinesFromWords(width),
map(convertCharactersToCharacterCodes),
verticalAlign(height, component?.style?.align || Align.top),
horizontalAlign(width, component?.style?.justify || Justify.left),
renderComponent(emptyComponent)
)("template" in component ? component.template : "") as number[][];
)(template) as number[][];
};

export const parseAbsoluteComponent =
Expand Down

0 comments on commit a8a3f9d

Please sign in to comment.