You need to state the name and full version number of the story format you are using, as answers can be different for each one. I will assume you are using the default version of Harlowe which is currently 1.2.4
Based on your question I understand you already know the following information, I am only including it here for the sake of anyone else reading this thread.
The developer of the Harlowe story format (1.x and 2.x) has deliberately designed and implemented it in such a way to restrict access to it's engine's internals using Javascript, and the story format currently has no Javascript API documentation.
You stated that you are willing to "map" Javascript variables to story format variables, the following example demonstrates that this can be done in a single direction.
note: The following Javascript example is not meant to demonstrate the best way to implement a namespace nor best practices in coding in Javascript, it was just quickly put together to show that something was possible.
1. Javascript used to define some variables with different data-types, this code would be placed in the story's Story Javascript area.
if (! window.GE) {
window.GE = {};
}
GE.someString = "A Sting";
GE.someNumber = 123;
GE.someArray = ["A", "B", "C"];
GE.someMap = new Map();
GE.someMap.set("name", "aaaa");
GE.someMap.set("health", 20);
2. TwineScript used within a passage to assign the values of Javascript based variables into story variables, it demonstrates both the different syntax's that can be used to access the Javascript variables as well as that Harlowe's Array and Datamap features still work.
(set: $string1 to window.GE.someString)string: $string1
(set: $string2 to GE.someString)string: $string2
(set: $string3 to window["GE"]["someString"])string: $string3
(set: $string4 to GE["someString"])string: $string4
(set: $number to GE["someNumber"])number: $number
number X 2: (print: $number * 2)
(set: $array to GE["someArray"])array: $array
array length: (print: $array's length)
first element: (print: $array's 1st)
second element: (print: $array's 2nd)
third element: (print: $array's 3rd)
last element: (print: $array's last)
(set: $map to GE["someMap"])(data)map: (print: $map)
name element: (print: $map's name)
health element: (print: $map's health)