fontWeight.js 852 B

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. const parsers = require("../parsers");
  3. module.exports.parse = function parse(v) {
  4. const num = parsers.parseNumber(v, true);
  5. if (num && parseFloat(num) <= 1000) {
  6. return num;
  7. }
  8. const keywords = ["normal", "bold", "lighter", "bolder"];
  9. return parsers.parseKeyword(v, keywords);
  10. };
  11. module.exports.isValid = function isValid(v) {
  12. if (v === "") {
  13. return true;
  14. }
  15. return typeof module.exports.parse(v) === "string";
  16. };
  17. module.exports.definition = {
  18. set(v) {
  19. v = parsers.prepareValue(v, this._global);
  20. if (parsers.hasVarFunc(v)) {
  21. this._setProperty("font", "");
  22. this._setProperty("font-weight", v);
  23. } else {
  24. this._setProperty("font-weight", module.exports.parse(v));
  25. }
  26. },
  27. get() {
  28. return this.getPropertyValue("font-weight");
  29. },
  30. enumerable: true,
  31. configurable: true
  32. };