Compare commits
No commits in common. "2a1e691d62e4e7eb1766a1a82820f526010f02c2" and "be347ca8965f724b7b058aa24139b748fd3927eb" have entirely different histories.
2a1e691d62
...
be347ca896
3 changed files with 8 additions and 18 deletions
|
@ -23,4 +23,4 @@ jobs:
|
|||
run: npm run format-check
|
||||
|
||||
- name: Run tests
|
||||
run: npm run test -- --ci --onlyChanged
|
||||
run: npm run test
|
||||
|
|
|
@ -46,23 +46,13 @@ export type dbReminder = {
|
|||
* @returns An object with the time and the option
|
||||
*/
|
||||
export const splitTime = (time: string) => {
|
||||
const mapping = {
|
||||
[OptionReminder.DirectMessage]: "p",
|
||||
[OptionReminder.Mention]: "@",
|
||||
};
|
||||
|
||||
const lowered = time.toLowerCase();
|
||||
const trimmed = lowered.replaceAll(new RegExp(Object.values(mapping).join("|"), "g"), "");
|
||||
|
||||
// Depending of the last character of the string
|
||||
switch (lowered.slice(-1)) {
|
||||
case mapping[OptionReminder.Mention]:
|
||||
return { time: trimmed, option: OptionReminder.Mention };
|
||||
case mapping[OptionReminder.DirectMessage]:
|
||||
return { time: trimmed, option: OptionReminder.DirectMessage };
|
||||
default:
|
||||
return { time: time, option: OptionReminder.Nothing };
|
||||
if (time?.endsWith("@")) {
|
||||
return { time: time.slice(0, -1), option: OptionReminder.Mention };
|
||||
} else if (time?.toLowerCase().endsWith("p")) {
|
||||
return { time: time.slice(0, -1), option: OptionReminder.DirectMessage };
|
||||
}
|
||||
|
||||
return { time: time, option: OptionReminder.Nothing };
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,7 +10,7 @@ describe("Time splitter", () => {
|
|||
{
|
||||
const name = "2m@p";
|
||||
test(name, () => {
|
||||
expect(splitTime(name)).toStrictEqual({ option: OptionReminder.DirectMessage, time: "2m" });
|
||||
expect(splitTime(name)).toStrictEqual({ option: OptionReminder.Mention, time: "2m" });
|
||||
});
|
||||
}
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue