-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
76 lines (61 loc) · 1.79 KB
/
index.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Main for the the Bots Shortcodes package
*/
class BotsShortcodes {
/**
* Create a new BotsShortcodes object
*/
constructor() {
this.shortcodes = [];
this.shotcodeTags = [];
}
/**
* Add a shortcode to the list of ones that will be used to process answers.
*
* @param {object} shortcode An instantiated shortcode object ready for use.
*/
addShortcode( shortcode ) {
if ( typeof shortcode === "undefined" ) {
throw new TypeError( "shortcode argument is required" );
}
if ( typeof shortcode !== "object" ) {
throw new TypeError( "shortcode argument must be an object" );
}
this.shortcodes.push( shortcode );
this.tags.push( shortcode.tag );
}
/**
* Return a list of tags configured for use.
*
* @returns {Array} an array of shortcode tags
*/
get tags() {
return this.getTagNames();
}
/**
* Return a list of tag names configured for use.
*
* @returns {Array} an array of shortcode tag names
*/
getTagNames() {
return this.shotcodeTags;
}
/**
* Check the answer for all of the configured shortcodes.
*
* @param {string} answerContent The content of the answer.
*
* @returns {string} The updated answer content.
*/
async processAnswer( answerContent ) {
for ( let i = 0; i < this.shortcodes.length; i++ ) {
// eslint-disable-next-line security/detect-object-injection
const shortcode = this.shortcodes[ i ];
answerContent = await shortcode.replace( answerContent );
}
return answerContent;
}
}
module.exports.BotsShortcodes = BotsShortcodes;
module.exports.LibraryOpenToday = require( "./shortcodes/libraryOpenToday.js" ).LibraryOpenToday;
module.exports.TestingShortcode = require( "./shortcodes/testingShortcode.js" ).TestingShortcode;