index.js
12 lines
| 1 | /** |
| 2 | * Given an attributes object will return only the allowed attributes |
| 3 | * |
| 4 | * @param {Object} attributes Full block attributes |
| 5 | * @param {Array} allowedKeys The allowed attributes |
| 6 | * @return {Object} The filtered attributes object |
| 7 | */ |
| 8 | export default ( attributes, allowedKeys = [] ) => Object |
| 9 | .keys( attributes ) |
| 10 | .filter( ( key ) => allowedKeys.includes( key ) ) |
| 11 | .reduce( ( result, key ) => Object.assign( {}, result, { [ key ]: attributes[ key ] } ), {} ); |
| 12 |