mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 01:53:30 +01:00
Add toJSON methods (#1859)
* tojson things * fix client * ignore private properties * remove extra property descriptors * handle primitive flattening * remove unused import * add toJSON to collections * reduce stateful props * state * allow custom prop names when flattening * fix client * fix build * fix flatten docs * remove guild.available, cleanup permissions, remove arbitrary id reduction * fix util import * add valueOf as needed, update member props * fix incorrect merge * update permissionoverwrites and permissions remove serialization of permissions in PermissionOverwrites#toJSON. change Permissions#toJSON to serialize permissions, by default excluding admin checks. * change Permissions#toJSON to return the primitive * Permissions#toJSON explicitly return bitfield
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
const Util = require('./Util');
|
||||
|
||||
/**
|
||||
* A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has
|
||||
* an ID, for significantly improved performance and ease-of-use.
|
||||
@@ -425,6 +427,10 @@ class Collection extends Map {
|
||||
sort(compareFunction = (x, y) => +(x > y) || +(x === y) - 1) {
|
||||
return new Collection([...this.entries()].sort((a, b) => compareFunction(a[1], b[1], a[0], b[0])));
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return this.map(e => typeof e.toJSON === 'function' ? e.toJSON() : Util.flatten(e));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Collection;
|
||||
|
||||
Reference in New Issue
Block a user