Skip to content

Commit dd22d60

Browse files
committed
docs: add main documentation index
1 parent 4e2334d commit dd22d60

3 files changed

Lines changed: 208 additions & 54 deletions

File tree

README.md

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,18 @@
11
# Patcode
22

3-
Patcode is a generator of short, memorable, human-friendly numeric codes based on structured patterns.
4-
Perfect for **OTP**, **SMS verification**, **2FA**, **PIN codes**, onboarding steps, and any UX-friendly confirmation flows.
3+
Patcode is a generator of short, structured, human-friendly numeric codes designed for high usability and strong memorability.
4+
The library produces predictable, readable patterns suitable for authentication flows such as OTP, SMS verification, 2FA, PIN codes, and onboarding confirmation steps.
55

6-
---
6+
## Documentation
77

8-
## Features
8+
The full documentation is available in the /docs directory:
99

10-
- Generates **4-digit** and **6-digit** human-friendly codes
11-
- Pattern-based generation: **AABB**, **ABAB**, **ABBA**, **AAAB**, **ABBB**, **AABC**, **ABBC**,
12-
plus **ABABAB**, **AABBCC**, **AAABBB**, **ABBABB**, **ABCABC**, **ABCCBA**
13-
- Filters out simple sequences (`1234`, `9876`) and repeated digits (`0000`)
14-
- Fully customizable strategies (your own generator logic)
15-
- Optional custom RNG (for cryptographic random or deterministic tests)
16-
17-
---
18-
19-
## Installation
20-
21-
```bash
22-
npm install patcode
23-
# or
24-
yarn add patcode
25-
# or
26-
pnpm add patcode
27-
```
28-
29-
---
30-
31-
## Usage
32-
33-
### Basic
34-
35-
```ts
36-
import { generateCode } from 'patcode'
37-
38-
generateCode() // "535353" (6-digit, mixed patterns)
39-
```
40-
41-
### 4-digit code
42-
43-
```ts
44-
generateCode({ length: 4 }) // "5566"
45-
```
46-
47-
## Custom Strategy
48-
49-
```ts
50-
generateCode({
51-
length: 6,
52-
strategy: 'custom',
53-
customStrategy(ctx) {
54-
// example: code starting with 9, then ABAB
55-
const [A, B] = ctx.pickTwoDifferentDigits()
56-
return ctx.fromDigits(['9', A, B, A, B, A])
57-
},
58-
})
59-
```
10+
- [Introduction](./docs/index.md)
11+
- [Generation Strategies](./docs/strategies.md)
12+
- [Code Analysis](./docs/analyze.md)
13+
- [RNG System](./docs/rng.md)
14+
- [Configuration Options](./docs/configuration.md)
15+
- [Custom Strategies](./docs/custom-strategies.md)
6016

6117
## License
6218

