Skip to content

Instantly share code, notes, and snippets.

@mir4ef
mir4ef / sonar-project.properties
Last active August 7, 2017 20:11
Sonar properties file for angular 2+ applications
sonar.projectKey = company:mycompay
sonar.projectName = My Project
sonar.projectVersion = 0.0.1
sonar.sourceEncoding = UTF-8
sonar.sources = src/app
sonar.exclusions = **/node_modules/**,**/*.spec.ts
sonar.tests = src/app
sonar.test.inclusions = **/*.spec.ts
sonar.ts.tslint.configPath = tslint.json
@mir4ef
mir4ef / deep-merge.js
Created January 9, 2018 02:44
Deep Merge JavaScript Objects
/**
* @description Method to check if an item is an object. Date and Function are considered
* an object, so if you need to exclude those, please update the method accordingly.
* @param item - The item that needs to be checked
* @return {Boolean} Whether or not @item is an object
*/
function isObject(item) {
return (item === Object(item) && !Array.isArray(item));
}
@mir4ef
mir4ef / deep-merge.ts
Created January 9, 2018 03:14
Deep merging of JavaScript objects (in TypeScript)
interface IIsObject {
(item: any): boolean;
}
interface IObject {
[key: string]: any;
}
interface IDeepMerge {
(target: IObject, ...sources: Array<IObject>): IObject;
@mir4ef
mir4ef / async-await-handler.ts
Last active September 21, 2019 04:59
async/await utility function for more elegant handling of failures rather than adding try/catch blocks everywhere. This allows us to also know what exactly failed.
interface IAsyncAwait<T, R> {
error: R|Error|null;
response: T|null;
}
// async/await utility function for more elegant handling of failures
const asyncAwaitHandler: <A, B>(promise: Promise<A>) => Promise<IAsyncAwait<A|null, B|null>> = <A, B>(promise: Promise<A>): Promise<IAsyncAwait<A|null, B|null>> => {
return promise
.then((response: A): IAsyncAwait<A, null> => ({ error: null, response }))
.catch((error: B): Promise<IAsyncAwait<null, B>> => Promise.resolve({ error, response: null }));
@mir4ef
mir4ef / async-await-handler.js
Created August 23, 2019 15:43
async/await utility function for more elegant handling of failures rather than adding try/catch blocks everywhere. This allows us to also know what exactly failed.
// async/await utility function for more elegant handling of failures
const asyncAwaitHandler = promise => {
return promise
.then(response => ({ error: null, response }))
.catch(error => Promise.resolve({ error, response: null }));
};
// example promise
const myPromise = (errorMe) => {
if (errorMe) {