persian-number-input 4.5.0 → 4.5.1

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.
Files changed (3) hide show
  1. package/README.fa.md +57 -3
  2. package/README.md +58 -3
  3. package/package.json +1 -1
package/README.fa.md CHANGED
@@ -42,7 +42,8 @@ English | [فارسی](./README.fa.md)
42
42
  - ⚡ **فقط ~۱ کیلوبایت** — بدون هیچ dependency اضافه
43
43
  - 🎯 **TypeScript** — تعریف تایپ کامل
44
44
  - 🔄 **حفظ موقعیت cursor** — بدون جهش هنگام فرمت‌دهی
45
- - **اعتبارسنجی min/max** — کنترل بازه مجاز و دقت اعشاری
45
+ - 📋 **مدیریت هوشمند paste** — محتوای چسبانده شده خودکار پالایش و تبدیل می‌شود
46
+ - ✅ **اعتبارسنجی min/max** — اعتبارسنجی نرم با `aria-invalid` و اعمال خودکار محدودیت در blur
46
47
  - ♿ **دسترس‌پذیر** — رعایت استانداردهای WCAG
47
48
 
48
49
  ---
@@ -203,12 +204,15 @@ function CustomInput() {
203
204
  value={value}
204
205
  onChange={onChange}
205
206
  onBlur={onBlur}
207
+ onPaste={onPaste}
206
208
  dir="rtl"
207
209
  />
208
210
  );
209
211
  }
210
212
  ```
211
213
 
214
+ Hook همچنین `isInvalid` (boolean) رو وقتی مقدار از `max` بیشتر بشه برمی‌گردونه، و `onPaste` برای مدیریت رویداد paste.
215
+
212
216
  ---
213
217
 
214
218
  ### ماشین‌حساب وام
@@ -266,11 +270,11 @@ function LoanCalculator() {
266
270
  | `suffix` | `string` | `undefined` | پسوند — مثل `تومان`، `ریال` |
267
271
  | `maxDecimals` | `number` | `undefined` | حداکثر رقم اعشار مجاز |
268
272
  | `min` | `number` | `undefined` | کمترین مقدار مجاز |
269
- | `max` | `number` | `undefined` | بیشترین مقدار مجاز |
273
+ | `max` | `number` | `undefined` | بیشترین مقدار مجاز — اعتبارسنجی نرم (علامت‌گذاری invalid، اعمال در blur) |
270
274
  | `showZero` | `boolean` | `false` | نمایش صفر وقتی ورودی خالی است |
271
275
  | `onValueChange` | `(value: string \| undefined) => void` | `undefined` | callback هنگام تغییر — همیشه ارقام انگلیسی برمی‌گرداند |
272
276
 
273
- تمام props استاندارد `<input>` مثل `className`، `style`، `placeholder` و `disabled` هم پشتیبانی می‌شن.
277
+ تمام props استاندارد `<input>` مثل `onChange`، `onKeyDown`، `onPaste`، `className`، `style`، `placeholder`dir` و `disabled` هم پشتیبانی می‌شن.
274
278
 
275
279
  ---
276
280
 
@@ -326,6 +330,56 @@ sanitizeNumericInput("۱۲۳abc۴۵۶", 2); // "123456"
326
330
  sanitizeNumericInput("12.345.67", 2); // "12.34"
327
331
  ```
328
332
 
333
+ #### `stripNonNumeric(str)`
334
+
335
+ حذف همه کاراکترهای غیرعددی و غیر از نقطه:
336
+
337
+ ```tsx
338
+ import { stripNonNumeric } from "persian-number-input";
339
+
340
+ stripNonNumeric("12abc34.56xyz"); // "1234.56"
341
+ ```
342
+
343
+ #### `normalizeDecimals(str)`
344
+
345
+ نگه داشتن فقط اولین نقطه اعشاری:
346
+
347
+ ```tsx
348
+ import { normalizeDecimals } from "persian-number-input";
349
+
350
+ normalizeDecimals("12.34.56"); // "12.3456"
351
+ ```
352
+
353
+ #### `stripLeadingZeros(str)`
354
+
355
+ حذف صفرهای اضافه ابتدای عدد:
356
+
357
+ ```tsx
358
+ import { stripLeadingZeros } from "persian-number-input";
359
+
360
+ stripLeadingZeros("001234.56"); // "1234.56"
361
+ ```
362
+
363
+ #### `applyDecimalPrecision(str, maxDecimals?)`
364
+
365
+ محدود کردن قسمت اعشار به تعداد رقم مشخص:
366
+
367
+ ```tsx
368
+ import { applyDecimalPrecision } from "persian-number-input";
369
+
370
+ applyDecimalPrecision("1234.5678", 2); // "1234.56"
371
+ ```
372
+
373
+ #### `roundToDecimals(value, maxDecimals?)`
374
+
375
+ مشابه `applyDecimalPrecision` — محدود کردن قسمت اعشار:
376
+
377
+ ```tsx
378
+ import { roundToDecimals } from "persian-number-input";
379
+
380
+ roundToDecimals("1234.5678", 2); // "1234.56"
381
+ ```
382
+
329
383
  ---
330
384
 
331
385
  ## 🎨 استایل‌دهی
package/README.md CHANGED
@@ -42,7 +42,9 @@ Form receives: "1234567"
42
42
  - ⚡ **~1KB gzipped** — zero extra dependencies, pure TypeScript
43
43
  - 🎯 **TypeScript** — full type definitions included
44
44
  - 🔄 **Cursor-position preservation** — no jump on re-format
45
- - **Min/max validation** — built-in range enforcement and decimal precision control
45
+ - 📋 **Smart paste handling** — pasted content is sanitized and auto-converted
46
+ - ✅ **Min/max validation** — soft enforcement with `aria-invalid` and automatic clamp on blur
47
+
46
48
  - ♿ **Accessible** — follows WCAG input best practices
47
49
 
48
50
  ---
@@ -203,12 +205,15 @@ function CustomInput() {
203
205
  value={value}
204
206
  onChange={onChange}
205
207
  onBlur={onBlur}
208
+ onPaste={onPaste}
206
209
  dir="rtl"
207
210
  />
208
211
  );
209
212
  }
210
213
  ```
