Fix compatibility with earlier Node.js versions

Named regex match groups are not supported until Node.js 10.0.0
This commit is contained in:
Matthew Oslan
2019-06-29 13:10:22 -04:00
parent 5f35b0410c
commit aa26698481

View File

@@ -453,10 +453,13 @@ function getParameter( parameter: string | string[] ): string {
* @throws Throws an error message if the string is in an invalid format and cannot be parsed.
*/
function parsePWS( pwsString: string): PWS {
const match = pwsString.match( /^pws:(?<apiKey>[a-f\d]{32})@(?<id>[a-zA-Z\d]+)$/ );
const match = pwsString.match( /^pws:([a-f\d]{32})@([a-zA-Z\d]+)$/ );
if ( !match ) {
throw "Invalid PWS format.";
}
return match.groups as PWS;
return {
apiKey: match[ 1 ],
id: match[ 2 ]
};
}