Skip to content

Commit 8eaea36

Browse files
committed
chore: wip
1 parent 491a6a6 commit 8eaea36

File tree

22 files changed

+1317
-317
lines changed

22 files changed

+1317
-317
lines changed

docs/.vitepress/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// @ts-nocheck
33
// Generated by unplugin-vue-components
44
// Read more: https://github.com/vuejs/core/pull/3399
5+
// biome-ignore lint: disable
56
export {}
67

78
/* prettier-ignore */

docs/.vitepress/config.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,26 @@ const sidebar = [
5656
{ text: 'Intro', link: '/intro' },
5757
{ text: 'Install', link: '/install' },
5858
{ text: 'Usage', link: '/usage' },
59-
{ text: 'Config', link: '/config' },
59+
],
60+
},
61+
{
62+
text: 'Features',
63+
items: [
64+
{ text: 'Credit Card Formatting', link: '/features/credit-card' },
65+
{ text: 'Date Formatting', link: '/features/date' },
66+
{ text: 'Time Formatting', link: '/features/time' },
67+
{ text: 'Numerical Formatting', link: '/features/numeral' },
68+
{ text: 'Cursor Tracking', link: '/features/cursor' },
69+
],
70+
},
71+
{
72+
text: 'Vue Components',
73+
items: [
74+
{ text: 'Overview', link: '/vue/' },
75+
{ text: 'Credit Card Input', link: '/vue/credit-card' },
76+
{ text: 'Date Input', link: '/vue/date' },
77+
{ text: 'Time Input', link: '/vue/time' },
78+
{ text: 'Numeral Input', link: '/vue/numeral' },
6079
],
6180
},
6281
{ text: 'Showcase', link: '/Showcase' },

docs/config.md

Lines changed: 0 additions & 67 deletions
This file was deleted.

docs/features/credit-card.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Credit Card Formatting
2+
3+
Format and validate credit card numbers with support for various card types.
4+
5+
## Basic Usage
6+
7+
```typescript
8+
import { formatCreditCard, getCreditCardType, unformatCreditCard } from 'ts-inputs'
9+
10+
// Format a credit card number
11+
const formattedCard = formatCreditCard('4111111111111111')
12+
// Output: '4111 1111 1111 1111'
13+
14+
// Get the card type
15+
const cardType = getCreditCardType('4111111111111111')
16+
// Output: 'visa'
17+
18+
// Remove formatting
19+
const unformattedCard = unformatCreditCard('4111 1111 1111 1111')
20+
// Output: '4111111111111111'
21+
```
22+
23+
## Options
24+
25+
```typescript
26+
import { DefaultCreditCardDelimiter, formatCreditCard } from 'ts-inputs'
27+
28+
const options = {
29+
delimiter: DefaultCreditCardDelimiter, // defaults to ' '
30+
// other options...
31+
}
32+
33+
const formattedCard = formatCreditCard('4111111111111111', options)
34+
```
35+
36+
## Supported Card Types
37+
38+
- Visa
39+
- Mastercard
40+
- American Express
41+
- Discover
42+
- JCB
43+
- Diners Club
44+
- Maestro
45+
- UnionPay
46+
47+
## Validation
48+
49+
The library automatically validates card numbers using the Luhn algorithm and checks for valid card type patterns.
50+
51+
## Error Handling
52+
53+
```typescript
54+
try {
55+
const formattedCard = formatCreditCard('invalid-card-number')
56+
}
57+
catch (error) {
58+
console.error('Invalid card number:', error.message)
59+
}
60+
```

