Skip to content

Commit

Permalink
Update timeAgo.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
wpdas committed Apr 26, 2024
1 parent f66dbe6 commit 2b7a8ca
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/modules/TimeAgo/timeAgo.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { UseModuleProps } from "alem";
import en from "./en";

// TODO: Fazer video tutorial disso
// Code builder for "formatTimestamp"
const formatTimestampCode = (timestamp: number) => {
const code = `
(() => {
TimeAgo.addDefaultLocale({
${en}
});
return new TimeAgo('en-US').format(new Date(${timestamp}));
})()
`;
return code;
};

const timeAgo = {
moduleSetup: `
TimeAgo.addDefaultLocale({
${en}
})
`,
formatTimestamp: (timestamp: number, onComplete: (data: string) => void) =>
({
setupCode: timeAgo.moduleSetup,
code: `new TimeAgo('en-US').format(new Date(${timestamp}))`,
code: formatTimestampCode(timestamp),
onComplete,
} as UseModuleProps),
};
Expand Down

0 comments on commit 2b7a8ca

Please sign in to comment.