persian-number-input 3.0.3 → 3.0.6
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/README.md +87 -68
- package/dist/components/PersianNumberInput.d.ts +6 -4
- package/dist/components/PersianNumberInput.js +21 -11
- package/dist/components/PersianNumberInput.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/digitUtils.js +1 -0
- package/dist/utils/digitUtils.js.map +1 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -4,34 +4,36 @@
|
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
[
|
|
7
|
+
[English 🇺🇸](#-english)| [فارسی 🇮🇷](#-فارسی)
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## 🇺🇸 English
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Persian Number Input - React Component for Persian, English & Indic Number Formatting
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Easily input, format, and convert numbers in Persian, English, or Indic digits with customizable digit separators. Lightweight, React-compatible, and fully localized for React versions 16 to 19.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
- قابلیت تعیین جداکننده ارقام دلخواه (هزارگان)
|
|
19
|
-
- تبدیل خودکار اعداد محلی به اعداد انگلیسی
|
|
20
|
-
- استفاده آسان و پشتیبانی از React نسخههای 16 تا 19
|
|
17
|
+
✅ **Key Features:**
|
|
21
18
|
|
|
22
|
-
|
|
19
|
+
- Support for Persian, English, and Indic digit localization
|
|
20
|
+
- Customizable digit grouping separators (e.g., commas)
|
|
21
|
+
- Automatically converts localized digits to standard English digits
|
|
22
|
+
- Simple, easy-to-integrate React API
|
|
23
|
+
|
|
24
|
+
### 🚀 Installation
|
|
23
25
|
|
|
24
26
|
```bash
|
|
25
27
|
npm install persian-number-input
|
|
26
28
|
```
|
|
27
29
|
|
|
28
|
-
### 💻
|
|
30
|
+
### 💻 Usage Example
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
Simple usage example:
|
|
31
33
|
|
|
32
34
|
```jsx
|
|
33
35
|
import React, { useState } from "react";
|
|
34
|
-
import PersianNumberInput from "persian-number-input";
|
|
36
|
+
import { PersianNumberInput } from "persian-number-input";
|
|
35
37
|
|
|
36
38
|
const App = () => {
|
|
37
39
|
const [number, setNumber] = useState("");
|
|
@@ -49,58 +51,89 @@ const App = () => {
|
|
|
49
51
|
export default App;
|
|
50
52
|
```
|
|
51
53
|
|
|
52
|
-
### 🔥
|
|
54
|
+
### 🔥 Output Example
|
|
53
55
|
|
|
54
56
|
```
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
Input: 123456
|
|
58
|
+
Displayed Output: ۱۲۳,۴۵۶
|
|
59
|
+
English Output: 123456
|
|
58
60
|
```
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+

|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
-
|
|
|
67
|
-
|
|
|
68
|
-
|
|
|
64
|
+
### 📚 Props Reference
|
|
65
|
+
|
|
66
|
+
| Name | Type | Default | Description |
|
|
67
|
+
| -------------- | ------------------------------- | ------- | ------------------------------------ |
|
|
68
|
+
| initialValue | string | "" | Initial input value |
|
|
69
|
+
| separatorCount | number | 0 | Number of digits per group (e.g., 3) |
|
|
70
|
+
| separatorChar | string | "," | Digit grouping character |
|
|
71
|
+
| lang | 'fa' \| 'in' \| 'en' | "fa" | Digit localization language |
|
|
72
|
+
| onChangeValue | (englishNumber: string) => void | - | Callback function on value change |
|
|
69
73
|
|
|
70
74
|
---
|
|
71
75
|
|
|
72
|
-
###
|
|
76
|
+
### ❓ FAQ (Frequently Asked Questions)
|
|
73
77
|
|
|
74
|
-
|
|
78
|
+
**Does this package support React 19?**
|
|
79
|
+
Yes, it fully supports React versions 16 through 19.
|
|
80
|
+
|
|
81
|
+
**What is the best use-case scenario for this component?**
|
|
82
|
+
Ideal for multilingual web applications, forms, and any interface requiring localized numeric inputs.
|
|
83
|
+
|
|
84
|
+
**How can I customize the styles of this component?**
|
|
85
|
+
You can pass custom classes or inline styles directly to the component to match your design requirements.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
### 🌟 Support the Project
|
|
90
|
+
|
|
91
|
+
If you find this package helpful, **please give it a star ⭐ on GitHub** to encourage further improvements.
|
|
75
92
|
|
|
76
93
|
👉 **[GitHub Repository](https://github.com/javadSharifi/persian-number-input)**
|
|
77
94
|
|
|
78
|
-
|
|
95
|
+
Thank you for your support! ❤️🚀
|
|
79
96
|
|
|
80
|
-
|
|
97
|
+
---
|
|
81
98
|
|
|
82
|
-
|
|
99
|
+
### 📈 SEO Keywords
|
|
83
100
|
|
|
84
|
-
|
|
101
|
+
`Persian Number Input`, `React Persian input`, `localization`, `digit grouping`, `Persian digits`, `React numeric input`, `number formatter`
|
|
85
102
|
|
|
86
|
-
|
|
87
|
-
- Customizable digit grouping separators
|
|
88
|
-
- Automatically converts localized digits to English
|
|
89
|
-
- Easy-to-use API supporting React versions 16 to 19
|
|
103
|
+
---
|
|
90
104
|
|
|
91
|
-
###
|
|
105
|
+
### 📄 License
|
|
106
|
+
|
|
107
|
+
[MIT License](LICENSE)
|
|
108
|
+
|
|
109
|
+
© 2024 Your Name. All rights reserved.
|
|
110
|
+
|
|
111
|
+
# persian-number-input
|
|
112
|
+
|
|
113
|
+
## 🇮🇷 فارسی
|
|
114
|
+
|
|
115
|
+
کامپوننت React برای ورودی اعداد فارسی، انگلیسی و هندی با قابلیت جداکننده ارقام و محلیسازی کامل.
|
|
116
|
+
|
|
117
|
+
✅ **امکانات کلیدی:**
|
|
118
|
+
|
|
119
|
+
- پشتیبانی از اعداد فارسی، انگلیسی و هندی
|
|
120
|
+
- قابلیت تعیین جداکننده ارقام دلخواه (هزارگان)
|
|
121
|
+
- تبدیل خودکار اعداد محلی به اعداد انگلیسی
|
|
122
|
+
- استفاده آسان و پشتیبانی از React نسخههای 16 تا 19
|
|
123
|
+
|
|
124
|
+
### 🚀 نصب
|
|
92
125
|
|
|
93
126
|
```bash
|
|
94
127
|
npm install persian-number-input
|
|
95
128
|
```
|
|
96
129
|
|
|
97
|
-
### 💻
|
|
130
|
+
### 💻 روش استفاده
|
|
98
131
|
|
|
99
|
-
|
|
132
|
+
مثال ساده:
|
|
100
133
|
|
|
101
134
|
```jsx
|
|
102
135
|
import React, { useState } from "react";
|
|
103
|
-
import PersianNumberInput from "persian-number-input";
|
|
136
|
+
import { PersianNumberInput } from "persian-number-input";
|
|
104
137
|
|
|
105
138
|
const App = () => {
|
|
106
139
|
const [number, setNumber] = useState("");
|
|
@@ -118,44 +151,30 @@ const App = () => {
|
|
|
118
151
|
export default App;
|
|
119
152
|
```
|
|
120
153
|
|
|
121
|
-
### 🔥
|
|
154
|
+
### 🔥 مثال خروجی
|
|
122
155
|
|
|
123
156
|
```
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
157
|
+
ورودی: 123456
|
|
158
|
+
خروجی نمایشی: ۱۲۳,۴۵۶
|
|
159
|
+
خروجی انگلیسی: 123456
|
|
127
160
|
```
|
|
128
161
|
|
|
129
|
-
### 📚 Props
|
|
130
|
-
|
|
131
|
-
| Name | Type | Default | Description |
|
|
132
|
-
| -------------- | ------------------------------- | ------- | ------------------------------------ |
|
|
133
|
-
| initialValue | string | "" | Initial input value |
|
|
134
|
-
| separatorCount | number | 0 | Number of digits per group (e.g., 3) |
|
|
135
|
-
| separatorChar | string | "," | Digit grouping character |
|
|
136
|
-
| lang | 'fa' \| 'in' \| 'en' | "fa" | Digit localization language |
|
|
137
|
-
| onChangeValue | (englishNumber: string) => void | - | Callback function on value change |
|
|
138
|
-
|
|
139
|
-
### 🌟 Support the Project
|
|
140
|
-
|
|
141
|
-
If you found this package useful, **please consider giving a star ⭐ on GitHub**. It's the best way to support the project and encourage further improvements.
|
|
142
|
-
|
|
143
|
-
👉 **[GitHub Repository](https://github.com/javadSharifi/persian-number-input)**
|
|
144
|
-
|
|
145
|
-
Thank you for your support! ❤️🚀
|
|
146
|
-
|
|
147
|
-
---
|
|
148
|
-
|
|
149
|
-
### 📈 SEO Keywords
|
|
162
|
+
### 📚 مشخصات Props
|
|
150
163
|
|
|
151
|
-
|
|
164
|
+
| نام | نوع | پیشفرض | توضیح |
|
|
165
|
+
| -------------- | ------------------------------- | ------ | -------------------------------- |
|
|
166
|
+
| initialValue | string | "" | مقدار اولیه |
|
|
167
|
+
| separatorCount | number | 0 | تعداد ارقام جداشده (مثلاً ۳ رقم) |
|
|
168
|
+
| separatorChar | string | "," | کاراکتر جداکننده (مانند `,`) |
|
|
169
|
+
| lang | 'fa' \| 'in' \| 'en' | "fa" | زبان نمایش ارقام |
|
|
170
|
+
| onChangeValue | (englishNumber: string) => void | - | فراخوانی در تغییر مقدار |
|
|
152
171
|
|
|
153
172
|
---
|
|
154
173
|
|
|
155
|
-
###
|
|
174
|
+
### 🌟 حمایت از پروژه
|
|
156
175
|
|
|
157
|
-
|
|
176
|
+
اگر این پکیج برای شما مفید بود، **لطفاً یک ستاره به مخزن GitHub بدهید ⭐**. این بهترین راه برای حمایت از پروژه و تشویق توسعهدهنده به بهبود آن است.
|
|
158
177
|
|
|
159
|
-
|
|
178
|
+
👉 **[GitHub Repository](https://github.com/javadSharifi/persian-number-input)**
|
|
160
179
|
|
|
161
|
-
|
|
180
|
+
از حمایت شما متشکریم! ❤️🚀
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
interface PersianNumberInputCustomProps {
|
|
3
|
+
value: string;
|
|
4
4
|
separatorCount?: number;
|
|
5
5
|
separatorChar?: string;
|
|
6
6
|
lang?: 'fa' | 'in' | 'en';
|
|
7
|
-
|
|
7
|
+
onChange: (value: string) => void;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
type AllowedInputProps = Pick<React.InputHTMLAttributes<HTMLInputElement>, 'className' | 'style' | 'placeholder' | 'disabled' | 'readOnly' | 'id' | 'name' | 'autoComplete' | 'autoFocus' | 'maxLength' | 'minLength' | 'required' | 'title' | 'dir' | 'onClick' | 'onKeyDown' | 'onKeyUp' | 'onKeyPress' | 'onFocus' | 'onBlur' | 'onMouseDown' | 'onMouseUp' | 'onMouseEnter' | 'onMouseLeave' | 'onTouchStart' | 'onTouchEnd' | 'onPaste'>;
|
|
10
|
+
export type PersianNumberInputProps = PersianNumberInputCustomProps & AllowedInputProps;
|
|
11
|
+
declare const PersianNumberInput: ({ value, separatorCount, separatorChar, lang, onChange, style, ...rest }: PersianNumberInputProps) => React.JSX.Element;
|
|
10
12
|
export default PersianNumberInput;
|
|
@@ -9,19 +9,29 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import React
|
|
12
|
+
import React from 'react';
|
|
13
13
|
import { toLocalizedDigits, groupDigits, convertToEnglishDigits } from '../utils/digitUtils';
|
|
14
|
+
// استایل پایه برای input
|
|
15
|
+
const baseInputStyle = {
|
|
16
|
+
border: '1px solid #ccc',
|
|
17
|
+
borderRadius: '4px',
|
|
18
|
+
padding: '8px 12px',
|
|
19
|
+
fontSize: '14px',
|
|
20
|
+
outline: 'none',
|
|
21
|
+
};
|
|
14
22
|
const PersianNumberInput = (_a) => {
|
|
15
|
-
var {
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
setValue(input);
|
|
20
|
-
if (onChangeValue)
|
|
21
|
-
onChangeValue(input);
|
|
22
|
-
}, [onChangeValue]);
|
|
23
|
-
const formattedValue = groupDigits(value, separatorCount, separatorChar);
|
|
23
|
+
var { value, separatorCount = 0, separatorChar = ',', lang = 'fa', onChange, style } = _a, rest = __rest(_a, ["value", "separatorCount", "separatorChar", "lang", "onChange", "style"]);
|
|
24
|
+
// تبدیل مقدار به فرمت نمایشی
|
|
25
|
+
const numericValue = convertToEnglishDigits(value).replace(/\D/g, '');
|
|
26
|
+
const formattedValue = groupDigits(numericValue, separatorCount, separatorChar);
|
|
24
27
|
const displayValue = lang === 'en' ? formattedValue : toLocalizedDigits(formattedValue, lang);
|
|
25
|
-
|
|
28
|
+
// هندل تغییرات
|
|
29
|
+
const handleChange = (e) => {
|
|
30
|
+
const newValue = convertToEnglishDigits(e.target.value).replace(/\D/g, '');
|
|
31
|
+
onChange(newValue);
|
|
32
|
+
};
|
|
33
|
+
const mergedStyle = Object.assign(Object.assign({}, baseInputStyle), style);
|
|
34
|
+
return React.createElement("input", Object.assign({ value: displayValue, onChange: handleChange, style: mergedStyle }, rest));
|
|
26
35
|
};
|
|
27
36
|
export default PersianNumberInput;
|
|
37
|
+
//# sourceMappingURL=PersianNumberInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PersianNumberInput.js","sourceRoot":"","sources":["../../src/components/PersianNumberInput.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AA4C7F,yBAAyB;AACzB,MAAM,cAAc,GAAwB;IACxC,MAAM,EAAE,gBAAgB;IACxB,YAAY,EAAE,KAAK;IACnB,OAAO,EAAE,UAAU;IACnB,QAAQ,EAAE,MAAM;IAChB,OAAO,EAAE,MAAM;CAClB,CAAC;AAKF,MAAM,kBAAkB,GAAG,CAAC,EAQF,EAAE,EAAE;QARF,EACxB,KAAK,EACL,cAAc,GAAG,CAAC,EAClB,aAAa,GAAG,GAAG,EACnB,IAAI,GAAG,IAAI,EACX,QAAQ,EACR,KAAK,OAEiB,EADnB,IAAI,cAPiB,yEAQ3B,CADU;IAEP,6BAA6B;IAC7B,MAAM,YAAY,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACtE,MAAM,cAAc,GAAG,WAAW,CAAC,YAAY,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;IAChF,MAAM,YAAY,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,iBAAiB,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IAE9F,eAAe;IACf,MAAM,YAAY,GAAG,CAAC,CAAsC,EAAE,EAAE;QAC5D,MAAM,QAAQ,GAAG,sBAAsB,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC3E,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACvB,CAAC,CAAC;IAEF,MAAM,WAAW,mCAAQ,cAAc,GAAK,KAAK,CAAE,CAAC;IAEpD,OAAO,6CACH,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,WAAW,IACd,IAAI,EACV,CAAC;AACP,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,iCAAiC,CAAC"}
|
package/dist/utils/digitUtils.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digitUtils.js","sourceRoot":"","sources":["../../src/utils/digitUtils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAgC;IACpD,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IACtD,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG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C;IACF,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AACvD,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "persian-number-input",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "React component for Persian, Indic, or English localized number input with customizable digit grouping",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"typings": "dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
7
10
|
"files": [
|
|
8
11
|
"dist"
|
|
9
12
|
],
|