packages/extension-map/lib/hashmap_extension.js
/**
 * This function will parse the args string to find the target variable name and 
 * JSON hashmap arguments we'll use for doing the hash mapping.  
 * 
 * @param args a string with the extension arguments
 * 
 * @return an object of format: {const: varname, map: hashmap}
 */
This function will parse the args string to find the target variable name and
JSON hashmap arguments we'll use for doing the hash mapping.

@param args a string with the extension arguments

@return an object of format: {const: varname, map: hashmap}
This function will parse the args string to find the target variable name and JSON hashmap arguments we ' ll use for doing the hash mapping . @param args a string with the extension arguments @return an object of format : { const : varname map : hashmap }
function parseArgs(mapDirective, args) {
    if (args === undefined || args.length === 0) throw Error("Hashmap extension requires a variable name and map as arguments, but found none!");
    const matches = /^[ ]*([\w:<>]+)[ ]*,[ ]*({.*)$/.exec(args);
    if (matches === null || matches.length < 3) throw Error("Hashmap extension requires a variable name and map as arguments, but found: " + mapDirective + "!");
    const varName = matches[1]; 
    const hashString = matches[2];
    let map;
    try { 
        map = JSON.parse(hashString);
        if (Object.keys(map).length === 0) throw Error("Empty hashmap!");
    } catch(e) { 
        throw Error("Hashmap extension unable to parse map in " + mapDirective+"!" + e.message);
    } 
    const values = Object.values(map);
  if (values.length != [...new Set(values)].length) throw Error('Hashmap extension requires unique key/value pairs!');
    return { varName: varName,
             hash: map };
}
function parseArgs ( mapDirective , args ) { if ( args === undefined || args . length === 0 ) throw Error ( "Hashmap extension requires a variable name and map as arguments, but found none!" ) ; const matches = / ^[ ]*([\w:<>]+)[ ]*,[ ]*({.*)$ / . exec ( args ) ; if ( matches === null || matches . length < 3 ) throw Error ( "Hashmap extension requires a variable name and map as arguments, but found: " + mapDirective + "!" ) ; const varName = matches [ 1 ] ; const hashString = matches [ 2 ] ; let map ; try { map = JSON . parse ( hashString ) ; if ( Object . keys ( map ) . length === 0 ) throw Error ( "Empty hashmap!" ) ; } catch ( e ) { throw Error ( "Hashmap extension unable to parse map in " + mapDirective + "!" + e . message ) ; } const values = Object . values ( map ) ; if ( values . length != [ ... new Set ( values ) ] . length ) throw Error ( 'Hashmap extension requires unique key/value pairs!' ) ; return { varName : varName , hash : map } ; }
This function will parse the args string to find the target variable name and
 JSON hashmap arguments we'll use for doing the hash mapping.
This function will parse the args string to find the target variable name and JSON hashmap arguments we ' ll use for doing the hash mapping .
// Do we have anything in args?  // get the variable name and hashmap // Verify that the hash key/value pairs are unique