211
214
 
215
+ The hook also returns `isInvalid` (boolean) when the value exceeds `max`, and `onPaste` for paste event handling.
216
+
212
217
  ---
213
218
 
214
219
  ## 🛠️ API Reference
@@ -225,11 +230,11 @@ function CustomInput() {
225
230
  | `suffix` | `string` | `undefined` | Currency or unit suffix (e.g. `تومان`, `ریال`) |
226
231
  | `maxDecimals` | `number` | `undefined` | Maximum allowed decimal places |
227
232
  | `min` | `number` | `undefined` | Minimum allowed value |
228
- | `max` | `number` | `undefined` | Maximum allowed value |
233
+ | `max` | `number` | `undefined` | Maximum allowed value — soft validation (marks invalid, clamps on blur) |
229
234
  | `showZero` | `boolean` | `false` | Display `0` instead of empty when value is zero |
230
235
  | `onValueChange` | `(value: string \| undefined) => void` | `undefined` | Fires on change — always returns English digits |
231
236
 
232
- All standard HTML `<input>` props (e.g. `className`, `style`, `placeholder`, `disabled`) are also supported.
237
+ All standard HTML `<input>` props are also supported, including `onChange`, `onKeyDown`, `onPaste`, `className`, `style`, `placeholder`, `dir`, and `disabled`.
233
238
 
234
239
  ---
235
240
 
@@ -285,6 +290,56 @@ sanitizeNumericInput("۱۲۳abc۴۵۶", 2); // "123456"
285
290
  sanitizeNumericInput("12.345.67", 2); // "12.34"
286
291
  ```
287
292
 
293
+ #### `stripNonNumeric(str)`
294
+
295
+ Remove all non-digit and non-dot characters.
296
+
297
+ ```tsx
298
+ import { stripNonNumeric } from "persian-number-input";
299
+
300
+ stripNonNumeric("12abc34.56xyz"); // "1234.56"
301
+ ```
302
+
303
+ #### `normalizeDecimals(str)`
304
+
305
+ Keep only the first decimal point.
306
+
307
+ ```tsx
308
+ import { normalizeDecimals } from "persian-number-input";
309
+
310
+ normalizeDecimals("12.34.56"); // "12.3456"
311
+ ```
312
+
313
+ #### `stripLeadingZeros(str)`
314
+
315
+ Strip leading zeros from a numeric string.
316
+
317
+ ```tsx
318
+ import { stripLeadingZeros } from "persian-number-input";
319
+
320
+ stripLeadingZeros("001234.56"); // "1234.56"
321
+ ```
322
+
323
+ #### `applyDecimalPrecision(str, maxDecimals?)`
324
+
325
+ Truncate fractional part to the specified decimal places.
326
+
327
+ ```tsx
328
+ import { applyDecimalPrecision } from "persian-number-input";
329
+
330
+ applyDecimalPrecision("1234.5678", 2); // "1234.56"
331
+ ```
332
+
333
+ #### `roundToDecimals(value, maxDecimals?)`
334
+
335
+ Alias for `applyDecimalPrecision` — truncate fractional part.
336
+
337
+ ```tsx
338
+ import { roundToDecimals } from "persian-number-input";
339
+
340
+ roundToDecimals("1234.5678", 2); // "1234.56"
341
+ ```
342
+
288
343
  ---
289
344
 
290
345
  ## 🎨 Styling
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "persian-number-input",
3
- "version": "4.5.0",
3
+ "version": "4.5.1",
4
4
  "description": "React component for Persian, Indic, or English localized number input with customizable digit grouping",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",