docs/index.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# Patcode Documentation
2+
3+
Patcode is a human-centric numeric code generator designed for OTP, SMS verification, 2FA systems, banking environments, onboarding flows, and any scenario that requires short and memorable codes.
4+
The library focuses on generating structured, high-readability numeric patterns while maintaining configurable security guarantees.
5+
6+
**Patcode provides**:
7+
8+
- Human-friendly numeric code generation (4-digit and 6-digit)
9+
- Pattern-based strategies (AABB, ABAB, wave, mirror, escalator)
10+
- Configurable strictness levels and security modes
11+
- Adaptive UX profiles (children, elderly, asia, latam)
12+
- Code analysis engine (entropy, memorability, collision risk)
13+
- Secure RNG abstraction with fallback logic
14+
- Fully typed API with TypeScript support
15+
- Works in Node.js, browsers, Deno, Bun, Cloudflare Workers
16+
17+
## Why Patcode
18+
19+
Memorability and predictability often conflict in numeric code generation.
20+
Patcode attempts to balance these competing goals by providing:
21+
22+
1. Predictably structured patterns for user experience
23+
2. Customizable entropy and strictness levels
24+
3. Optional banking-grade security modes
25+
4. Transparent analysis tools for evaluating generated codes
26+
27+
## Installation
28+
29+
Patcode supports all major JavaScript runtimes.
30+
31+
### Node.js / Bun / Deno
32+
33+
```bash
34+
npm install patcode
35+
```
36+
37+
or
38+
39+
```bash
40+
yarn add patcode
41+
```
42+
43+
or
44+
45+
```bash
46+
pnpm add patcode
47+
```
48+
49+
or
50+
51+
```bash
52+
bun add patcode
53+
```
54+
55+
ESM:
56+
57+
```js
58+
import { generateCode } from 'patcode'
59+
```
60+
61+
CJS:
62+
63+
```js
64+
const { generateCode } = require('patcode')
65+
```
66+
67+
## Quick Start
68+
69+
Generate a 6-digit code:
70+
71+
```js
72+
import { generateCode } from 'patcode'
73+
74+
const code = generateCode()
75+
```
76+
77+
Generate a 4-digit code
78+
79+
```js
80+
generateCode({ length: 4 })
81+
```
82+
83+
Use a specific pattern strategy
84+
85+
```js
86+
generateCode({ strategy: 'wave' })
87+
```
88+
89+
Analyze a code
90+
91+
```js
92+
import { analyze } from 'patcode'
93+
94+
const result = analyze('5566')
95+
```
96+
97+
## Features Overview
98+
99+
### Pattern-Based Code Generation
100+
101+
Patcode includes multiple predefined strategies:
102+
103+
- mixed
104+
- pairs
105+
- triples
106+
- mirror
107+
- wave
108+
- escalator
109+
- pairWave
110+
- custom
111+
112+
Patterns include:
113+
114+
- AABB
115+
- ABAB
116+
- ABBA
117+
- AAAB
118+
- ABCABC
119+
- ABCCBA
120+
121+
These strategies produce codes with predictable structures, improving user memorability.
122+
123+
### Code Analysis Engine
124+
125+
Patcode includes a built-in analysis module that identifies:
126+
127+
- Shannon entropy (normalized per code length)
128+
- Memorability score
129+
- Collision risk
130+
- Ascending or descending sequences
131+
- Structural patterns
132+
- Group segmentation
133+
134+
This module can be used for research, reporting, debugging, or building custom rules for OTP distribution.
135+
136+
### Adaptive User Profiles
137+
138+
Different user groups memorize patterns differently.
139+
Each profile adjusts:
140+
141+
- allowed patterns
142+
- memorability weighting
143+
- entropy thresholds
144+
- sequence filtering
145+
- digit selection preferences
146+
147+
### Security Modes
148+
149+
Patcode offers specialized operational modes:
150+
151+
- normal
152+
- banking
153+
- enterprise
154+
- ultra-secure
155+
156+
High-security modes reduce pattern predictability, avoid digit repetition, and increase entropy guarantees.
157+
158+
### Universal RNG Engine
159+
160+
Patcode includes an abstraction layer for secure random number generation.
161+
162+
Supported RNG sources:
163+
164+
- Web Crypto API
165+
- Node.js crypto.webcrypto
166+
- Custom user-provided RNG
167+
- Math.random fallback (only when explicitly allowed)
168+
169+
Secure RNG is automatically selected when available.
170+
171+
## When to Use Patcode
172+
173+
Patcode is particularly effective in:
174+
175+
- SMS verification workflows
176+
- Password reset flows
177+
- 2FA onboarding
178+
- Banking transaction approvals
179+
- One-time PIN generation
180+
- IoT device pairing
181+
- Access control terminals
182+
- Authentication systems with UX constraints
183+
184+
If your system requires codes that are both human-friendly and structurally meaningful, Patcode is a suitable solution.
185+
186+
## When Not to Use Patcode
187+
188+
Patcode is not intended for:
189+
190+
- Cryptographically guaranteed high-entropy tokens
191+
- Long-form UUID or SHA-based identifiers
192+
- Authentication flows that prohibit human-readable structure
193+
- Encoding arbitrary data into numeric strings
194+
195+
For these cases, consider using UUID v4 or crypto-based random generators.

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)