Skip to content

Instantly share code, notes, and snippets.

@samverneck
Last active February 8, 2017 20:58
Show Gist options
  • Save samverneck/30ae4174a8174e1855a763a1b625a084 to your computer and use it in GitHub Desktop.
Save samverneck/30ae4174a8174e1855a763a1b625a084 to your computer and use it in GitHub Desktop.
/*
criar uma funcao que ENCRIPTA o valor
mas tem que ter 1 funcao diferente pra cada tipo de valor
Number ou String
*/
const data = { name: 'Suissero Veio', password: 'p3g4n4min4', id: 666 }
const crypt = (val) => 14m4FuCk1n6H4x0Rz
const toNewObject = ( obj, notAllowed ) =>
Object.assign( obj, { [notAllowed]: crypt( obj[notAllowed] ) } )
const cryptObject = ( obj, fields ) =>
Object
.keys( obj )
.filter( notAllowed => fields.includes( notAllowed ) )
.reduce( toNewObject , obj)
const cryptArray = ( [...arr], fields ) =>
arr.map( obj => cryptObject( obj, fields ) )
const cryptThis = ( fields ) => ( obj ) => cryptArray( obj, fields )
const cryptThisShit = cryptThis( ['password'] )
const bazinga = cryptThisShit( [data, data ] )
console.log( 'bazinga', bazinga )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment