fix(Transfomers): call .toJSON in toSnakeCase (#8790)

* fix(Transfomers): call `.toJSON` in `toSnakeCase`

Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>

* fix: move it under the Date check

Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>

* fix(toSnakeCase): stop assuming `toJSON` returns snake_case values

Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>

Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
RedGuy12
2022-11-19 15:01:41 -06:00
committed by GitHub
parent e74aa7f6b0
commit 017f9b1ed4

View File

@@ -1,5 +1,6 @@
'use strict';
const { isJSONEncodable } = require('@discordjs/util');
const snakeCase = require('lodash.snakecase');
/**
@@ -10,6 +11,7 @@ const snakeCase = require('lodash.snakecase');
function toSnakeCase(obj) {
if (typeof obj !== 'object' || !obj) return obj;
if (obj instanceof Date) return obj;
if (isJSONEncodable(obj)) return toSnakeCase(obj.toJSON());
if (Array.isArray(obj)) return obj.map(toSnakeCase);
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [snakeCase(key), toSnakeCase(value)]));
}