Skip to content

Commit

Permalink
feat: ✨ keep emojis on cli
Browse files Browse the repository at this point in the history
  • Loading branch information
gouz committed May 4, 2024
1 parent 5b4a788 commit 882f732
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "choc",
"version": "0.1.11",
"version": "0.1.12",
"module": "src/index.ts",
"type": "module",
"devDependencies": {
Expand Down
32 changes: 10 additions & 22 deletions src/DTO.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Options, SpeakerData, Talk, TalkRow } from "./types";
import { removeEmojis, splitString } from "./utils";
import { splitString } from "./utils";

const getCompanies = (speakerHash: Map<string, SpeakerData>, uid: string) => ({
company: speakerHash.get(uid)?.company,
Expand All @@ -9,24 +9,15 @@ const getAdresses = (speakerHash: Map<string, SpeakerData>, uid: string) => ({
addresses: speakerHash.get(uid)?.address,
});

const getFormats = (
formatsHash: Map<string, string>,
format: string,
removeEmoji: boolean = false
) => ({
format: removeEmoji
? removeEmojis(formatsHash.get(format))
: formatsHash.get(format),
const getFormats = (formatsHash: Map<string, string>, format: string) => ({
format: formatsHash.get(format),
});

const getCategories = (
categoriesHash: Map<string, string>,
category: string,
removeEmoji: boolean = false
category: string
) => ({
categories: removeEmoji
? removeEmojis(categoriesHash.get(category))
: categoriesHash.get(category),
categories: categoriesHash.get(category),
});

export const DTO = (
Expand All @@ -52,20 +43,17 @@ export const DTO = (
position: number
) => {
const lines: TalkRow[] = [];
let titleSplit: string[] = splitString(
removeEmojis(title),
options.titlelength
).map((text) => text.padEnd(options.titlelength, " "));
let titleSplit: string[] = splitString(title, options.titlelength).map(
(text) => text.padEnd(options.titlelength, " ")
);
speakers.forEach((uid: string, i: number) => {
if (i === 0) {
lines.push({
position: position + 1,
title: titleSplit.shift(),
...(options.withFormats
? getFormats(formatsHash, formats, true)
: {}),
...(options.withFormats ? getFormats(formatsHash, formats) : {}),
...(options.withCategories
? getCategories(categoriesHash, categories, true)
? getCategories(categoriesHash, categories)
: {}),
speakers: speakerHash.get(uid)?.name,
...(options.withCompanies ? getCompanies(speakerHash, uid) : {}),
Expand Down
4 changes: 0 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,3 @@ export const splitString = (str: string, n: number): string[] => {
}
return result;
};

export const removeEmojis = (str: string | undefined): string => {
return str?.replace(/[^\p{L}\p{N}\p{P}\p{Z}^$\n]/gu, "").trim() ?? "";
};

0 comments on commit 882f732

Please sign in to comment.