mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
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:
@@ -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)]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user