UNPKG

841 BJavaScriptView Raw
1'use strict';
2
3const FUNCTION_ID_PATTEN = /(([a-zA-Z_][\w-]{0,127})\/)?([a-zA-Z_][\w-]{0,127})$/;
4const SERVICE_NAME_REGEX_INDEX = 2;
5const FUNCTION_NAME_REGEX_INDEX = 3;
6
7class FunctionIdentifier {
8 constructor(identifier) {
9 const results = identifier.match(FUNCTION_ID_PATTEN);
10 if (!results) {
11 throw new Error(
12 `Can't parse the given string as a function identifier: ${identifier}.`
13 );
14 }
15 this._identifier = identifier;
16 this._serviceName = results[SERVICE_NAME_REGEX_INDEX];
17 this._functionName = results[FUNCTION_NAME_REGEX_INDEX];
18 }
19
20 get identifier() {
21 return this._identifier;
22 }
23
24 get serviceName() {
25 return this._serviceName;
26 }
27
28 get functionName() {
29 return this._functionName;
30 }
31
32 toString() {
33 return this._identifier;
34 }
35}
36
37module.exports = FunctionIdentifier;
\No newline at end of file