diff options
author | Tyler Schicke <tyler_schicke@brown.edu> | 2019-07-22 10:12:18 -0400 |
---|---|---|
committer | Tyler Schicke <tyler_schicke@brown.edu> | 2019-07-22 10:12:18 -0400 |
commit | 6d2795e9f451fd11bfcad4b773b937bc467b55aa (patch) | |
tree | 5abe061feffab40ba81f44a4510e08fde6e0ea20 /src/Utils.ts | |
parent | f7b85fbc695f326fe4f8238254eef8b94dd5b9bb (diff) | |
parent | 0da823a85d1c7a64669d2347344ec28aa08f4c80 (diff) |
Merge branch 'master' of github-tsch-brown:browngraphicslab/Dash-Web
Diffstat (limited to 'src/Utils.ts')
-rw-r--r-- | src/Utils.ts | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/Utils.ts b/src/Utils.ts index ac6d127cc..8df67df5d 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -146,7 +146,7 @@ export type Without<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; export type Predicate<K, V> = (entry: [K, V]) => boolean; -export function deepCopy<K, V>(source: Map<K, V>, predicate?: Predicate<K, V>) { +export function DeepCopy<K, V>(source: Map<K, V>, predicate?: Predicate<K, V>) { let deepCopy = new Map<K, V>(); let entries = source.entries(), next = entries.next(); while (!next.done) { @@ -157,4 +157,18 @@ export function deepCopy<K, V>(source: Map<K, V>, predicate?: Predicate<K, V>) { next = entries.next(); } return deepCopy; +} + +export namespace JSONUtils { + + export function tryParse(source: string) { + let results: any; + try { + results = JSON.parse(source); + } catch (e) { + results = source; + } + return results; + } + }
\ No newline at end of file |