argous 1.2.179 → 1.2.180
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.
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +26 -1
- package/lib/utils/index.ts +21 -0
- package/package.json +1 -1
package/dist/utils/index.d.ts
CHANGED
|
@@ -57,5 +57,8 @@ export declare const reduxDispatch: (action: ActionType) => void;
|
|
|
57
57
|
export declare const formataTelefone: (value: string) => string;
|
|
58
58
|
export declare const useWebSocket: () => {};
|
|
59
59
|
export declare const formataCpf: (value: string) => string;
|
|
60
|
+
export declare const numbersOnly: (value: string, type: string) => string;
|
|
61
|
+
export declare const currencyMask: (value: string | number) => string | undefined;
|
|
62
|
+
export declare const toFloat: (value: string) => number | undefined;
|
|
60
63
|
export declare const copyToClipboard: (text: string) => void;
|
|
61
64
|
export declare const confirm: (props: BasicModalProps | string) => Promise<boolean>;
|
package/dist/utils/index.js
CHANGED
|
@@ -82,13 +82,14 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
|
82
82
|
return to;
|
|
83
83
|
};
|
|
84
84
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
85
|
-
exports.confirm = exports.copyToClipboard = exports.formataCpf = exports.useWebSocket = exports.formataTelefone = exports.reduxDispatch = exports.useStore = exports.useModal = exports.useGraph = exports.randomColor = exports.humanFileSize = exports.sanitizaHTML = exports.formataDinheiro = exports.useUpdateEffect = exports.usePrevious = exports.getNumeroFromInitials = exports.getInitials = exports.getRandomColor = exports.printPdf = exports.downloadFromUrl = exports.downloadBase64 = exports.formataNome = exports.addExtraZero = exports.getCookie = exports.widthToCenterVertically = void 0;
|
|
85
|
+
exports.confirm = exports.copyToClipboard = exports.toFloat = exports.currencyMask = exports.numbersOnly = exports.formataCpf = exports.useWebSocket = exports.formataTelefone = exports.reduxDispatch = exports.useStore = exports.useModal = exports.useGraph = exports.randomColor = exports.humanFileSize = exports.sanitizaHTML = exports.formataDinheiro = exports.useUpdateEffect = exports.usePrevious = exports.getNumeroFromInitials = exports.getInitials = exports.getRandomColor = exports.printPdf = exports.downloadFromUrl = exports.downloadBase64 = exports.formataNome = exports.addExtraZero = exports.getCookie = exports.widthToCenterVertically = void 0;
|
|
86
86
|
var store_1 = require("./store");
|
|
87
87
|
var api_1 = require("../api");
|
|
88
88
|
var ModalProvider_1 = require("../components/ConfirmModal/ModalProvider");
|
|
89
89
|
var fieldsRedux_1 = require("../fieldsRedux");
|
|
90
90
|
var core_1 = require("@material-ui/core");
|
|
91
91
|
var colors = __importStar(require("@material-ui/core/colors"));
|
|
92
|
+
var lodash_1 = require("lodash");
|
|
92
93
|
var react_1 = require("react");
|
|
93
94
|
var widthToCenterVertically = function (content) {
|
|
94
95
|
var B = document.body;
|
|
@@ -362,6 +363,30 @@ var useWebSocket = function () {
|
|
|
362
363
|
exports.useWebSocket = useWebSocket;
|
|
363
364
|
var formataCpf = function (value) { return value === null || value === void 0 ? void 0 : value.replace(/[^\d]/, '').replace(/^(.{3})(.{3})(.{3})(.{2})$/, '$1.$2.$3-$4'); };
|
|
364
365
|
exports.formataCpf = formataCpf;
|
|
366
|
+
var numbersOnly = function (value, type) { return value ? value.replace(type === 'float' ? /[^0-9/.,]/g : /[^0-9]/g, '') : ''; };
|
|
367
|
+
exports.numbersOnly = numbersOnly;
|
|
368
|
+
var currencyMask = function (value) {
|
|
369
|
+
if (value === 0)
|
|
370
|
+
return value.toString() + ",00";
|
|
371
|
+
if (!value)
|
|
372
|
+
return;
|
|
373
|
+
if (lodash_1.isNumber(value))
|
|
374
|
+
value = value.toFixed(2);
|
|
375
|
+
value = value.toString();
|
|
376
|
+
value = value.replace(/\D/g, '');
|
|
377
|
+
value = value.replace(/(\d)(\d{2})$/, '$1,$2');
|
|
378
|
+
value = value.replace(/(?=(\d{3})+(\D))\B/g, '.');
|
|
379
|
+
return value;
|
|
380
|
+
};
|
|
381
|
+
exports.currencyMask = currencyMask;
|
|
382
|
+
var toFloat = function (value) {
|
|
383
|
+
if (!value)
|
|
384
|
+
return;
|
|
385
|
+
value = value.replace(/[.]/g, '');
|
|
386
|
+
value = value.replace(/[,]/g, '.');
|
|
387
|
+
return parseFloat(value);
|
|
388
|
+
};
|
|
389
|
+
exports.toFloat = toFloat;
|
|
365
390
|
var copyToClipboard = function (text) {
|
|
366
391
|
if (navigator.clipboard)
|
|
367
392
|
navigator.clipboard.writeText(text);
|
package/lib/utils/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import * as colors from '@material-ui/core/colors';
|
|
|
8
8
|
import { ChartOptions } from 'chart.js';
|
|
9
9
|
// import { BasicModal } from '../components';
|
|
10
10
|
import { BasicModalProps } from 'lib/components';
|
|
11
|
+
import { isNumber } from 'lodash';
|
|
11
12
|
import React, { useRef, useEffect, useContext, useState } from 'react';
|
|
12
13
|
|
|
13
14
|
export const widthToCenterVertically = (content:number) => {
|
|
@@ -295,6 +296,26 @@ export const useWebSocket = () => {
|
|
|
295
296
|
|
|
296
297
|
export const formataCpf = (value: string) => value?.replace(/[^\d]/, '').replace(/^(.{3})(.{3})(.{3})(.{2})$/, '$1.$2.$3-$4');
|
|
297
298
|
|
|
299
|
+
export const numbersOnly = (value: string, type: string) => value ? value.replace(type === 'float' ? /[^0-9/.,]/g : /[^0-9]/g, '') : '';
|
|
300
|
+
|
|
301
|
+
export const currencyMask = (value: string | number) => {
|
|
302
|
+
if (value === 0) return `${value.toString()},00`;
|
|
303
|
+
if (!value) return;
|
|
304
|
+
if (isNumber(value)) value = value.toFixed(2);
|
|
305
|
+
value = value.toString();
|
|
306
|
+
value = value.replace(/\D/g, '');
|
|
307
|
+
value = value.replace(/(\d)(\d{2})$/, '$1,$2');
|
|
308
|
+
value = value.replace(/(?=(\d{3})+(\D))\B/g, '.');
|
|
309
|
+
return value;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
export const toFloat = (value: string) => {
|
|
313
|
+
if (!value) return;
|
|
314
|
+
value = value.replace(/[.]/g, '');
|
|
315
|
+
value = value.replace(/[,]/g, '.');
|
|
316
|
+
return parseFloat(value);
|
|
317
|
+
};
|
|
318
|
+
|
|
298
319
|
export const copyToClipboard = (text: string) => {
|
|
299
320
|
if (navigator.clipboard) navigator.clipboard.writeText(text);
|
|
300
321
|
else {
|