native-pytech 1.0.18 → 1.0.21

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.
@@ -0,0 +1 @@
1
+ export * from '../../libs/constants/formats';
@@ -0,0 +1 @@
1
+ export * from '../../libs/constants/formats';
@@ -0,0 +1,10 @@
1
+ declare function numberToTextCurrency(value: number): string;
2
+ declare const Formats: {
3
+ numberToText: (value: number) => string;
4
+ TextToNumber: (value: string) => number;
5
+ numberToTextCurrency: typeof numberToTextCurrency;
6
+ dateToText: (value: string) => string;
7
+ capitalizeText: (string: string) => string;
8
+ phoneToText: (phone: number | string) => string;
9
+ };
10
+ export default Formats;
@@ -0,0 +1,77 @@
1
+ const formatter = new Intl.NumberFormat('es-AR');
2
+ const numberToText = (value) => {
3
+ const abs = formatter.format(Math.abs(value));
4
+ return value < 0 ? `(${abs})` : abs;
5
+ };
6
+ const TextToNumber = (value) => {
7
+ const trimmed = value.trim();
8
+ const isNegative = /^\(.*\)$/.test(trimmed);
9
+ const normalized = trimmed
10
+ .replace(/[()]/g, '')
11
+ .replace(/\./g, '')
12
+ .replace(',', '.');
13
+ const parsed = Number.parseFloat(normalized);
14
+ if (Number.isNaN(parsed))
15
+ return 0;
16
+ return isNegative ? -parsed : parsed;
17
+ };
18
+ function numberToTextCurrency(value) {
19
+ return new Intl.NumberFormat('es-AR', {
20
+ style: 'currency',
21
+ currency: 'ARS',
22
+ minimumFractionDigits: 0, // <- no obliga decimales
23
+ maximumFractionDigits: 2 // <- si vienen, los respeta
24
+ }).format(Number(value));
25
+ }
26
+ const dateToText = (value) => {
27
+ const [year, month, day] = value.split('-').map(Number);
28
+ const date = new Date(year, month - 1, day);
29
+ const monthText = new Intl.DateTimeFormat('es-AR', {
30
+ month: 'long',
31
+ }).format(date);
32
+ const dayText = new Intl.DateTimeFormat('es-AR', {
33
+ day: '2-digit',
34
+ }).format(date);
35
+ const yearText = new Intl.DateTimeFormat('es-AR', {
36
+ year: 'numeric',
37
+ }).format(date);
38
+ return `${monthText} ${dayText}, ${yearText}`;
39
+ };
40
+ const capitalizeText = (string) => {
41
+ return string.charAt(0).toUpperCase() + string.slice(1);
42
+ };
43
+ const phoneToText = (phone) => {
44
+ const digits = phone.toString().replace(/\D/g, '');
45
+ if (!digits)
46
+ return '';
47
+ const formattedPart = digits.slice(0, 13);
48
+ const extra = digits.slice(13);
49
+ let base = formattedPart;
50
+ if (formattedPart.length > 4) {
51
+ const right = formattedPart.slice(-4);
52
+ const left = formattedPart.slice(0, -4);
53
+ if (formattedPart.length <= 8) {
54
+ base = `${left}-${right}`;
55
+ }
56
+ else {
57
+ const prefix = formattedPart.slice(0, -8);
58
+ const middle = formattedPart.slice(-8, -4);
59
+ const p3 = prefix.slice(-2);
60
+ const p2 = prefix.slice(-3, -2);
61
+ const p1 = prefix.slice(0, -3);
62
+ base = [p1, p2, p3, `${middle}-${right}`]
63
+ .filter(Boolean)
64
+ .join(' ');
65
+ }
66
+ }
67
+ return extra ? `${base}${extra}` : base;
68
+ };
69
+ const Formats = {
70
+ numberToText,
71
+ TextToNumber,
72
+ numberToTextCurrency,
73
+ dateToText,
74
+ capitalizeText,
75
+ phoneToText,
76
+ };
77
+ export default Formats;
@@ -1,13 +1,9 @@
1
1
  import { StyleProp } from 'react-native';
2
2
  import React from 'react';
3
3
  export declare const addProps: (element: React.ReactElement | null, additionalStyles?: StyleProp<any>, extraProps?: Record<string, any>) => React.ReactElement | null;
