wix-style-react
Version:
23 lines (21 loc) • 726 B
JavaScript
import { filterObject } from './filterObject';
/**
* a generic utility to get a subset of the received props object according to the prefix of the prop name
* @param props
* @param prefix
* @return {any}
*/
export var extractAttributes = function extractAttributes(props) {
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
return filterObject(props, function (key) {
return key.length >= prefix.length && key.indexOf(prefix) === 0;
});
};
/**
* Returns a subset of the received props object that starts with "data-"
* @param props
* @return {*}
*/
export var extractDataAttributes = function extractDataAttributes(props) {
return extractAttributes(props, 'data-');
};