UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

24 lines 784 B
import { isNodeOfType } from 'eslint-codemod-utils'; import { countMatchingKeyValues } from './count-matching-key-values'; /** * Given a node, translate the node into css key-value pairs and * compare the output to the reference styles required to make a * visually hidden element. * * @returns {number} A fraction between 0-1 depending on the object's likeness. */ export const getObjectLikeness = node => { const styleEntries = node.properties.filter(node => isNodeOfType(node, 'Property')).map(({ key, value }) => { if (key.type === 'Identifier') { return { key: key.name, value: value.type === 'Literal' && value.value }; } return null; }).filter(node => Boolean(node)); return countMatchingKeyValues(styleEntries); };