rn-css 1.8.13 → 1.8.14

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.
@@ -1,12 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cornerValue = exports.sideValue = exports.font = exports.transform = exports.textDecoration = exports.background = exports.placeContent = exports.flexFlow = exports.flex = exports.shadow = exports.borderLike = exports.border = void 0;
4
- /** Check if the value is a number. Numbers start with a digit, a decimal point or calc(, max( ou min( */
5
- function isNumber(value) {
4
+ /**
5
+ * Check if the value is a number. Numbers start with a digit, a decimal point or calc(, max( ou min(.
6
+ * Optionally accept "auto" value (for margins)
7
+ * @param value The value to check
8
+ * @param acceptAuto true if auto is an accepted value
9
+ * @returns true if the value is a number
10
+ */
11
+ function isNumber(value, acceptAuto) {
12
+ if (acceptAuto && value === 'auto')
13
+ return true;
6
14
  return value.match(/^[+-]?(\.\d|\d|calc\(|max\(|min\()/mg);
7
15
  }
8
- /** Split the value into numbers values and non numbers values */
9
- function findNumbers(value) {
16
+ /**
17
+ * Check if the value is a number. Numbers start with a digit, a decimal point or calc(, max( ou min(.
18
+ * Optionally accept "auto" value (for margins)
19
+ * @param value The value to check
20
+ * @param acceptAuto true if auto is an accepted value
21
+ * @returns true if the value is a number
22
+ */
23
+ /**
24
+ * Split the value into numbers values and non numbers values
25
+ * @param value The value to check
26
+ * @param acceptAuto true if auto is an accepted value
27
+ * @returns An object containing the number and non number values as arrays.
28
+ */
29
+ function findNumbers(value, acceptAuto) {
10
30
  const result = {
11
31
  nonNumbers: [],
12
32
  numbers: []
@@ -21,7 +41,7 @@ function findNumbers(value) {
21
41
  if (group)
22
42
  result.nonNumbers.push(val);
23
43
  else
24
- result[isNumber(val) ? 'numbers' : 'nonNumbers'].push(val);
44
+ result[isNumber(val, acceptAuto) ? 'numbers' : 'nonNumbers'].push(val);
25
45
  });
26
46
  return result;
27
47
  }
@@ -219,7 +239,7 @@ exports.font = font;
219
239
  function sideValue(prefixKey, value, postFix = '') {
220
240
  if (value === 'none')
221
241
  return sideValue(prefixKey, '0', postFix);
222
- const [top = value, right = top, bottom = top, left = right] = findNumbers(value).numbers;
242
+ const [top = value, right = top, bottom = top, left = right] = findNumbers(value, prefixKey === 'margin').numbers;
223
243
  return {
224
244
  [prefixKey + 'Top' + postFix]: top,
225
245
  [prefixKey + 'Left' + postFix]: left,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-css",
3
- "version": "1.8.13",
3
+ "version": "1.8.14",
4
4
  "scripts": {
5
5
  "test": "jest",
6
6
  "prepare": "tsc",
@@ -1,12 +1,31 @@
1
1
  import type { Style, Transform } from '../types'
2
2
 
3
- /** Check if the value is a number. Numbers start with a digit, a decimal point or calc(, max( ou min( */
4
- function isNumber (value: string) {
3
+ /**
4
+ * Check if the value is a number. Numbers start with a digit, a decimal point or calc(, max( ou min(.
5
+ * Optionally accept "auto" value (for margins)
6
+ * @param value The value to check
7
+ * @param acceptAuto true if auto is an accepted value
8
+ * @returns true if the value is a number
9
+ */
10
+ function isNumber (value: string, acceptAuto?: boolean) {
11
+ if (acceptAuto && value === 'auto') return true
5
12
  return value.match(/^[+-]?(\.\d|\d|calc\(|max\(|min\()/mg)
6
13
  }
7
14
 
8
- /** Split the value into numbers values and non numbers values */
9
- function findNumbers (value: string) {
15
+ /**
16
+ * Check if the value is a number. Numbers start with a digit, a decimal point or calc(, max( ou min(.
17
+ * Optionally accept "auto" value (for margins)
18
+ * @param value The value to check
19
+ * @param acceptAuto true if auto is an accepted value
20
+ * @returns true if the value is a number
21
+ */
22
+ /**
23
+ * Split the value into numbers values and non numbers values
24
+ * @param value The value to check
25
+ * @param acceptAuto true if auto is an accepted value
26
+ * @returns An object containing the number and non number values as arrays.
27
+ */
28
+ function findNumbers (value: string, acceptAuto?: boolean) {
10
29
  const result = {
11
30
  nonNumbers: [] as string[],
12
31
  numbers: [] as string[]
@@ -17,7 +36,7 @@ function findNumbers (value: string) {
17
36
  if (val.startsWith('"') || val.startsWith("'")) group = val.charAt(0)
18
37
  if (group && val.endsWith(group)) group = ''
19
38
  if (group) result.nonNumbers.push(val)
20
- else result[isNumber(val) ? 'numbers' : 'nonNumbers'].push(val)
39
+ else result[isNumber(val, acceptAuto) ? 'numbers' : 'nonNumbers'].push(val)
21
40
  })
22
41
  return result
23
42
  }
@@ -188,7 +207,7 @@ export function font (value: string) {
188
207
  /** Parses a css value for the side of an element (border-width, margin, padding) */
189
208
  export function sideValue <T extends 'padding' | 'margin' | 'border'> (prefixKey: T, value: string, postFix: T extends 'border' ? 'Width' | 'Style' | 'Color' | '' : '' = ''): { [x: string]: string} {
190
209
  if (value === 'none') return sideValue(prefixKey, '0', postFix)
191
- const [top = value, right = top, bottom = top, left = right] = findNumbers(value).numbers
210
+ const [top = value, right = top, bottom = top, left = right] = findNumbers(value, prefixKey === 'margin').numbers
192
211
  return {
193
212
  [prefixKey + 'Top' + postFix]: top,
194
213
  [prefixKey + 'Left' + postFix]: left,