forked from SimpleRegex/SRL-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimesMethod.js
More file actions
33 lines (25 loc) · 827 Bytes
/
TimesMethod.js
File metadata and controls
33 lines (25 loc) · 827 Bytes
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
'use strict'
const Method = require('./Method')
const SyntaxException = require('../../Exceptions/Syntax')
/**
* Method having one or two parameters. First is simple, ignoring second "time" or "times". Will throw SyntaxException if more parameters provided.
*/
class TimeMethod extends Method {
/**
* @inheritdoc
*/
setParameters(parameters) {
parameters = parameters.filter((parameter) => {
if (typeof parameter !== 'string') {
return true
}
const lower = parameter.toLowerCase()
return lower !== 'times' && lower !== 'time'
})
if (parameters.length > 1) {
throw new SyntaxException('Invalid parameter.')
}
return super.setParameters(parameters)
}
}
module.exports = TimeMethod