Skip to content

ndxbxrme/objtrans

Repository files navigation

objtrans

transform a javascript object

similar to js-object-transform but works a bit differently

install with
npm install --save objtrans
or
bower install --save objtrans

##example

user =
  name: 'jimmy'
  emails: [
    'jam@jam.com'
    'jef@jef.com'
    'zam@zam.com'
  ]
  local:
    email: 'jim@jim.com'
    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": "jam@jam.com",
  "firstname": "JIM",
  "lastname": "smith",
  "details": {
    "fullname": "Jim Smith"
  }
}
###

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published