@commercetools-uikit/utils
Advanced tools
Comparing version 10.42.2 to 10.44.0
# @commercetools-uikit/utils | ||
## 10.44.0 | ||
### Minor Changes | ||
- [`22164a3`](https://github.com/commercetools/ui-kit/commit/22164a34ec0607b778df534378f5cf3f8403f80f) [#1740](https://github.com/commercetools/ui-kit/pull/1740) Thanks [@emmenko](https://github.com/emmenko)! - Migrate utils to TypeScript | ||
## 10.42.2 | ||
@@ -4,0 +10,0 @@ |
@@ -5,12 +5,10 @@ 'use strict'; | ||
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys'); | ||
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray'); | ||
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries'); | ||
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter'); | ||
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce'); | ||
var _defineProperty$1 = require('@babel/runtime-corejs3/helpers/defineProperty'); | ||
var _Object$fromEntries = require('@babel/runtime-corejs3/core-js-stable/object/from-entries'); | ||
var isPropValid = require('@emotion/is-prop-valid'); | ||
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat'); | ||
var warning = require('warning'); | ||
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray'); | ||
var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim'); | ||
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries'); | ||
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each'); | ||
@@ -20,12 +18,10 @@ | ||
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys); | ||
var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray); | ||
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries); | ||
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty); | ||
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty); | ||
var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty$1); | ||
var _Object$fromEntries__default = /*#__PURE__*/_interopDefault(_Object$fromEntries); | ||
var isPropValid__default = /*#__PURE__*/_interopDefault(isPropValid); | ||
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty); | ||
var warning__default = /*#__PURE__*/_interopDefault(warning); | ||
var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray); | ||
var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty); | ||
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries); | ||
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty); | ||
@@ -35,11 +31,10 @@ | ||
function filterDataAttributes(obj) { | ||
var _context, _context2; | ||
var _context; | ||
return _reduceInstanceProperty__default['default'](_context = _filterInstanceProperty__default['default'](_context2 = _Object$keys__default['default'](obj)).call(_context2, function (p) { | ||
return regexpData.test(p); | ||
})).call(_context, function (acc, p) { | ||
// eslint-disable-next-line no-param-reassign | ||
acc[p] = obj[p]; | ||
return acc; | ||
}, {}); | ||
return _Object$fromEntries__default['default'](_filterInstanceProperty__default['default'](_context = _Object$entries__default['default'](obj)).call(_context, function (_ref) { | ||
var _ref2 = _slicedToArray__default['default'](_ref, 1), | ||
propFromEntry = _ref2[0]; | ||
return regexpData.test(propFromEntry); | ||
})); | ||
} | ||
@@ -49,72 +44,23 @@ | ||
function filterAriaAttributes(obj) { | ||
var _context, _context2; | ||
var _context; | ||
return _reduceInstanceProperty__default['default'](_context = _filterInstanceProperty__default['default'](_context2 = _Object$keys__default['default'](obj)).call(_context2, function (p) { | ||
return regexpData$1.test(p); | ||
})).call(_context, function (acc, p) { | ||
// eslint-disable-next-line no-param-reassign | ||
acc[p] = obj[p]; | ||
return acc; | ||
}, {}); | ||
} | ||
return _Object$fromEntries__default['default'](_filterInstanceProperty__default['default'](_context = _Object$entries__default['default'](obj)).call(_context, function (_ref) { | ||
var _ref2 = _slicedToArray__default['default'](_ref, 1), | ||
propFromEntry = _ref2[0]; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
return regexpData$1.test(propFromEntry); | ||
})); | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
function filterInvalidAttributes(obj) { | ||
var _context; | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return _Object$fromEntries__default['default'](_filterInstanceProperty__default['default'](_context = _Object$entries__default['default'](obj)).call(_context, function (_ref) { | ||
var _ref2 = _slicedToArray__default['default'](_ref, 1), | ||
propFromEntry = _ref2[0]; | ||
return keys; | ||
return isPropValid__default['default'](propFromEntry); | ||
})); | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function filterInvalidAttributes(obj) { | ||
var _context, _context2; | ||
return _reduceInstanceProperty__default['default'](_context = _filterInstanceProperty__default['default'](_context2 = _Object$keys__default['default'](obj)).call(_context2, function (prop) { | ||
return isPropValid__default['default'](prop); | ||
})).call(_context, function (acc, prop) { | ||
return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty__default['default']({}, prop, obj[prop])); | ||
}, {}); | ||
} | ||
// Given a string, validates that it has the correct format | ||
@@ -126,3 +72,3 @@ // to be a number, with decimal separators and negative sign. | ||
var warnDeprecatedComponent = (function (componentName) { | ||
function warnDeprecatedComponent(componentName) { | ||
var _context; | ||
@@ -135,11 +81,13 @@ | ||
warning__default['default'](false, message); | ||
}); | ||
} | ||
var warnDeprecatedProp = (function (propName, componentName, additionalMessage) { | ||
function warnDeprecatedProp(propName, componentName) { | ||
var _context, _context2; | ||
var additionalMessage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; | ||
var message = _concatInstanceProperty__default['default'](_context = _concatInstanceProperty__default['default'](_context2 = "\"".concat(propName, "\" property of \"")).call(_context2, componentName, "\" has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage); | ||
warning__default['default'](false, message); | ||
}); | ||
} | ||
@@ -152,3 +100,3 @@ // Whenever a field requires a unique id, this factory can be used | ||
// const element = <div id={sequentialId()}>foo</div> | ||
var createSequentialId = function createSequentialId(prefix) { | ||
function createSequentialId(prefix) { | ||
var id = 0; | ||
@@ -161,3 +109,3 @@ return function () { | ||
}; | ||
}; | ||
} | ||
@@ -193,30 +141,26 @@ var getFieldId = function getFieldId(props, state, createId) { | ||
hours = _match[1], | ||
_match$ = _match[2], | ||
minutes = _match$ === void 0 ? '00' : _match$, | ||
_match$2 = _match[3], | ||
seconds = _match$2 === void 0 ? '00' : _match$2, | ||
_match$3 = _match[4], | ||
milliseconds = _match$3 === void 0 ? '000' : _match$3, | ||
// eslint-disable-next-line prefer-const | ||
amPm = _match[5]; | ||
minutes = _match[2], | ||
seconds = _match[3], | ||
milliseconds = _match[4], | ||
amPm = _match[5]; | ||
minutes = Number(minutes); | ||
seconds = Number(seconds); // Parses the number as a fraction to ensure that .5, .05 and .005 are | ||
var parsedMinutes = Number(minutes !== null && minutes !== void 0 ? minutes : '00'); | ||
var parsedSeconds = Number(seconds !== null && seconds !== void 0 ? seconds : '00'); // Parses the number as a fraction to ensure that .5, .05 and .005 are | ||
// parsed correctily (they are 500, 50 and 5 respectively). | ||
milliseconds = Number("0.".concat(milliseconds)) * 1000; // edge-case: allow 24:00, but nothing over it | ||
var parsedMilliseconds = Number("0.".concat(milliseconds !== null && milliseconds !== void 0 ? milliseconds : '000')) * 1000; // edge-case: allow 24:00, but nothing over it | ||
hours = Number(hours) === 24 && minutes === 0 && seconds === 0 && milliseconds === 0 ? 0 : Number(hours); | ||
var parsedHours = Number(hours) === 24 && parsedMinutes === 0 && parsedSeconds === 0 && parsedMilliseconds === 0 ? 0 : Number(hours); | ||
if (amPm) { | ||
if (hours > 12) return null; | ||
if (hours === 0) return null; | ||
if (minutes > 59) return null; | ||
if (parsedHours > 12) return null; | ||
if (parsedHours === 0) return null; | ||
if (parsedMinutes > 59) return null; | ||
} else { | ||
if (hours > 23) return null; | ||
if (minutes > 59) return null; | ||
if (parsedHours > 23) return null; | ||
if (parsedMinutes > 59) return null; | ||
} | ||
if (seconds > 59) return null; | ||
if (milliseconds > 999) return null; // 12 pm (just like 24:00) would be on the next day, so we treat it as an | ||
if (parsedSeconds > 59) return null; | ||
if (parsedMilliseconds > 999) return null; // 12 pm (just like 24:00) would be on the next day, so we treat it as an | ||
// invalid value to avoid edge cases like the day jumping forward | ||
@@ -226,5 +170,5 @@ // if (amPm === 'pm' && Number(hours) === 12) return null; | ||
var hourOffset = function () { | ||
if (amPm === 'am' && hours === 12) return -12; | ||
if (amPm === 'am' && parsedHours === 12) return -12; | ||
if (amPm === 'am') return 0; | ||
if (amPm === 'pm' && hours !== 12) return 12; | ||
if (amPm === 'pm' && parsedHours !== 12) return 12; | ||
return 0; | ||
@@ -234,6 +178,6 @@ }(); | ||
return { | ||
hours: Number(hours) + hourOffset, | ||
minutes: minutes, | ||
seconds: seconds, | ||
milliseconds: milliseconds | ||
hours: parsedHours + hourOffset, | ||
minutes: parsedMinutes, | ||
seconds: parsedSeconds, | ||
milliseconds: parsedMilliseconds | ||
}; | ||
@@ -247,6 +191,6 @@ }; | ||
var addStaticFields = (function (Component, fields) { | ||
function addStaticFields(Component, fields) { | ||
var _context; | ||
return _forEachInstanceProperty__default['default'](_context = _Object$entries__default['default'](fields)).call(_context, function (_ref) { | ||
_forEachInstanceProperty__default['default'](_context = _Object$entries__default['default'](fields)).call(_context, function (_ref) { | ||
var _ref2 = _slicedToArray__default['default'](_ref, 2), | ||
@@ -257,8 +201,11 @@ key = _ref2[0], | ||
// eslint-disable-next-line no-param-reassign | ||
// @ts-expect-error | ||
Component[key] = value; | ||
}); | ||
}); | ||
return Component; | ||
} | ||
// NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file. | ||
var version = '10.42.2'; | ||
var version = '10.44.0'; | ||
@@ -265,0 +212,0 @@ exports.SafeHTMLElement = SafeHTMLElement; |
@@ -5,12 +5,10 @@ 'use strict'; | ||
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys'); | ||
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray'); | ||
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries'); | ||
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter'); | ||
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce'); | ||
var _defineProperty$1 = require('@babel/runtime-corejs3/helpers/defineProperty'); | ||
var _Object$fromEntries = require('@babel/runtime-corejs3/core-js-stable/object/from-entries'); | ||
var isPropValid = require('@emotion/is-prop-valid'); | ||
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat'); | ||
var warning = require('warning'); | ||
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray'); | ||
var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim'); | ||
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries'); | ||
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each'); | ||
@@ -20,12 +18,10 @@ | ||
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys); | ||
var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray); | ||
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries); | ||
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty); | ||
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty); | ||
var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty$1); | ||
var _Object$fromEntries__default = /*#__PURE__*/_interopDefault(_Object$fromEntries); | ||
var isPropValid__default = /*#__PURE__*/_interopDefault(isPropValid); | ||
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty); | ||
var warning__default = /*#__PURE__*/_interopDefault(warning); | ||
var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray); | ||
var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty); | ||
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries); | ||
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty); | ||
@@ -35,11 +31,10 @@ | ||
function filterDataAttributes(obj) { | ||
var _context, _context2; | ||
var _context; | ||
return _reduceInstanceProperty__default['default'](_context = _filterInstanceProperty__default['default'](_context2 = _Object$keys__default['default'](obj)).call(_context2, function (p) { | ||
return regexpData.test(p); | ||
})).call(_context, function (acc, p) { | ||
// eslint-disable-next-line no-param-reassign | ||
acc[p] = obj[p]; | ||
return acc; | ||
}, {}); | ||
return _Object$fromEntries__default['default'](_filterInstanceProperty__default['default'](_context = _Object$entries__default['default'](obj)).call(_context, function (_ref) { | ||
var _ref2 = _slicedToArray__default['default'](_ref, 1), | ||
propFromEntry = _ref2[0]; | ||
return regexpData.test(propFromEntry); | ||
})); | ||
} | ||
@@ -49,72 +44,23 @@ | ||
function filterAriaAttributes(obj) { | ||
var _context, _context2; | ||
var _context; | ||
return _reduceInstanceProperty__default['default'](_context = _filterInstanceProperty__default['default'](_context2 = _Object$keys__default['default'](obj)).call(_context2, function (p) { | ||
return regexpData$1.test(p); | ||
})).call(_context, function (acc, p) { | ||
// eslint-disable-next-line no-param-reassign | ||
acc[p] = obj[p]; | ||
return acc; | ||
}, {}); | ||
} | ||
return _Object$fromEntries__default['default'](_filterInstanceProperty__default['default'](_context = _Object$entries__default['default'](obj)).call(_context, function (_ref) { | ||
var _ref2 = _slicedToArray__default['default'](_ref, 1), | ||
propFromEntry = _ref2[0]; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
return regexpData$1.test(propFromEntry); | ||
})); | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
function filterInvalidAttributes(obj) { | ||
var _context; | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return _Object$fromEntries__default['default'](_filterInstanceProperty__default['default'](_context = _Object$entries__default['default'](obj)).call(_context, function (_ref) { | ||
var _ref2 = _slicedToArray__default['default'](_ref, 1), | ||
propFromEntry = _ref2[0]; | ||
return keys; | ||
return isPropValid__default['default'](propFromEntry); | ||
})); | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function filterInvalidAttributes(obj) { | ||
var _context, _context2; | ||
return _reduceInstanceProperty__default['default'](_context = _filterInstanceProperty__default['default'](_context2 = _Object$keys__default['default'](obj)).call(_context2, function (prop) { | ||
return isPropValid__default['default'](prop); | ||
})).call(_context, function (acc, prop) { | ||
return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty__default['default']({}, prop, obj[prop])); | ||
}, {}); | ||
} | ||
// Given a string, validates that it has the correct format | ||
@@ -126,3 +72,3 @@ // to be a number, with decimal separators and negative sign. | ||
var warnDeprecatedComponent = (function (componentName) { | ||
function warnDeprecatedComponent(componentName) { | ||
var _context; | ||
@@ -135,11 +81,13 @@ | ||
warning__default['default'](false, message); | ||
}); | ||
} | ||
var warnDeprecatedProp = (function (propName, componentName, additionalMessage) { | ||
function warnDeprecatedProp(propName, componentName) { | ||
var _context, _context2; | ||
var additionalMessage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; | ||
var message = _concatInstanceProperty__default['default'](_context = _concatInstanceProperty__default['default'](_context2 = "\"".concat(propName, "\" property of \"")).call(_context2, componentName, "\" has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage); | ||
warning__default['default'](false, message); | ||
}); | ||
} | ||
@@ -152,3 +100,3 @@ // Whenever a field requires a unique id, this factory can be used | ||
// const element = <div id={sequentialId()}>foo</div> | ||
var createSequentialId = function createSequentialId(prefix) { | ||
function createSequentialId(prefix) { | ||
var id = 0; | ||
@@ -161,3 +109,3 @@ return function () { | ||
}; | ||
}; | ||
} | ||
@@ -193,30 +141,26 @@ var getFieldId = function getFieldId(props, state, createId) { | ||
hours = _match[1], | ||
_match$ = _match[2], | ||
minutes = _match$ === void 0 ? '00' : _match$, | ||
_match$2 = _match[3], | ||
seconds = _match$2 === void 0 ? '00' : _match$2, | ||
_match$3 = _match[4], | ||
milliseconds = _match$3 === void 0 ? '000' : _match$3, | ||
// eslint-disable-next-line prefer-const | ||
amPm = _match[5]; | ||
minutes = _match[2], | ||
seconds = _match[3], | ||
milliseconds = _match[4], | ||
amPm = _match[5]; | ||
minutes = Number(minutes); | ||
seconds = Number(seconds); // Parses the number as a fraction to ensure that .5, .05 and .005 are | ||
var parsedMinutes = Number(minutes !== null && minutes !== void 0 ? minutes : '00'); | ||
var parsedSeconds = Number(seconds !== null && seconds !== void 0 ? seconds : '00'); // Parses the number as a fraction to ensure that .5, .05 and .005 are | ||
// parsed correctily (they are 500, 50 and 5 respectively). | ||
milliseconds = Number("0.".concat(milliseconds)) * 1000; // edge-case: allow 24:00, but nothing over it | ||
var parsedMilliseconds = Number("0.".concat(milliseconds !== null && milliseconds !== void 0 ? milliseconds : '000')) * 1000; // edge-case: allow 24:00, but nothing over it | ||
hours = Number(hours) === 24 && minutes === 0 && seconds === 0 && milliseconds === 0 ? 0 : Number(hours); | ||
var parsedHours = Number(hours) === 24 && parsedMinutes === 0 && parsedSeconds === 0 && parsedMilliseconds === 0 ? 0 : Number(hours); | ||
if (amPm) { | ||
if (hours > 12) return null; | ||
if (hours === 0) return null; | ||
if (minutes > 59) return null; | ||
if (parsedHours > 12) return null; | ||
if (parsedHours === 0) return null; | ||
if (parsedMinutes > 59) return null; | ||
} else { | ||
if (hours > 23) return null; | ||
if (minutes > 59) return null; | ||
if (parsedHours > 23) return null; | ||
if (parsedMinutes > 59) return null; | ||
} | ||
if (seconds > 59) return null; | ||
if (milliseconds > 999) return null; // 12 pm (just like 24:00) would be on the next day, so we treat it as an | ||
if (parsedSeconds > 59) return null; | ||
if (parsedMilliseconds > 999) return null; // 12 pm (just like 24:00) would be on the next day, so we treat it as an | ||
// invalid value to avoid edge cases like the day jumping forward | ||
@@ -226,5 +170,5 @@ // if (amPm === 'pm' && Number(hours) === 12) return null; | ||
var hourOffset = function () { | ||
if (amPm === 'am' && hours === 12) return -12; | ||
if (amPm === 'am' && parsedHours === 12) return -12; | ||
if (amPm === 'am') return 0; | ||
if (amPm === 'pm' && hours !== 12) return 12; | ||
if (amPm === 'pm' && parsedHours !== 12) return 12; | ||
return 0; | ||
@@ -234,6 +178,6 @@ }(); | ||
return { | ||
hours: Number(hours) + hourOffset, | ||
minutes: minutes, | ||
seconds: seconds, | ||
milliseconds: milliseconds | ||
hours: parsedHours + hourOffset, | ||
minutes: parsedMinutes, | ||
seconds: parsedSeconds, | ||
milliseconds: parsedMilliseconds | ||
}; | ||
@@ -247,6 +191,6 @@ }; | ||
var addStaticFields = (function (Component, fields) { | ||
function addStaticFields(Component, fields) { | ||
var _context; | ||
return _forEachInstanceProperty__default['default'](_context = _Object$entries__default['default'](fields)).call(_context, function (_ref) { | ||
_forEachInstanceProperty__default['default'](_context = _Object$entries__default['default'](fields)).call(_context, function (_ref) { | ||
var _ref2 = _slicedToArray__default['default'](_ref, 2), | ||
@@ -257,8 +201,11 @@ key = _ref2[0], | ||
// eslint-disable-next-line no-param-reassign | ||
// @ts-expect-error | ||
Component[key] = value; | ||
}); | ||
}); | ||
return Component; | ||
} | ||
// NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file. | ||
var version = '10.42.2'; | ||
var version = '10.44.0'; | ||
@@ -265,0 +212,0 @@ exports.SafeHTMLElement = SafeHTMLElement; |
@@ -1,11 +0,9 @@ | ||
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys'; | ||
import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray'; | ||
import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries'; | ||
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter'; | ||
import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce'; | ||
import _defineProperty$1 from '@babel/runtime-corejs3/helpers/defineProperty'; | ||
import _Object$fromEntries from '@babel/runtime-corejs3/core-js-stable/object/from-entries'; | ||
import isPropValid from '@emotion/is-prop-valid'; | ||
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat'; | ||
import warning from 'warning'; | ||
import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray'; | ||
import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/trim'; | ||
import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries'; | ||
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each'; | ||
@@ -15,11 +13,10 @@ | ||
function filterDataAttributes(obj) { | ||
var _context, _context2; | ||
var _context; | ||
return _reduceInstanceProperty(_context = _filterInstanceProperty(_context2 = _Object$keys(obj)).call(_context2, function (p) { | ||
return regexpData.test(p); | ||
})).call(_context, function (acc, p) { | ||
// eslint-disable-next-line no-param-reassign | ||
acc[p] = obj[p]; | ||
return acc; | ||
}, {}); | ||
return _Object$fromEntries(_filterInstanceProperty(_context = _Object$entries(obj)).call(_context, function (_ref) { | ||
var _ref2 = _slicedToArray(_ref, 1), | ||
propFromEntry = _ref2[0]; | ||
return regexpData.test(propFromEntry); | ||
})); | ||
} | ||
@@ -29,72 +26,23 @@ | ||
function filterAriaAttributes(obj) { | ||
var _context, _context2; | ||
var _context; | ||
return _reduceInstanceProperty(_context = _filterInstanceProperty(_context2 = _Object$keys(obj)).call(_context2, function (p) { | ||
return regexpData$1.test(p); | ||
})).call(_context, function (acc, p) { | ||
// eslint-disable-next-line no-param-reassign | ||
acc[p] = obj[p]; | ||
return acc; | ||
}, {}); | ||
} | ||
return _Object$fromEntries(_filterInstanceProperty(_context = _Object$entries(obj)).call(_context, function (_ref) { | ||
var _ref2 = _slicedToArray(_ref, 1), | ||
propFromEntry = _ref2[0]; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
return regexpData$1.test(propFromEntry); | ||
})); | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
function filterInvalidAttributes(obj) { | ||
var _context; | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return _Object$fromEntries(_filterInstanceProperty(_context = _Object$entries(obj)).call(_context, function (_ref) { | ||
var _ref2 = _slicedToArray(_ref, 1), | ||
propFromEntry = _ref2[0]; | ||
return keys; | ||
return isPropValid(propFromEntry); | ||
})); | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function filterInvalidAttributes(obj) { | ||
var _context, _context2; | ||
return _reduceInstanceProperty(_context = _filterInstanceProperty(_context2 = _Object$keys(obj)).call(_context2, function (prop) { | ||
return isPropValid(prop); | ||
})).call(_context, function (acc, prop) { | ||
return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty$1({}, prop, obj[prop])); | ||
}, {}); | ||
} | ||
// Given a string, validates that it has the correct format | ||
@@ -106,3 +54,3 @@ // to be a number, with decimal separators and negative sign. | ||
var warnDeprecatedComponent = (function (componentName) { | ||
function warnDeprecatedComponent(componentName) { | ||
var _context; | ||
@@ -115,11 +63,13 @@ | ||
warning(false, message); | ||
}); | ||
} | ||
var warnDeprecatedProp = (function (propName, componentName, additionalMessage) { | ||
function warnDeprecatedProp(propName, componentName) { | ||
var _context, _context2; | ||
var additionalMessage = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; | ||
var message = _concatInstanceProperty(_context = _concatInstanceProperty(_context2 = "\"".concat(propName, "\" property of \"")).call(_context2, componentName, "\" has been deprecated and will be removed in the next major version.")).call(_context, additionalMessage); | ||
warning(false, message); | ||
}); | ||
} | ||
@@ -132,3 +82,3 @@ // Whenever a field requires a unique id, this factory can be used | ||
// const element = <div id={sequentialId()}>foo</div> | ||
var createSequentialId = function createSequentialId(prefix) { | ||
function createSequentialId(prefix) { | ||
var id = 0; | ||
@@ -141,3 +91,3 @@ return function () { | ||
}; | ||
}; | ||
} | ||
@@ -173,30 +123,26 @@ var getFieldId = function getFieldId(props, state, createId) { | ||
hours = _match[1], | ||
_match$ = _match[2], | ||
minutes = _match$ === void 0 ? '00' : _match$, | ||
_match$2 = _match[3], | ||
seconds = _match$2 === void 0 ? '00' : _match$2, | ||
_match$3 = _match[4], | ||
milliseconds = _match$3 === void 0 ? '000' : _match$3, | ||
// eslint-disable-next-line prefer-const | ||
amPm = _match[5]; | ||
minutes = _match[2], | ||
seconds = _match[3], | ||
milliseconds = _match[4], | ||
amPm = _match[5]; | ||
minutes = Number(minutes); | ||
seconds = Number(seconds); // Parses the number as a fraction to ensure that .5, .05 and .005 are | ||
var parsedMinutes = Number(minutes !== null && minutes !== void 0 ? minutes : '00'); | ||
var parsedSeconds = Number(seconds !== null && seconds !== void 0 ? seconds : '00'); // Parses the number as a fraction to ensure that .5, .05 and .005 are | ||
// parsed correctily (they are 500, 50 and 5 respectively). | ||
milliseconds = Number("0.".concat(milliseconds)) * 1000; // edge-case: allow 24:00, but nothing over it | ||
var parsedMilliseconds = Number("0.".concat(milliseconds !== null && milliseconds !== void 0 ? milliseconds : '000')) * 1000; // edge-case: allow 24:00, but nothing over it | ||
hours = Number(hours) === 24 && minutes === 0 && seconds === 0 && milliseconds === 0 ? 0 : Number(hours); | ||
var parsedHours = Number(hours) === 24 && parsedMinutes === 0 && parsedSeconds === 0 && parsedMilliseconds === 0 ? 0 : Number(hours); | ||
if (amPm) { | ||
if (hours > 12) return null; | ||
if (hours === 0) return null; | ||
if (minutes > 59) return null; | ||
if (parsedHours > 12) return null; | ||
if (parsedHours === 0) return null; | ||
if (parsedMinutes > 59) return null; | ||
} else { | ||
if (hours > 23) return null; | ||
if (minutes > 59) return null; | ||
if (parsedHours > 23) return null; | ||
if (parsedMinutes > 59) return null; | ||
} | ||
if (seconds > 59) return null; | ||
if (milliseconds > 999) return null; // 12 pm (just like 24:00) would be on the next day, so we treat it as an | ||
if (parsedSeconds > 59) return null; | ||
if (parsedMilliseconds > 999) return null; // 12 pm (just like 24:00) would be on the next day, so we treat it as an | ||
// invalid value to avoid edge cases like the day jumping forward | ||
@@ -206,5 +152,5 @@ // if (amPm === 'pm' && Number(hours) === 12) return null; | ||
var hourOffset = function () { | ||
if (amPm === 'am' && hours === 12) return -12; | ||
if (amPm === 'am' && parsedHours === 12) return -12; | ||
if (amPm === 'am') return 0; | ||
if (amPm === 'pm' && hours !== 12) return 12; | ||
if (amPm === 'pm' && parsedHours !== 12) return 12; | ||
return 0; | ||
@@ -214,6 +160,6 @@ }(); | ||
return { | ||
hours: Number(hours) + hourOffset, | ||
minutes: minutes, | ||
seconds: seconds, | ||
milliseconds: milliseconds | ||
hours: parsedHours + hourOffset, | ||
minutes: parsedMinutes, | ||
seconds: parsedSeconds, | ||
milliseconds: parsedMilliseconds | ||
}; | ||
@@ -227,6 +173,6 @@ }; | ||
var addStaticFields = (function (Component, fields) { | ||
function addStaticFields(Component, fields) { | ||
var _context; | ||
return _forEachInstanceProperty(_context = _Object$entries(fields)).call(_context, function (_ref) { | ||
_forEachInstanceProperty(_context = _Object$entries(fields)).call(_context, function (_ref) { | ||
var _ref2 = _slicedToArray(_ref, 2), | ||
@@ -237,9 +183,12 @@ key = _ref2[0], | ||
// eslint-disable-next-line no-param-reassign | ||
// @ts-expect-error | ||
Component[key] = value; | ||
}); | ||
}); | ||
return Component; | ||
} | ||
// NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file. | ||
var version = '10.42.2'; | ||
var version = '10.44.0'; | ||
export { SafeHTMLElement, addStaticFields, createSequentialId, filterAriaAttributes, filterDataAttributes, filterInvalidAttributes, getFieldId, isNumberish, parseTime, version, warnDeprecatedComponent, warnDeprecatedProp }; |
{ | ||
"name": "@commercetools-uikit/utils", | ||
"description": "A collection of utilities shared across the other packages.", | ||
"version": "10.42.2", | ||
"version": "10.44.0", | ||
"bugs": "https://github.com/commercetools/ui-kit/issues", | ||
@@ -29,4 +29,5 @@ "repository": { | ||
"@emotion/is-prop-valid": "1.0.0", | ||
"@types/warning": "^3.0.0", | ||
"warning": "4.0.3" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
23
0
32513
5
534
+ Added@types/warning@^3.0.0
+ Added@types/warning@3.0.3(transitive)