diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2020-02-10 12:07:32 -0500 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2020-02-10 12:07:32 -0500 |
commit | 3f3fbcf0c2ea60625f20f3d06388723645e78170 (patch) | |
tree | a8d7796a8cdefbcaaa0db4c7493912b8f5f01fac /src/server/DashSession/Session/utilities/utilities.ts | |
parent | ffeddae0e12719c7bf2a07468822c9547772febc (diff) |
server session now local
Diffstat (limited to 'src/server/DashSession/Session/utilities/utilities.ts')
-rw-r--r-- | src/server/DashSession/Session/utilities/utilities.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/server/DashSession/Session/utilities/utilities.ts b/src/server/DashSession/Session/utilities/utilities.ts new file mode 100644 index 000000000..eb8de9d7e --- /dev/null +++ b/src/server/DashSession/Session/utilities/utilities.ts @@ -0,0 +1,37 @@ +import { v4 } from "uuid"; + +export namespace Utilities { + + export function guid() { + return v4(); + } + + /** + * 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 |