4
- export declare const numberFormat: (value: number) => string;
5
- export declare const numberFormatInverted: (value: string) => number;
6
- export declare const formatDate: (value: string) => string;
7
4
  export declare const isValidMail: (mail: string) => boolean;
8
5
  export declare function applyOpacity(color: string, opacity: number): string;
9
6
  export declare function adjustLightness(color: string, percentage: number): string;
10
7
  export declare const _getDeviceTier: () => "low" | "medium" | "high";
11
8
  export declare const createCtx: <T>() => readonly [React.Provider<T>, () => T];
12
9
  export declare const createUseContext: <T>(context: React.Context<T | null>) => T;
13
- export declare const capitalize: (string: string) => string;
@@ -13,37 +13,6 @@ export const addProps = (element, additionalStyles = [], extraProps = {}) => {
13
13
  ...extraProps
14
14
  });
15
15
  };
16
- const formatter = new Intl.NumberFormat('es-AR');
17
- export const numberFormat = (value) => {
18
- const abs = formatter.format(Math.abs(value));
19
- return value < 0 ? `(${abs})` : abs;
20
- };
21
- export const numberFormatInverted = (value) => {
22
- const trimmed = value.trim();
23
- const isNegative = /^\(.*\)$/.test(trimmed);
24
- const normalized = trimmed
25
- .replace(/[()]/g, '')
26
- .replace(/\./g, '')
27
- .replace(',', '.');
28
- const parsed = Number.parseFloat(normalized);
29
- if (Number.isNaN(parsed))
30
- return 0;
31
- return isNegative ? -parsed : parsed;
32
- };
33
- export const formatDate = (value) => {
34
- const [year, month, day] = value.split('-').map(Number);
35
- const date = new Date(year, month - 1, day);
36
- const monthText = new Intl.DateTimeFormat('es-AR', {
37
- month: 'long',
38
- }).format(date);
39
- const dayText = new Intl.DateTimeFormat('es-AR', {
40
- day: '2-digit',
41
- }).format(date);
42
- const yearText = new Intl.DateTimeFormat('es-AR', {
43
- year: 'numeric',
44
- }).format(date);
45
- return `${monthText} ${dayText}, ${yearText}`;
46
- };
47
16
  export const isValidMail = (mail) => {
48
17
  return mail.includes('@') && mail.endsWith('.com');
49
18
  };
@@ -93,6 +62,3 @@ export const createUseContext = (context) => {
93
62
  throw new Error('useContext debe usarse dentro de un context.Provider');
94
63
  return ctx;
95
64
  };
96
- export const capitalize = (string) => {
97
- return string.charAt(0).toUpperCase() + string.slice(1);
98
- };
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
2
  import { TextInputProps } from 'react-native';
3
- export declare function formatPeso(value: number): string;
4
3
  /**
5
4
  Se utiliza específicamente para formatear el valor del input a pesos.
6
5
  Utiliza el componente de TextInputOption.
@@ -1,17 +1,10 @@
1
1
  import React, { memo } from 'react';
2
2
  import TextInputOption from './textInput';
3
- export function formatPeso(value) {
4
- return new Intl.NumberFormat('es-AR', {
5
- style: 'currency',
6
- currency: 'ARS',
7
- minimumFractionDigits: 0, // <- no obliga decimales
8
- maximumFractionDigits: 2 // <- si vienen, los respeta
9
- }).format(Number(value));
10
- }
3
+ import Formats from '../../../../../libs/constants/formats';
11
4
  /**
12
5
  Se utiliza específicamente para formatear el valor del input a pesos.
13
6
  Utiliza el componente de TextInputOption.
14
7
  */
15
8
  export default memo(({ ...props }) => {
16
- return (<TextInputOption keyboardType='numeric' autoCapitalize='none' autoCorrect={false} placeholder={'$0'} mask={(value) => value ? formatPeso(value) : formatPeso(0)} {...props}/>);
9
+ return (<TextInputOption keyboardType='numeric' autoCapitalize='none' autoCorrect={false} placeholder={'$0'} mask={(value) => value ? Formats.numberToTextCurrency(value) : Formats.numberToTextCurrency(0)} {...props}/>);
17
10
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-pytech",
3
- "version": "1.0.18",
3
+ "version": "1.0.21",
4
4
  "description": "Libreria de React Native Pytech",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",