diff options
author | Tyler Schicke <tschicke@gmail.com> | 2020-01-11 14:10:59 -0800 |
---|---|---|
committer | Tyler Schicke <tschicke@gmail.com> | 2020-01-11 14:10:59 -0800 |
commit | f24fcf4df595542d47ec9b98e173979656db68bd (patch) | |
tree | daf32c16ac99add88460980a6f19925806eb51da /src/server/session/utilities/utilities.ts | |
parent | a2f423fa31e649805e7dd087037a5fe262c44a4a (diff) | |
parent | 54a241ff71abc07a5dbdebce1b614f1024a767e6 (diff) |
Merge branch 'master' of github.com:browngraphicslab/Dash-Web into no_db
Diffstat (limited to 'src/server/session/utilities/utilities.ts')
-rw-r--r-- | src/server/session/utilities/utilities.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/server/session/utilities/utilities.ts b/src/server/session/utilities/utilities.ts new file mode 100644 index 000000000..ac8a6590a --- /dev/null +++ b/src/server/session/utilities/utilities.ts @@ -0,0 +1,31 @@ +export namespace Utilities { + + /** + * At any arbitrary layer of nesting within the configuration objects, any single value that + * is not specified by the configuration is given the default counterpart. If, within an object, + * one peer is given by configuration and two are not, the one is preserved while the two are given + * the default value. + * @returns the composition of all of the assigned objects, much like Object.assign(), but with more + * granularity in the overwriting of nested objects + */ + export function preciseAssign(target: any, ...sources: any[]): any { + for (const source of sources) { + preciseAssignHelper(target, source); + } + return target; + } + + export function preciseAssignHelper(target: any, source: any) { + Array.from(new Set([...Object.keys(target), ...Object.keys(source)])).map(property => { + let targetValue: any, sourceValue: any; + if (sourceValue = source[property]) { + if (typeof sourceValue === "object" && typeof (targetValue = target[property]) === "object") { + preciseAssignHelper(targetValue, sourceValue); + } else { + target[property] = sourceValue; + } + } + }); + } + +}
\ No newline at end of file |