docs: add JSDoc comments to SharedService
This commit is contained in:
parent
8557a2f7f0
commit
11e9161135
1 changed files with 52 additions and 0 deletions
|
|
@ -22,26 +22,65 @@ export class SharedService {
|
||||||
|
|
||||||
// CHECK VIEW WIDTH
|
// CHECK VIEW WIDTH
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the window resize listener.
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* This function will set up the window resize listener and bind the
|
||||||
|
* onResize() method to it.
|
||||||
|
*/
|
||||||
private initResizeListener() {
|
private initResizeListener() {
|
||||||
this.resizeListener = this.onResize.bind(this);
|
this.resizeListener = this.onResize.bind(this);
|
||||||
window.addEventListener('resize', this.resizeListener);
|
window.addEventListener('resize', this.resizeListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the window resize listener.
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* This function will remove the window resize listener that was set up in
|
||||||
|
* the constructor. This is useful when the service is being destroyed.
|
||||||
|
*/
|
||||||
private removeResizeListener() {
|
private removeResizeListener() {
|
||||||
window.removeEventListener('resize', this.resizeListener);
|
window.removeEventListener('resize', this.resizeListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Window resize event listener method.
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* This method will update the isPageViewMedia and isContactViewMedia
|
||||||
|
* properties based on the current window width whenever the window is
|
||||||
|
* resized.
|
||||||
|
*/
|
||||||
private onResize() {
|
private onResize() {
|
||||||
this.isPageViewMedia = window.innerWidth <= 650;
|
this.isPageViewMedia = window.innerWidth <= 650;
|
||||||
this.isContactViewMedia = window.innerWidth <= 800;
|
this.isContactViewMedia = window.innerWidth <= 800;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleans up the service by removing the window resize listener.
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* This function is useful when the service is being destroyed.
|
||||||
|
*/
|
||||||
cleanup() {
|
cleanup() {
|
||||||
this.removeResizeListener();
|
this.removeResizeListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
// RANDOM COLOR
|
// RANDOM COLOR
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a random color string.
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* The generated color is a hex string that is not a shade of gray.
|
||||||
|
* The color is generated by randomly selecting a hex digit from the
|
||||||
|
* string '0123456789ABCDEF' and appending it to the color string. The
|
||||||
|
* loop continues until a non-gray color is generated.
|
||||||
|
*
|
||||||
|
* @returns A random color string.
|
||||||
|
*/
|
||||||
generateRandomColor(): string {
|
generateRandomColor(): string {
|
||||||
const letters = '0123456789ABCDEF';
|
const letters = '0123456789ABCDEF';
|
||||||
let color = '#';
|
let color = '#';
|
||||||
|
|
@ -62,6 +101,13 @@ export class SharedService {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a hex color string to an RGB object.
|
||||||
|
*
|
||||||
|
* @param hex A color string in hex format, e.g. '#FF0000'.
|
||||||
|
* @returns An object with r, g, and b properties, each an integer between
|
||||||
|
* 0 and 255, representing the red, green, and blue components of the color.
|
||||||
|
*/
|
||||||
hexToRgb(hex: string): { r: number; g: number; b: number } {
|
hexToRgb(hex: string): { r: number; g: number; b: number } {
|
||||||
const bigint = parseInt(hex.substring(1), 16);
|
const bigint = parseInt(hex.substring(1), 16);
|
||||||
const r = (bigint >> 16) & 255;
|
const r = (bigint >> 16) & 255;
|
||||||
|
|
@ -72,6 +118,12 @@ export class SharedService {
|
||||||
|
|
||||||
// SECURITY
|
// SECURITY
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitizes the input string by replacing any potential cross-site scripting characters.
|
||||||
|
* This ensures that the input string is safe to be stored in the Firebase Realtime Database.
|
||||||
|
* @param input The input string to be sanitized.
|
||||||
|
* @returns The sanitized string.
|
||||||
|
*/
|
||||||
replaceXSSChars(input: string) {
|
replaceXSSChars(input: string) {
|
||||||
return input.replace(/</g, '<').replace(/>/g, '>');
|
return input.replace(/</g, '<').replace(/>/g, '>');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue