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
/* | |
Merging all the times <entity>.module.ts and fake module instantation is boring for all, so let's help us using this structure. | |
*/ | |
export const moduleConf = { | |
imports: [ | |
TracksModule, | |
MongooseModule.forFeature([{ name: Entity.name, schema: EntitySchema }]), | |
MongooseModule.forFeature([ | |
{ name: SecondEntity.name, schema: SecondEntitySchema }, |
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
/** | |
Do you need to handle a potential RangeError (Max call stack size exceeded) because of a recursive function? | |
Maybe the input should change in several ranges basing on random criterias? | |
Please don't try/catch things lot of times, use this :) | |
Example Usage: | |
[ this is my recursive function ] [these are my fn args], [this are values that will be tried instead of 'ITERATE' arg ] | |
const simplifiedTrack: FeatureCollection = handleSyncRecursion(simplifyGeoJsonWithMaxPointsLimit, [track, 50, 'ITERATE'], [0.001, 0.005, 0.008, 0.01]); | |
*/ |
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
/** | |
* Little helper for creating "side effects" with TypeScript | |
* @param effect {Promise<T> | Function} Function or promise to call independently | |
* @param caller {string} Name of side effect, useful for logging | |
*/ | |
export function sideEffect(effect: Promise<any> | Function, caller: string): void { | |
if (effect instanceof Promise) { | |
effect | |
.then(() => console.log(`Side effect "${caller}" completed without errors.`)) |
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
export class BrokenJSONParser { | |
static forceParseNested(input: string) { | |
if (!input) return null; | |
let stringToParse = input; | |
try { | |
const parsed = JSON.parse(stringToParse); | |
return parsed; | |
} catch (e) { | |
const errorSearchString = 'at position '; | |
const startIndex = e.message.indexOf(errorSearchString); |