objtrans
v0.0.15
Published
transform an object
Downloads
26
Readme
objtrans
transform a javascript object
similar to js-object-transform but works a bit differently
install withnpm install --save objtrans
orbower install --save objtrans
##example
user =
name: 'jimmy'
emails: [
'[email protected]'
'[email protected]'
'[email protected]'
]
local:
email: '[email protected]'
password: '23goh32fgdf'
firstname: 'Jim'
horrible:
obj:
surname: 'Smith'
pattern =
nameDetails:
name: true
username: 'name'
email: 'emails[first]'
firstname: (input) ->
if input
input.toUpperCase()
lastname: ['horrible.obj.surname', (input) ->
if input
input.toLowerCase()
]
details:
fullname: (input) ->
input.firstname + ' ' + input.horrible.obj.surname
newUser = objtrans user, pattern
console.log newUser
###
{
"nameDetails": {
"name": "jimmy",
"username": "jimmy"
},
"email": "[email protected]",
"firstname": "JIM",
"lastname": "smith",
"details": {
"fullname": "Jim Smith"
}
}
###