diff options
author | yipstanley <stanley_yip@brown.edu> | 2019-07-22 17:16:41 -0400 |
---|---|---|
committer | yipstanley <stanley_yip@brown.edu> | 2019-07-22 17:16:41 -0400 |
commit | 4d6aee4230e60b67ba62609ef543845c230ce739 (patch) | |
tree | 31af1ba8650bb9b0486d2dd86b41c88ed43aa829 /src/Utils.ts | |
parent | 5e9bcf2e35415fd0ab4dec4f0141511cd4d312d0 (diff) | |
parent | fc1dbb1327d10bd1832d33a87d18cff1e836ecfb (diff) |
merge from master
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 |