jsedn
Version:
js implementation of edn
100 lines (77 loc) • 2.44 kB
JavaScript
// Generated by CoffeeScript 1.6.1
(function() {
var Prim, Tag, Tagged, tagActions, type,
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Prim = require("./atoms").Prim;
type = require("./type");
Tag = (function() {
function Tag() {
var name, namespace, _ref;
namespace = arguments[0], name = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
this.namespace = namespace;
this.name = name;
if (arguments.length === 1) {
_ref = arguments[0].split('/'), this.namespace = _ref[0], this.name = 2 <= _ref.length ? __slice.call(_ref, 1) : [];
}
}
Tag.prototype.ns = function() {
return this.namespace;
};
Tag.prototype.dn = function() {
return [this.namespace].concat(this.name).join('/');
};
return Tag;
})();
Tagged = (function(_super) {
__extends(Tagged, _super);
function Tagged(_tag, _obj) {
this._tag = _tag;
this._obj = _obj;
}
Tagged.prototype.jsEncode = function() {
return {
tag: this.tag().dn(),
value: this.obj().jsEncode()
};
};
Tagged.prototype.ednEncode = function() {
return "\#" + (this.tag().dn()) + " " + (require("./encode").encode(this.obj()));
};
Tagged.prototype.jsonEncode = function() {
return {
Tagged: [this.tag().dn(), this.obj().jsonEncode != null ? this.obj().jsonEncode() : this.obj()]
};
};
Tagged.prototype.tag = function() {
return this._tag;
};
Tagged.prototype.obj = function() {
return this._obj;
};
Tagged.prototype.walk = function(iter) {
return new Tagged(this._tag, type(this._obj.walk) === "function" ? this._obj.walk(iter) : iter(this._obj));
};
return Tagged;
})(Prim);
tagActions = {
uuid: {
tag: new Tag("uuid"),
action: function(obj) {
return obj;
}
},
inst: {
tag: new Tag("inst"),
action: function(obj) {
return new Date(Date.parse(obj));
}
}
};
module.exports = {
Tag: Tag,
Tagged: Tagged,
tagActions: tagActions
};
}).call(this);