This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'indianCurrency' | |
}) | |
export class IndiaCurrencyPipe implements PipeTransform { | |
transform(amount: any, args?: any): string { | |
if (amount !== null && !isNaN(amount)) { | |
const currencySymbol = '₹ '; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.getCollection('companydetails').aggregate([ | |
{ "$group": { | |
"_id": { "$toLower": "$state" }, | |
"count": { "$sum": 1 } | |
} }, | |
{ "$group": { | |
"_id": null, | |
"counts": { | |
"$push": { "k": "$_id", "v": "$count" } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.mash = function(callback) { | |
const addKeyValuePair = (acc, item) => { | |
const [key, value] = callback ? callback(item) : item | |
return {...acc, [key]: value} | |
} | |
return this.reduce(addKeyValuePair, {}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.scan = function (callback, initialValue) { | |
const appendAggregate = (acc, item) => { | |
const aggregate = acc[acc.length-1] //get last item | |
const newAggregate = callback(aggregate, item) | |
return [...acc, newAggregate] | |
} | |
const accumulator = [initialValue] | |
return this.reduce(appendAggregate, accumulator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function debounce(func, wait, immediate) { | |
var timeout; | |
return function() { | |
var context = this, args = arguments; | |
var later = function() { | |
timeout = null; | |
if (!immediate) func.apply(context, args); | |
}; | |
var callNow = immediate && !timeout; | |
clearTimeout(timeout); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let getFileName = function (header) { | |
let contentDispostion = header.split(';'); | |
const fileNameToken = `filename*=UTF-8''`; | |
let fileName = 'downloaded.pdf'; | |
for (let thisValue of contentDispostion) { | |
if (thisValue.trim().indexOf(fileNameToken) === 0) { | |
fileName = decodeURIComponent(thisValue.trim().replace(fileNameToken, '')); | |
break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function curry(fn) { | |
var arity = fn.length; | |
return (function resolver() { | |
var memory = Array.prototype.slice.call(arguments); | |
return function () { | |
var local = memory.slice(), | |
next; | |
Array.prototype.push.apply(local, arguments); | |
next = local.length >= arity ? fn : resolver; | |
return next.apply(null, local); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MyPromise(executor) { | |
let onResolve, onReject; | |
let fulfilled = false, | |
rejected = false, | |
called = false, | |
value; | |
function resolve(v) { | |
fulfilled = true; | |
value = v; |