Skip to content

Commit

Permalink
fix(Transfomers): call .toJSON in toSnakeCase (#8790)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
RedGuy12 and kodiakhq[bot] committed Nov 19, 2022
1 parent e74aa7f commit 017f9b1
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/discord.js/src/util/Transformers.js
@@ -1,5 +1,6 @@
'use strict';

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

/**
Expand All @@ -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)]));
}
Expand Down

0 comments on commit 017f9b1

Please sign in to comment.