cryptpad/www/common/convert.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

define([
'/common/hyperjson.js',
'/common/hyperscript.js'
2016-03-03 14:12:43 +00:00
], function (hyperjson, hyperscript) {
// complain if you don't find the required APIs
2016-03-03 14:12:43 +00:00
if (!(hyperjson && hyperscript)) { throw new Error(); }
// Generate a matrix of conversions
/*
convert.dom.to.hjson, convert.hjson.to.dom,
convert.dom.to.vdom, convert.vdom.to.dom,
and of course, identify functions in case you try to
convert a datatype to itself
*/
var convert = (function () {
var Self = function (x) {
return x;
},
methods = {
dom:{
dom: Self,
hjson: hyperjson.fromDOM
},
hjson:{
hjson: Self,
dom: function (H) {
// hyperjson.fromDOM,
return hyperjson.callOn(H, hyperscript);
}
}
2016-03-03 14:12:43 +00:00
},
convert = {};
Object.keys(methods).forEach(function (method) {
convert[method] = { to: methods[method] };
});
return convert;
}());
2016-01-27 09:10:47 +00:00
convert.core = {
hyperjson: hyperjson,
hyperscript: hyperscript
};
return convert;
});