luda
Version:
A library helps to build cross-framework UI components.
29 lines (25 loc) • 849 B
text/coffeescript
import luda from '../base/luda.coffee'
import readValue from '../base/read-value.coffee'
import parseValue from '../base/parse-value.coffee'
import Type from '../base/type.coffee'
import './remove-data.coffee'
import parseName from './helpers/parse-name.coffee'
luda.include
data: (name, value) ->
unless name
return unless [0]
datas = {}
datas[key] = readValue val for key, val of [0].dataset
return datas
if Type.isString name
name = parseName name
if arguments.length >= 2
return this if value is undefined
return name if value is null
val = parseValue value
.forEach (el) -> el.dataset[name] = val
return this
return unless [0]
return readValue [0].dataset[name]
key, val for key, val of name
this