lightning-client-utils
Advanced tools
Comparing version 0.1.1 to 0.2.0
46
index.js
var _ = require('lodash'); | ||
var request = require('superagent'); | ||
var r; | ||
@@ -37,2 +39,46 @@ var utils = { | ||
return retColors; | ||
}, | ||
isEditorOrPreview: function() { | ||
var url = document.URL; | ||
return /https?:\/\/[^\/]+\/visualization-types\/*/.test(url); | ||
}, | ||
fetchData: function(viz, keys, cb) { | ||
if(this.isEditorOrPreview()) { | ||
setTimeout(function() { | ||
var data = $('#data-editor').next('.CodeMirror').find('.CodeMirror-code span')[0].innerHTML; | ||
var fetchedData = JSON.parse(data); | ||
_.each(keys, function(key) { | ||
fetchedData = fetchedData[key]; | ||
}); | ||
cb(null, fetchedData); | ||
}, 0); | ||
} else { | ||
var url = viz.$el.parent().find('.permalink').find('a').attr('href'); | ||
if(r) { | ||
r.abort(); | ||
} | ||
r = request.get(url + '/data/' + keys.join('/'), function(err, res) { | ||
if(err) { | ||
return cb(err) | ||
} | ||
cb(null, (res.body || {}).data); | ||
}); | ||
} | ||
} | ||
@@ -39,0 +85,0 @@ |
{ | ||
"name": "lightning-client-utils", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "utilities for lightning visualizations to be used in the browser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
4229
58
0