2023-10-20 04:16:07 +00:00
|
|
|
import { browser } from '$app/environment';
|
2023-09-14 23:04:51 +01:00
|
|
|
import type { Course } from '../types';
|
|
|
|
|
|
|
|
|
|
export const isCourseFree = (cost: number) => !(Number(cost) > 0);
|
|
|
|
|
|
|
|
|
|
export const getStudentInviteLink = (_course: Course, orgSiteName: string) => {
|
|
|
|
|
const hash = encodeURIComponent(
|
|
|
|
|
btoa(
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
groupId: _course.group?.id,
|
|
|
|
|
name: _course.title,
|
|
|
|
|
description: _course.description,
|
|
|
|
|
orgSiteName
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return `https://${orgSiteName}.classroomio.com/invite/s/${hash}`;
|
|
|
|
|
};
|
2023-10-15 04:38:37 +00:00
|
|
|
|
|
|
|
|
export const getTextFromHTML = (html: string): string => {
|
2023-10-20 04:16:07 +00:00
|
|
|
if (!browser) return html;
|
|
|
|
|
|
2023-10-15 04:38:37 +00:00
|
|
|
const dummyDiv = document.createElement('div');
|
|
|
|
|
dummyDiv.innerHTML = html;
|
|
|
|
|
|
|
|
|
|
return dummyDiv.textContent?.trim() || '';
|
|
|
|
|
};
|
2023-10-21 07:44:57 +00:00
|
|
|
|
|
|
|
|
const tagsToReplace = {
|
|
|
|
|
'&': '&',
|
|
|
|
|
'<': '<',
|
|
|
|
|
'>': '>'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function replaceHTMLTag(text: string) {
|
|
|
|
|
return text
|
|
|
|
|
.split('')
|
|
|
|
|
.map((char) => tagsToReplace[char] || char)
|
|
|
|
|
.join('');
|
|
|
|
|
}
|