Skip to content

Instantly share code, notes, and snippets.

@luk-
Created October 30, 2011 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luk-/1325646 to your computer and use it in GitHub Desktop.
Save luk-/1325646 to your computer and use it in GitHub Desktop.
Small script used to convert text list of JS events to JSON
fs = require('fs');
var file;
var obj = new Object;
fs.readFile('events.txt', 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
file = data.split("\n");
for (i in file) {
var arr = file[i].split(' ');
var localObj = {
name: arr[0],
bubbles: arr[1],
cancel: arr[2]
};
obj[localObj.name] = {
bubbles: localObj.bubbles,
cancel: localObj.cancel
};
}
console.log(JSON.stringify(obj));
});
@luk-
Copy link
Author

luk- commented Oct 30, 2011

Text file was formatted like:

beforeunload no yes
blur no no
change no yes

etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment