Skip to content

Instantly share code, notes, and snippets.

View faisalmuhammad's full-sized avatar
🎯
Focusing

Muhammad Faisal faisalmuhammad

🎯
Focusing
View GitHub Profile
export class Mapping {
/**
* Checks if the given json object is type of a given instance (class/interface) type.
* @param jsonObject Object to check.
* @param instanceType The type to check for the object.
* @returns true if object is of the given instance type; false otherwise.
*/
public static isTypeOf<T>(jsonObject: Object, instanceType: { new(): T; }): boolean {
// Check that all the properties of the JSON Object are also available in the Class.
const instanceObject = new instanceType();
@faisalmuhammad
faisalmuhammad / local-storage.ts
Last active October 15, 2020 13:12
Generic Local Storage Class
/**
* Customized HTML5 local storage class with additional functionality.
*/
export class LocalStorage {
/**
* Checks if the browser supports local storage.
* @returns true if the local storage is supported; false otherwise.
*/
public static isSupported(): boolean {
try {
@faisalmuhammad
faisalmuhammad / development-only.directive.ts
Last active July 13, 2018 18:29
Angular | Development Only Directive
/**
* @author Muhammad FAISAL
* @description Controls the display of html contents only during development mode.
* @example <button development-only>Some Button</button>
*/
// Angular Imports
import { Directive, OnInit, ElementRef, isDevMode } from '@angular/core';
// Define class for the Directive
@faisalmuhammad
faisalmuhammad / data.service.ts
Created June 4, 2018 10:04
Angular | Parallel API Requests
/**
* @author Muhammad Faisal
* @description Service for getting data.
*/
// Angular Imports
import { Injectable } from '@angular/core';
import { HttpErrorResponse } from '@angular/common/http';
import { forkJoin as observableForkJoin, Observable } from 'rxjs';
@faisalmuhammad
faisalmuhammad / password.pipe.ts
Created June 5, 2018 10:16
Pipe to replace the value with * or specified character
/**
* @author Muhammad Faisal
* @description Pipe to replace the value with * or specified character.
*/
// Angular Imports
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'password'