Skip to content

Commit 54b16e1

Browse files
committed
Convert snake_case to camelCase during serialisation
Signed-off-by: Itay Dafna <[email protected]>
1 parent c60b91f commit 54b16e1

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

js/datagrid.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,28 @@ export class DataGridModel extends DOMWidgetModel {
258258
_view_callbacks: ICallbacks;
259259
}
260260

261+
/**
262+
* Helper function to conver snake_case strings to camelCase.
263+
* Assumes all strings are valid snake_case (all lowercase).
264+
* @param string snake_case string
265+
* @returns camelCase string
266+
*/
267+
function camelCase(string: string): string {
268+
string = string.toLowerCase();
269+
const charArray = [];
270+
for (let i = 0; i < string.length; i++) {
271+
const curChar = string.charAt(i);
272+
if (curChar === '_') {
273+
i++;
274+
charArray.push(string.charAt(i).toUpperCase());
275+
continue;
276+
}
277+
charArray.push(curChar);
278+
}
279+
280+
return charArray.join('');
281+
}
282+
261283
/**
262284
* Custom deserialization function for grid styles.
263285
*/
@@ -268,7 +290,7 @@ function unpack_style(
268290
if (value instanceof Object && typeof value !== 'string') {
269291
const unpacked: { [key: string]: any } = {};
270292
Object.keys(value).forEach((key) => {
271-
unpacked[key] = unpack_style(value[key], manager);
293+
unpacked[camelCase(key)] = unpack_style(value[key], manager);
272294
});
273295
return resolvePromisesDict(unpacked);
274296
} else if (typeof value === 'string' && value.slice(0, 10) === 'IPY_MODEL_') {

0 commit comments

Comments
 (0)