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
// 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) { |
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
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 })); |
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
interface IIsObject { | |
(item: any): boolean; | |
} | |
interface IObject { | |
[key: string]: any; | |
} | |
interface IDeepMerge { | |
(target: IObject, ...sources: Array<IObject>): IObject; |
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
/** | |
* @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)); | |
} |
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
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 |
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
'use strict'; | |
/** | |
* @method flattenArray | |
* @description A method to convert multi dimensional arrays to 1D arrays | |
* @param {Array} arr - The multi D array that needs to be flattened (converted to 1D) | |
* @param {String} [key] - An object key that will be used to flatten an array of | |
* nested objects (e.g. "[ { key: [ val1, val2, ..., valN ] }, { key: [ val1, val2, ..., valN ] } ]") | |
* @param {Boolean} [remove] - Flag to indicate whether or not to delete object's children if | |
* they are not need it after flattening (e.g. if true, will remove "key: [ val1, val2, ..., valN ]" after it is being flattened) |
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 SaveFileCtrl (SaveFileService) { | |
var vm = this; | |
function downloadFile(someArgument) { | |
SaveFileService.downloadFile({ | |
param: someArgument | |
}, function (response) { | |
var fileName = response.headers['content-disposition'].split("=")[1].replace(/\"/gi,''); | |
var fileType = response.headers['content-type'] + ';charset=utf-8'; | |
var blob = new Blob([response.data], { type: fileType }); |
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
// 1d array | |
for (var i = 0, len = arr.length; i < len; i++) { | |
if (somevalue < arr[i]) { | |
arr.splice(i, 0, somevalue); | |
break; | |
} | |
} | |
return arr; |
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
// date format: 'YYYY-MM-dd' | |
var RegExp = /^(199\\d)|([2-9]\\d{3})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])$/; | |
// date format: 'MM/dd/YYYY', | |
RegExp = /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/; | |
// passed as a string | |
var regexp = new RegExp('^(0[1-9]|1[0-2])\/(0[1-9]|1\\d|2\\d|3[01])\/(19|20)\\d{2}$'); |
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
// from https://www.sitepoint.com/sort-an-array-of-objects-in-javascript/ | |
function compareValues(key, order='asc') { | |
return function(a, b) { | |
if(!a.hasOwnProperty(key) || !b.hasOwnProperty(key)) { | |
return 0; | |
} | |
const valA = (typeof a[key] === 'string') ? a[key].toUpperCase() : a[key]; | |
const valB = (typeof b[key] === 'string') ? b[key].toUpperCase() : b[key]; | |
let comparison = 0; |
NewerOlder