Last active
April 13, 2017 20:09
-
-
Save nicklozon/fa260e5cbff28b94ea7963457c12b493 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mapSchema = require('./index.js'); | |
// Basic example | |
var params = {'noise': 'Meow!'}; | |
var schema = {'makeNoise': function(p) { return p.noise; }}; | |
mapSchema(schema, params, function(ret) { | |
console.log(ret); //{ makeNoise: 'Meow!' } | |
}); | |
// Nested example | |
params = {'noiseCat': 'Meow!', 'noiseDog': 'Woof!'}; | |
schema = { | |
'makeNoises': { | |
'cat': function(p) { return p.noiseCat; }, | |
'dog': function(p) { return p.noiseDog; } | |
} | |
}; | |
mapSchema(schema, params, function(ret) { | |
console.log(ret); //{ makeNoises: { cat: 'Meow!', dog: 'Woof!' } } | |
}); | |
// Undefined example | |
params = {'isCat': true, 'noiseCat': 'Meow!', 'isDog': false, 'noiseDog': 'Woof!'}; | |
schema = { | |
'makeNoises': { | |
'cat': function(p) { if(p.isCat) return p.noiseCat; }, | |
'dog': function(p) { if(p.isDog) return p.noiseDog; }, | |
} | |
}; | |
mapSchema(schema, params, function(ret) { | |
console.log(ret); //{ makeNoises: { cat: 'Meow!' } } | |
}); | |
// Static example | |
params = {'isCat': true, 'noiseCat': 'Meow!'}; | |
schema = { | |
'makeNoises': { | |
'cat': function(p) { if(p.isCat) return p.noiseCat; }, | |
'dog': "Meow! I mean, Woof!" | |
} | |
}; | |
mapSchema(schema, params, function(ret) { | |
console.log(ret); //{ makeNoises: { cat: 'Meow!', dog: 'Meow! I mean, Woof!' } } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment