UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

27 lines 893 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 var getObjectLikeness = function getObjectLikeness(node) { var styleEntries = node.properties.filter(function (node) { return isNodeOfType(node, 'Property'); }).map(function (_ref) { var key = _ref.key, value = _ref.value; if (key.type === 'Identifier') { return { key: key.name, value: value.type === 'Literal' && value.value }; } return null; }).filter(function (node) { return Boolean(node); }); return countMatchingKeyValues(styleEntries); };