UNPKG

644 BPlain TextView Raw
1// Copyright (c) .NET Foundation. All rights reserved.
2// Licensed under the MIT License.
3
4export function toCamelCaseValue(data: unknown): unknown {
5 if (typeof data !== 'object' || data === null) {
6 return data;
7 } else if (Array.isArray(data)) {
8 return data.map(toCamelCaseValue);
9 } else {
10 const result = {};
11 for (const [key, value] of Object.entries(data)) {
12 result[toCamelCaseKey(key)] = toCamelCaseValue(value);
13 }
14 return result;
15 }
16}
17
18export function toCamelCaseKey(key: string): string {
19 return key.charAt(0).toLowerCase() + key.slice(1);
20}