Files
classroomio/apps/dashboard/src/lib/utils/functions/course.ts
T
Toyin MuhammedandRotimi Best 6d689ede45 feat: unit tests for utils (#92)
* init

* get unit test working for course.ts file

* added some other tests

* tests halfway + change config to accomodate js files

* utility functions tests done

* fix: config file + miscellaneous fixes

* fix: prepare script

* fix lock file

---------

Co-authored-by: Rotimi Best <best@classroomio.com>
2023-12-20 14:28:40 +03:00

39 lines
891 B
TypeScript

import type { Course } from '../types';
export const isCourseFree = (cost: number) => !(Number(cost) > 0);
export const getStudentInviteLink = (_course: Course, orgSiteName: string, origin: string) => {
const hash = encodeURIComponent(
btoa(
JSON.stringify({
groupId: _course.group?.id,
name: _course.title,
description: _course.description,
orgSiteName
})
)
);
return `${origin}/invite/s/${hash}`;
};
export const getTextFromHTML = (html: string): string => {
const dummyDiv = document.createElement('div');
dummyDiv.innerHTML = html;
return dummyDiv.textContent?.trim() || '';
};
const tagsToReplace: { [k: string]: string } = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;'
};
export function replaceHTMLTag(text: string) {
return text
.split('')
.map((char) => tagsToReplace[char] || char)
.join('');
}