docs/features/cursor.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Cursor Tracking
2+
3+
Manage cursor position in input fields during formatting operations.
4+
5+
## Basic Usage
6+
7+
```typescript
8+
import { registerCursorTracker } from 'ts-inputs'
9+
10+
const inputElement = document.querySelector('input')
11+
12+
// Register cursor tracker
13+
const cleanup = registerCursorTracker(inputElement, {
14+
// tracking options...
15+
})
16+
17+
// Clean up when done
18+
cleanup()
19+
```
20+
21+
## Options
22+
23+
```typescript
24+
import { CursorTrackingOptions } from 'ts-inputs'
25+
26+
const options: CursorTrackingOptions = {
27+
preservePosition: true, // Whether to preserve cursor position after formatting
28+
trackSelection: true, // Whether to track text selection
29+
debounce: 100, // Debounce time in milliseconds
30+
}
31+
```
32+
33+
## Advanced Usage
34+
35+
### With Formatters
36+
37+
```typescript
38+
import { formatCreditCard, registerCursorTracker } from 'ts-inputs'
39+
40+
const inputElement = document.querySelector('input')
41+
42+
// Register cursor tracker with formatter
43+
const cleanup = registerCursorTracker(inputElement, {
44+
onFormat: value => formatCreditCard(value),
45+
preservePosition: true,
46+
})
47+
```
48+
49+
### With Multiple Fields
50+
51+
```typescript
52+
import { registerCursorTracker } from 'ts-inputs'
53+
54+
// Track multiple inputs
55+
const inputs = document.querySelectorAll('input[data-format]')
56+
57+
inputs.forEach((input) => {
58+
const cleanup = registerCursorTracker(input, {
59+
onFormat: (value) => {
60+
// Custom formatting logic based on data-format attribute
61+
const format = input.dataset.format
62+
return formatValue(value, format)
63+
},
64+
})
65+
})
66+
```
67+
68+
## Error Handling
69+
70+
```typescript
71+
try {
72+
const cleanup = registerCursorTracker(inputElement, options)
73+
}
74+
catch (error) {
75+
console.error('Failed to register cursor tracker:', error.message)
76+
}
77+
```

docs/features/date.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Date Formatting
2+
3+
Format and validate dates with support for various formats and locales.
4+
5+
## Basic Usage
6+
7+
```typescript
8+
import { formatDate, isValidDate, parseDate } from 'ts-inputs'
9+
10+
// Format a date
11+
const formattedDate = formatDate(new Date(), 'YYYY-MM-DD')
12+
// Output: '2024-03-21'
13+
14+
// Parse a date string
15+
const parsedDate = parseDate('2024-03-21', 'YYYY-MM-DD')
16+
// Output: Date object
17+
18+
// Validate a date
19+
const isValid = isValidDate('2024-03-21')
20+
// Output: true
21+
```
22+
23+
## Date Formats
24+
25+
The library supports various date formats:
26+
27+
- `YYYY-MM-DD` (ISO format)
28+
- `MM/DD/YYYY` (US format)
29+
- `DD/MM/YYYY` (European format)
30+
- `YYYY/MM/DD` (Japanese format)
31+
32+
## Locale Support
33+
34+
```typescript
35+
import { formatDate, setLocale } from 'ts-inputs'
36+
37+
// Set locale
38+
setLocale('en-US')
39+
40+
// Format with locale
41+
const formattedDate = formatDate(new Date(), 'LL', { locale: 'en-US' })
42+
// Output: 'March 21, 2024'
43+
```
44+
45+
## Date Validation
46+
47+
```typescript
48+
import { isValidDate, validateDate } from 'ts-inputs'
49+
50+
// Simple validation
51+
const isValid = isValidDate('2024-03-21')
52+
53+
// Advanced validation with options
54+
const validation = validateDate('2024-03-21', {
55+
minDate: new Date('2024-01-01'),
56+
maxDate: new Date('2024-12-31'),
57+
format: 'YYYY-MM-DD'
58+
})
59+
```
60+
61+
## Error Handling
62+
63+
```typescript
64+
try {
65+
const formattedDate = formatDate('invalid-date', 'YYYY-MM-DD')
66+
}
67+
catch (error) {
68+
console.error('Invalid date:', error.message)
69+
}
70+
```

0 commit comments

Comments
 (0)