jsedn
Version:
js implementation of edn
35 lines (24 loc) • 870 B
text/coffeescript
{Prim} = require "./atoms"
type = require "./type"
class Tag
constructor: (, ...) ->
if arguments.length is 1
[, ...] = arguments[0].split('/')
ns: ->
dn: -> [].concat().join('/')
class Tagged extends Prim
constructor: (, ) ->
jsEncode: ->
tag: .dn(), value: .jsEncode()
ednEncode: ->
"\##{@tag().dn()} #{require("./encode").encode @obj()}"
jsonEncode: ->
Tagged: [.dn(), if .jsonEncode? then .jsonEncode() else ]
tag: ->
obj: ->
walk: (iter) ->
new Tagged , if type(.walk) is "function" then .walk iter else iter
tagActions =
uuid: tag: (new Tag "uuid"), action: (obj) -> obj
inst: tag: (new Tag "inst"), action: (obj) -> new Date Date.parse obj
module.exports = {Tag, Tagged, tagActions}