@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
30 lines (29 loc) • 790 B
JavaScript
import { isNodeOfType } from 'eslint-codemod-utils';
import { getValue } from './get-value';
/**
* @example
* ```js
* `2 ${variable} 0`
*
* // results in [2, NaN, 0]
* ```
* ```js
* const variable = 4;
* `2 ${variable} 0`
*
* // results in [2, 4, 0]
* ```
*/
export var getValueFromTemplateLiteralRaw = function getValueFromTemplateLiteralRaw(node, context) {
if (!isNodeOfType(node, "TemplateLiteral")) {
return null;
}
var combinedString = node.quasis.map(function (q, i) {
return "".concat(q.value.raw).concat(node.expressions[i] ? getValue(node.expressions[i], context) : '');
}).join('').trim();
var fontFamily = /(sans-serif$)|(monospace$)/;
if (fontFamily.test(combinedString)) {
return combinedString;
}
return combinedString.split(' ');
};