postcss-normalize-positions 5.0.2 → 5.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +18 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11,16 +11,11 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
11
11
 
12
12
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
13
 
14
- const directionKeywords = ['top', 'right', 'bottom', 'left', 'center'];
14
+ const directionKeywords = new Set(['top', 'right', 'bottom', 'left', 'center']);
15
15
  const center = '50%';
16
- const horizontal = {
17
- right: '100%',
18
- left: '0'
19
- };
20
- const verticalValue = {
21
- bottom: '100%',
22
- top: '0'
23
- };
16
+ const horizontal = new Map([['right', '100%'], ['left', '0']]);
17
+ const verticalValue = new Map([['bottom', '100%'], ['top', '0']]);
18
+ const mathFunctions = new Set(['calc', 'min', 'max', 'clamp']);
24
19
 
25
20
  function isCommaNode(node) {
26
21
  return node.type === 'div' && node.value === ',';
@@ -39,7 +34,7 @@ function isMathFunctionNode(node) {
39
34
  return false;
40
35
  }
41
36
 
42
- return ['calc', 'min', 'max', 'clamp'].includes(node.value.toLowerCase());
37
+ return mathFunctions.has(node.value.toLowerCase());
43
38
  }
44
39
 
45
40
  function isNumberNode(node) {
@@ -104,7 +99,7 @@ function transform(value) {
104
99
  return;
105
100
  }
106
101
 
107
- const isPositionKeyword = node.type === 'word' && directionKeywords.includes(node.value.toLowerCase()) || isDimensionNode(node) || isNumberNode(node) || isMathFunctionNode(node);
102
+ const isPositionKeyword = node.type === 'word' && directionKeywords.has(node.value.toLowerCase()) || isDimensionNode(node) || isNumberNode(node) || isMathFunctionNode(node);
108
103
 
109
104
  if (ranges[rangeIndex].start === null && isPositionKeyword) {
110
105
  ranges[rangeIndex].start = index;
@@ -142,34 +137,32 @@ function transform(value) {
142
137
  nodes[2].value = nodes[1].value = '';
143
138
  }
144
139
 
145
- const map = Object.assign({}, horizontal, {
146
- center
147
- });
140
+ const map = new Map([...horizontal, ['center', center]]);
148
141
 
149
- if (Object.prototype.hasOwnProperty.call(map, firstNode)) {
150
- nodes[0].value = map[firstNode];
142
+ if (map.has(firstNode)) {
143
+ nodes[0].value = map.get(firstNode);
151
144
  }
152
145
 
153
146
  return;
154
147
  }
155
148
 
156
- if (firstNode === 'center' && directionKeywords.includes(secondNode)) {
149
+ if (firstNode === 'center' && directionKeywords.has(secondNode)) {
157
150
  nodes[0].value = nodes[1].value = '';
158
151
 
159
- if (Object.prototype.hasOwnProperty.call(horizontal, secondNode)) {
160
- nodes[2].value = horizontal[secondNode];
152
+ if (horizontal.has(secondNode)) {
153
+ nodes[2].value = horizontal.get(secondNode);
161
154
  }
162
155
 
163
156
  return;
164
157
  }
165
158
 
166
- if (Object.prototype.hasOwnProperty.call(horizontal, firstNode) && Object.prototype.hasOwnProperty.call(verticalValue, secondNode)) {
167
- nodes[0].value = horizontal[firstNode];
168
- nodes[2].value = verticalValue[secondNode];
159
+ if (horizontal.has(firstNode) && verticalValue.has(secondNode)) {
160
+ nodes[0].value = horizontal.get(firstNode);
161
+ nodes[2].value = verticalValue.get(secondNode);
169
162
  return;
170
- } else if (Object.prototype.hasOwnProperty.call(verticalValue, firstNode) && Object.prototype.hasOwnProperty.call(horizontal, secondNode)) {
171
- nodes[0].value = horizontal[secondNode];
172
- nodes[2].value = verticalValue[firstNode];
163
+ } else if (verticalValue.has(firstNode) && horizontal.has(secondNode)) {
164
+ nodes[0].value = horizontal.get(secondNode);
165
+ nodes[2].value = verticalValue.get(firstNode);
173
166
  return;
174
167
  }
175
168
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-normalize-positions",
3
- "version": "5.0.2",
3
+ "version": "5.0.3",
4
4
  "description": "Normalize keyword values for position into length values.",
5
5
  "main": "dist/index.js",
6
6
  "files": [