@panneau/display-unit 3.0.223 → 3.0.224

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/package.json +8 -5
  2. package/lib/index.js +0 -128
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/display-unit",
3
- "version": "3.0.223",
3
+ "version": "3.0.224",
4
4
  "description": "Unit display",
5
5
  "keywords": [
6
6
  "javascript"
@@ -25,8 +25,11 @@
25
25
  }
26
26
  ],
27
27
  "license": "ISC",
28
- "main": "lib/index.js",
28
+ "type": "module",
29
29
  "module": "es/index.js",
30
+ "exports": {
31
+ ".": "./es/index.js"
32
+ },
30
33
  "files": [
31
34
  "lib",
32
35
  "es",
@@ -46,8 +49,8 @@
46
49
  },
47
50
  "dependencies": {
48
51
  "@babel/runtime": "^7.12.5",
49
- "@panneau/core": "^3.0.223",
50
- "@panneau/themes": "^3.0.223",
52
+ "@panneau/core": "^3.0.224",
53
+ "@panneau/themes": "^3.0.224",
51
54
  "lodash": "^4.17.21",
52
55
  "pretty-bytes": "^6.1.1",
53
56
  "prop-types": "^15.7.2",
@@ -56,5 +59,5 @@
56
59
  "publishConfig": {
57
60
  "access": "public"
58
61
  },
59
- "gitHead": "14196bd955b0e44cbc214e00f3189b3216f3fa53"
62
+ "gitHead": "c95bd465867c4c7d112bf0ed66036574cc05c627"
60
63
  }
package/lib/index.js DELETED
@@ -1,128 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var isObject = require('lodash/isObject');
6
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
7
- var _typeof = require('@babel/runtime/helpers/typeof');
8
- var PropTypes = require('prop-types');
9
- var React = require('react');
10
- var utils = require('@panneau/core/utils');
11
-
12
- var BYTE_UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
13
- var BIBYTE_UNITS = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
14
- var BIT_UNITS = ['b', 'kbit', 'Mbit', 'Gbit', 'Tbit', 'Pbit', 'Ebit', 'Zbit', 'Ybit'];
15
- var BIBIT_UNITS = ['b', 'kibit', 'Mibit', 'Gibit', 'Tibit', 'Pibit', 'Eibit', 'Zibit', 'Yibit'];
16
-
17
- /*
18
- Formats the given number using `Number#toLocaleString`.
19
- - If locale is a string, the value is expected to be a locale-key (for example: `de`).
20
- - If locale is true, the system default locale is used for translation.
21
- - If no value for locale is specified, the number is returned unmodified.
22
- */
23
- var toLocaleString = function toLocaleString(number, locale, options) {
24
- var result = number;
25
- if (typeof locale === 'string' || Array.isArray(locale)) {
26
- result = number.toLocaleString(locale, options);
27
- } else if (locale === true || options !== undefined) {
28
- result = number.toLocaleString(undefined, options);
29
- }
30
- return result;
31
- };
32
- function prettyBytes(number, options) {
33
- if (!Number.isFinite(number)) {
34
- throw new TypeError("Expected a finite number, got ".concat(_typeof(number), ": ").concat(number));
35
- }
36
- options = _objectSpread({
37
- bits: false,
38
- binary: false,
39
- space: true
40
- }, options);
41
- var UNITS = options.bits ? options.binary ? BIBIT_UNITS : BIT_UNITS : options.binary ? BIBYTE_UNITS : BYTE_UNITS;
42
- var separator = options.space ? ' ' : '';
43
- if (options.signed && number === 0) {
44
- return " 0".concat(separator).concat(UNITS[0]);
45
- }
46
- var isNegative = number < 0;
47
- var prefix = isNegative ? '-' : options.signed ? '+' : '';
48
- if (isNegative) {
49
- number = -number;
50
- }
51
- var localeOptions;
52
- if (options.minimumFractionDigits !== undefined) {
53
- localeOptions = {
54
- minimumFractionDigits: options.minimumFractionDigits
55
- };
56
- }
57
- if (options.maximumFractionDigits !== undefined) {
58
- localeOptions = _objectSpread({
59
- maximumFractionDigits: options.maximumFractionDigits
60
- }, localeOptions);
61
- }
62
- if (number < 1) {
63
- var _numberString = toLocaleString(number, options.locale, localeOptions);
64
- return prefix + _numberString + separator + UNITS[0];
65
- }
66
- var exponent = Math.min(Math.floor(options.binary ? Math.log(number) / Math.log(1024) : Math.log10(number) / 3), UNITS.length - 1);
67
- number /= Math.pow(options.binary ? 1024 : 1000, exponent);
68
- if (!localeOptions) {
69
- number = number.toPrecision(3);
70
- }
71
- var numberString = toLocaleString(Number(number), options.locale, localeOptions);
72
- var unit = UNITS[exponent];
73
- return prefix + numberString + separator + unit;
74
- }
75
-
76
- /* eslint-disable react/jsx-no-useless-fragment */
77
- var propTypes = {
78
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.object]),
79
- placeholder: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
80
- format: PropTypes.string,
81
- suffix: PropTypes.string
82
- };
83
- var defaultProps = {
84
- value: null,
85
- placeholder: null,
86
- format: null,
87
- suffix: null
88
- };
89
- var Unit = function Unit(_ref) {
90
- var value = _ref.value,
91
- placeholder = _ref.placeholder,
92
- format = _ref.format,
93
- suffix = _ref.suffix;
94
- var finalValue = React.useMemo(function () {
95
- if (value === null) {
96
- return null;
97
- }
98
- if (format === 'bytes' && !isObject(value)) {
99
- return prettyBytes(parseInt(value, 10));
100
- }
101
- if (format === 'dimensions') {
102
- var _ref2 = value || {},
103
- _ref2$width = _ref2.width,
104
- width = _ref2$width === void 0 ? null : _ref2$width,
105
- _ref2$height = _ref2.height,
106
- height = _ref2$height === void 0 ? null : _ref2$height,
107
- _ref2$depth = _ref2.depth,
108
- depth = _ref2$depth === void 0 ? null : _ref2$depth;
109
- var finalWidth = width !== null && width > 0 ? width : null;
110
- var finalHeight = height !== null && height > 0 ? height : null;
111
- var finalDepth = depth !== null && depth > 0 ? depth : null;
112
- var finalSuffix = suffix !== null ? suffix : '';
113
- return "".concat(finalWidth !== null ? "".concat(finalWidth).concat(finalSuffix) : '').concat(finalHeight !== null ? " x ".concat(finalHeight).concat(finalSuffix) : '').concat(finalDepth !== null ? " x ".concat(finalDepth).concat(finalSuffix) : '');
114
- }
115
- if (format === 'duration') {
116
- return utils.formatDuration(value);
117
- }
118
- return value;
119
- }, [value]);
120
- return /*#__PURE__*/React.createElement("span", {
121
- className: "text-nowrap"
122
- }, finalValue || placeholder);
123
- };
124
- Unit.propTypes = propTypes;
125
- Unit.defaultProps = defaultProps;
126
- var Unit$1 = Unit;
127
-
128
- exports.default = Unit$1;