Skip to content

Instantly share code, notes, and snippets.

View sankarseran's full-sized avatar

sankaralingam seranthian sankarseran

View GitHub Profile
detectBrowser: function(window) {
var navigator = window && window.navigator;
// Returned result object.
var result = {};
result.browser = null;
result.version = null;
// Fail early if it's not a browser
if (typeof window === 'undefined' || !window.navigator) {
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({name: 'groupBy'})
export class GroupByPipe implements PipeTransform {
transform(collection: Array, property: string): Array {
// prevents the application from breaking if the array of objects doesn't exist yet
if(!collection) {
return null;
}
@sankarseran
sankarseran / keyBoardPrevent.directive.ts
Last active April 27, 2020 06:35
This used prevent the typing in input based on key code. In this directive we can give two type number, alphanumeric and alphabets.
import { Directive, ElementRef, HostListener, Input } from '@angular/core';
@Directive({
// tslint:disable-next-line:directive-selector
selector: '[keyPrevent]'
})
export class KeyPreventDirective {
constructor(private el: ElementRef) { }
import { Pipe } from '@angular/core';
import { DecimalPipe } from '@angular/common';
@Pipe({
name: 'countConvert'
})
export class ThousandPipe extends DecimalPipe {
transform(value: number): any {
if (499 > value) {
return super.transform((value || 0), '1.0-0');
@sankarseran
sankarseran / temporary-email-address-domains
Created September 21, 2018 12:36 — forked from adamloving/temporary-email-address-domains
A list of domains for disposable and temporary email addresses. Useful for filtering your email list to increase open rates (sending email to these domains likely will not be opened).
0-mail.com
0815.ru
0clickemail.com
0wnd.net
0wnd.org
10minutemail.com
20minutemail.com
2prong.com
30minutemail.com
3d-painting.com
@sankarseran
sankarseran / child.component.ts
Created September 17, 2018 11:05
This spinet for loading the component, While the route path is changed but the component is not rendered.
import { ErrorHandler, Injectable, Injector, NgZone } from '@angular/core';
import { Router } from '@angular/router';
@Injectable()
export class AppErrorHandler implements ErrorHandler {
constructor(private injector: Injector) { }
handleError(error: any): void {
const routerService = this.injector.get(Router);
import { EventEmitter, ElementRef, OnInit, Directive, Input, Output } from '@angular/core';
import { Observable } from 'rxjs';
import { NgModel } from '@angular/forms';
@Directive({ selector: '[debounce]' })
export class DebounceDirective implements OnInit {
@Input() delay: number = 700;
@Output() keyUpFunc: EventEmitter<any> = new EventEmitter();
constructor(private elementRef: ElementRef, private model: NgModel) {
import { Directive, HostListener, HostBinding, EventEmitter, Output, Input } from '@angular/core';
@Directive({
selector: '[appDragAndDrop]'
})
export class DragAndDropDirective {
@Input() private allowed_extensions: Array<string> = [];
@Output() private filesChangeEmiter: EventEmitter<File[]> = new EventEmitter();
@Output() private filesInvalidEmiter: EventEmitter<File[]> = new EventEmitter();
@HostBinding('style.background') private background = '#eee';
import {Directive, ElementRef, HostListener, Input} from '@angular/core';
@Directive({
selector: '[onlyNumber]'
})
export class OnlyNumberDirective {
@Input()
onlyNumber: boolean;
ISODateString(d) {
function pad(n) { return n < 10 ? '0' + n : n }
return d.getUTCFullYear() + '-'
+ pad(d.getUTCMonth() + 1) + '-'
+ pad(d.getUTCDate()) + 'T'
+ pad(d.getUTCHours()) + ':'
+ pad(d.getUTCMinutes()) + ':'
+ pad(d.getUTCSeconds()) + 'Z';
}