UNPKG

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