aboutsummaryrefslogtreecommitdiff
path: root/js/src/forms/messages.js
blob: 5c8c162c7e5ea52dbadce15cb46b12dfd956763a (plain)
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
/**
 * --------------------------------------------------------------------------
 * Bootstrap (v5.1.0): forms/messages.js
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
 * --------------------------------------------------------------------------
 */
import TemplateFactory from '../util/template-factory'

class Messages extends Map {
  constructor(templateConfig) {
    super()
    this._templateConfig = templateConfig
  }

  set(key, message) {
    const config = { ...this._templateConfig, content: { div: message } }
    super.set(key, new TemplateFactory(config))
  }

  getAllAsTextArray() {
    return Array.from(this.values()).map(message => message.getContent().join(', '))
  }

  getFirst() {
    const first = this.values().next()
    return first ? first.value : null
  }

  count() {
    return this.size
  }
}

export default Messages