UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

33 lines (32 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getObjectLikeness = void 0; var _eslintCodemodUtils = require("eslint-codemod-utils"); var _countMatchingKeyValues = require("./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. */ var getObjectLikeness = exports.getObjectLikeness = function getObjectLikeness(node) { var styleEntries = node.properties.filter(function (node) { return (0, _eslintCodemodUtils.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 (0, _countMatchingKeyValues.countMatchingKeyValues)(styleEntries); };