/** * 过滤出带prefix的属性 * @param {Object} holdProps 过滤的参照对象,最终的结果只保留不在参照对象中的key * @param {string} prefix 包含的字符串 * @return {Object} others * * @example * object.pickAttrsWith(FooComponent.propTypes, 'data-'); */ export function pickAttrsWith( holdProps: { [x: string]: unknown }, prefix: { [Symbol.match]: (string: string) => RegExpMatchArray | null }, ) { const others: { [x: string]: unknown } = {}; for (const key in holdProps) { if (key.match(prefix)) { others[key] = holdProps[key]; } } return others; }