aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/core-utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/core-utils.ts')
-rw-r--r--server/helpers/core-utils.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index 84e33c0e9..3fb824e36 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -11,6 +11,25 @@ import * as pem from 'pem'
11import { URL } from 'url' 11import { URL } from 'url'
12import { truncate } from 'lodash' 12import { truncate } from 'lodash'
13import { exec } from 'child_process' 13import { exec } from 'child_process'
14import { isArray } from './custom-validators/misc'
15
16const objectConverter = (oldObject: any, keyConverter: (e: string) => string, valueConverter: (e: any) => any) => {
17 if (!oldObject || typeof oldObject !== 'object') {
18 return valueConverter(oldObject)
19 }
20
21 if (isArray(oldObject)) {
22 return oldObject.map(e => objectConverter(e, keyConverter, valueConverter))
23 }
24
25 const newObject = {}
26 Object.keys(oldObject).forEach(oldKey => {
27 const newKey = keyConverter(oldKey)
28 newObject[ newKey ] = objectConverter(oldObject[ oldKey ], keyConverter, valueConverter)
29 })
30
31 return newObject
32}
14 33
15const timeTable = { 34const timeTable = {
16 ms: 1, 35 ms: 1,
@@ -235,6 +254,7 @@ export {
235 isTestInstance, 254 isTestInstance,
236 isProdInstance, 255 isProdInstance,
237 256
257 objectConverter,
238 root, 258 root,
239 escapeHTML, 259 escapeHTML,
240 pageToStartAndCount, 260 pageToStartAndCount,