summaryrefslogtreecommitdiff
path: root/node_modules/discord.js/src/structures/Component.js
blob: 10ba27d0585542a5a2c14254f66ed8bc83df2f7c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';

const isEqual = require('fast-deep-equal');

/**
 * Represents a component
 */
class Component {
  constructor(data) {
    /**
     * The API data associated with this component
     * @type {APIMessageComponent}
     */
    this.data = data;
  }

  /**
   * The type of the component
   * @type {ComponentType}
   * @readonly
   */
  get type() {
    return this.data.type;
  }

  /**
   * Whether or not the given components are equal
   * @param {Component|APIMessageComponent} other The component to compare against
   * @returns {boolean}
   */
  equals(other) {
    if (other instanceof Component) {
      return isEqual(other.data, this.data);
    }
    return isEqual(other, this.data);
  }

  /**
   * Returns the API-compatible JSON for this component
   * @returns {APIMessageComponent}
   */
  toJSON() {
    return { ...this.data };
  }
}

module.exports = Component;