UNPKG

1.36 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _endsWith = _interopRequireDefault(require("./_endsWith"));
6var _stripUnit = _interopRequireDefault(require("../helpers/stripUnit"));
7var _errors = _interopRequireDefault(require("./_errors"));
8function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9/**
10 * Factory function that creates pixel-to-x converters
11 * @private
12 */
13var pxtoFactory = function pxtoFactory(to) {
14 return function (pxval, base) {
15 if (base === void 0) {
16 base = '16px';
17 }
18 var newPxval = pxval;
19 var newBase = base;
20 if (typeof pxval === 'string') {
21 if (!(0, _endsWith["default"])(pxval, 'px')) {
22 throw new _errors["default"](69, to, pxval);
23 }
24 newPxval = (0, _stripUnit["default"])(pxval);
25 }
26 if (typeof base === 'string') {
27 if (!(0, _endsWith["default"])(base, 'px')) {
28 throw new _errors["default"](70, to, base);
29 }
30 newBase = (0, _stripUnit["default"])(base);
31 }
32 if (typeof newPxval === 'string') {
33 throw new _errors["default"](71, pxval, to);
34 }
35 if (typeof newBase === 'string') {
36 throw new _errors["default"](72, base, to);
37 }
38 return "" + newPxval / newBase + to;
39 };
40};
41var _default = exports["default"] = pxtoFactory;
42module.exports = exports.default;
\No newline at end of file