get-options.js 528 B

1234567891011121314151617181920
  1. // given an input that may or may not be an object, return an object that has
  2. // a copy of every defined property listed in 'copy'. if the input is not an
  3. // object, assign it to the property named by 'wrap'
  4. const getOptions = (input, { copy, wrap }) => {
  5. const result = {}
  6. if (input && typeof input === 'object') {
  7. for (const prop of copy) {
  8. if (input[prop] !== undefined) {
  9. result[prop] = input[prop]
  10. }
  11. }
  12. } else {
  13. result[wrap] = input
  14. }
  15. return result
  16. }
  17. module.exports = getOptions