intelicoreact 1.4.85 → 1.4.86

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.
@@ -292,48 +292,47 @@ function formatToReplaceAllWhiteSpace(str) {
292
292
  // ****************************
293
293
  // filter
294
294
  // ****************************
295
+ //? Намерянно выпилил определение дефолтного значение на уровне параметров, чтобы сделать null рабочим значением
296
+ //? decimalPlaces === null теперь точно определяет режим ввода БЕЗ ограничей десятичных знаков
297
+ const filterFloat = (inputValue, decimalPlaces) => {
298
+ var _ref2;
299
+ const replaser = input => ('' + input).replace(/[^\.\d]/g, '');
300
+ const value = getSafelyValue(inputValue);
295
301
 
296
- // export const filterFloat = (inputValue, decimalPlaces = null) => {
297
- // const value = getSafelyValue(inputValue);
298
- // const replaser = input => ('' + input).replace(/[^\.\d]/g, '');
299
- //
300
- // if (value.length === 1 && (value[0] === '.' || value[0] === ',')) return '0.';
301
- // let output = ('' + value)?.replace(/,/g, '.');
302
- // if (value.length > 1 && value[0] === '0' && value[1] !== '.' && value[0] !== ',') output = value.slice(1);
303
- //
304
- // const previousValue = '' + output.slice(0, -1);
305
- // const lastSym = '' + output.slice(-1);
306
- //
307
- // if (
308
- // decimalPlaces &&
309
- // typeof decimalPlaces === 'number' &&
310
- // previousValue.includes('.') &&
311
- // previousValue.indexOf('.') + 1 + decimalPlaces === previousValue.length
312
- // )
313
- // return replaser(previousValue);
314
- // return replaser(lastSym === '.' && previousValue.includes('.') ? previousValue : output);
315
- // };
302
+ //? safelyDecimalPlaces ТОЧНО либо null, либо целое число
303
+ const safelyDecimalPlaces = (() => {
304
+ if (decimalPlaces === null) return decimalPlaces;
305
+ const DEFAULT_VALUE = 2;
306
+ const isNumber = typeof decimalPlaces === 'number' || typeof decimalPlaces === 'string' && !Number.isNaN(+decimalPlaces);
316
307
 
317
- const filterFloat = function (inputValue) {
318
- var _output, _output2, _output3, _output4;
319
- let decimalPlaces = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
320
- const value = getSafelyValue(inputValue);
321
- const replacer = input => {
322
- var _String;
323
- return (_String = String(input)) === null || _String === void 0 ? void 0 : _String.replace(/[^\.\d,]/g, "");
324
- };
325
- if (value.length === 1 && (value[0] === "." || value[0] === ",")) return "0.";
326
- let output = value;
327
- const previousValue = String((_output = output) === null || _output === void 0 ? void 0 : _output.slice(0, -1));
328
- const lastSym = String((_output2 = output) === null || _output2 === void 0 ? void 0 : _output2.slice(-1));
329
- if (decimalPlaces && typeof decimalPlaces === "number" && previousValue !== null && previousValue !== void 0 && previousValue.includes(".") && (previousValue === null || previousValue === void 0 ? void 0 : previousValue.indexOf(".")) + 1 + decimalPlaces === (previousValue === null || previousValue === void 0 ? void 0 : previousValue.length)) {
330
- return replacer(previousValue);
331
- }
332
- if ((_output3 = output) !== null && _output3 !== void 0 && _output3.includes(".") && output[((_output4 = output) === null || _output4 === void 0 ? void 0 : _output4.indexOf(".")) + 3] !== undefined && Number(output)) {
333
- var _Number;
334
- output = (_Number = Number(output)) === null || _Number === void 0 ? void 0 : _Number.toFixed(decimalPlaces);
308
+ //? защита от дробного значения decimalPlaces
309
+ return isNumber ? Number((+decimalPlaces).toFixed()) : DEFAULT_VALUE;
310
+ })();
311
+
312
+ // Обработка кейса если первым символом нажата точка
313
+ if (value.length === 1 && (value[0] === '.' || value[0] === ',')) return '0.';
314
+
315
+ // Приводим запятые к корректному разделителю, но не выпиливаем
316
+ let output = (_ref2 = '' + value) === null || _ref2 === void 0 ? void 0 : _ref2.replace(/,/g, '.');
317
+
318
+ // Выпилить первый ноль, если это не дробь
319
+ if (value.length > 1 && value[0] === '0' && value[1] !== '.' && value[0] !== ',') output = value.slice(1);
320
+ const previousValue = '' + output.slice(0, -1);
321
+ const lastSym = '' + output.slice(-1);
322
+
323
+ // Обработка кейса второй точки в дроби
324
+ if (lastSym === '.' && previousValue.includes('.')) output = previousValue;
325
+
326
+ // if (localStorage.getItem('useDeb')) debugger;
327
+
328
+ // Логика ограничения по decimalPlaces
329
+ if (typeof safelyDecimalPlaces === 'number') {
330
+ if (!safelyDecimalPlaces && lastSym === '.') return replaser(previousValue);
331
+ if (previousValue.includes('.') && previousValue.indexOf('.') + 1 + safelyDecimalPlaces === (previousValue === null || previousValue === void 0 ? void 0 : previousValue.length)) {
332
+ return replaser(previousValue);
333
+ }
335
334
  }
336
- return replacer(lastSym === "." && previousValue !== null && previousValue !== void 0 && previousValue.includes(".") ? previousValue : output);
335
+ return replaser(output);
337
336
  };
338
337
  exports.filterFloat = filterFloat;
339
338
  const filterNumeric = (value, settings) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "1.4.85",
3
+ "version": "1.4.86",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [