@salesforce-ux/eslint-plugin-slds
Version:
ESLint plugin provides custom linting rules specifically built for Salesforce Lightning Design System 2 (SLDS 2 beta)
71 lines (69 loc) • 2.38 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/utils/value-utils.ts
var value_utils_exports = {};
__export(value_utils_exports, {
ALLOWED_UNITS: () => ALLOWED_UNITS,
isGlobalValue: () => isGlobalValue,
parseUnitValue: () => parseUnitValue,
toAlternateUnitValue: () => toAlternateUnitValue
});
module.exports = __toCommonJS(value_utils_exports);
function isGlobalValue(value) {
return value === "initial" || value === "inherit" || value === "unset" || value === "revert" || value === "revert-layer";
}
var ALLOWED_UNITS = ["px", "em", "rem", "%", "ch"];
function parseUnitValue(value) {
if (!value) return null;
const unitsPattern = ALLOWED_UNITS.join("|");
const regex = new RegExp(`^(-?\\d*\\.?\\d+)(${unitsPattern})?$`);
const match = value.match(regex);
if (!match) return null;
const number = parseFloat(match[1]);
const unit = match[2] ? match[2] : null;
if (isNaN(number)) return null;
return { number, unit };
}
function toAlternateUnitValue(numberVal, unitType) {
if (unitType === "px") {
let floatValue = parseFloat(`${numberVal / 16}`);
if (!isNaN(floatValue)) {
return {
unit: "rem",
number: parseFloat(floatValue.toFixed(4))
};
}
} else if (unitType === "rem") {
const intValue = parseInt(`${numberVal * 16}`);
if (!isNaN(intValue)) {
return {
unit: "px",
number: intValue
};
}
}
return null;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ALLOWED_UNITS,
isGlobalValue,
parseUnitValue,
toAlternateUnitValue
});
//# sourceMappingURL=value-utils.js.map