Skip to content

Commit 017f9b1

Browse files
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>
1 parent e74aa7f commit 017f9b1

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

packages/discord.js/src/util/Transformers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const { isJSONEncodable } = require('@discordjs/util');
34
const snakeCase = require('lodash.snakecase');
45

56
/**
@@ -10,6 +11,7 @@ const snakeCase = require('lodash.snakecase');
1011
function toSnakeCase(obj) {
1112
if (typeof obj !== 'object' || !obj) return obj;
1213
if (obj instanceof Date) return obj;
14+
if (isJSONEncodable(obj)) return toSnakeCase(obj.toJSON());
1315
if (Array.isArray(obj)) return obj.map(toSnakeCase);
1416
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [snakeCase(key), toSnakeCase(value)]));
1517
}

0 commit comments

Comments
 (0)