Skip to content

Commit

Permalink
updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
p333ter committed Dec 17, 2024
1 parent e09f5de commit c3ba50f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 54 deletions.
82 changes: 29 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,35 @@ A TypeScript/JavaScript library for generating, validating, and parsing Czech an

## Installation

```bash
```
npm install @ppasmik/birth-number-utils
```

## Usage

### Generate Birth Numbers

#### Czech Birth Number

```typescript
import { generateCzechBirthNumber } from '@ppasmik/birth-number-utils';
import { generateBirthNumber } from '@ppasmik/birth-number-utils';

// Generate a random Czech birth number
const randomCzechBirthNumber = generateCzechBirthNumber();
console.log('Random Czech Birth Number:', randomCzechBirthNumber); // e.g., "900720/3117"
// Generate a random birth number
const randomBirthNumber = generateBirthNumber();
console.log('Random Birth Number:', randomBirthNumber); // e.g., "900720/3117"

// Generate a Czech birth number with specific parameters
const customCzechBirthNumber = generateCzechBirthNumber({
// Generate a birth number with specific parameters
const customBirthNumber = generateBirthNumber({
gender: 'FEMALE',
birthDate: new Date(1990, 6, 20), // 20th July 1990
});
console.log('Custom Czech Birth Number:', customCzechBirthNumber); // e.g., "905720/3111"
```

#### Slovak Birth Number

```typescript
import { generateSlovakBirthNumber } from '@ppasmik/birth-number-utils';

// Generate a random Slovak birth number
const randomSlovakBirthNumber = generateSlovakBirthNumber();
console.log('Random Slovak Birth Number:', randomSlovakBirthNumber); // e.g., "900720/3117"

// Generate a Slovak birth number with specific parameters
const customSlovakBirthNumber = generateSlovakBirthNumber({
gender: 'MALE',
birthDate: new Date(1985, 11, 25), // 25th December 1985
});
console.log('Custom Slovak Birth Number:', customSlovakBirthNumber); // e.g., "851225/1234"
console.log('Custom Birth Number:', customBirthNumber); // e.g., "905720/3111"
```

### Validate Birth Numbers

```typescript
import { isValidBirthNumber } from '@ppasmik/birth-number-utils';

// Validate Czech or Slovak birth numbers
// Validate birth numbers
console.log(isValidBirthNumber('9007203117')); // true
console.log(isValidBirthNumber('9902291118')); // false (invalid date)
```
Expand All @@ -67,13 +48,14 @@ console.log(isValidBirthNumber('9902291118')); // false (invalid date)
```typescript
import { parseBirthNumber } from '@ppasmik/birth-number-utils';

// Parse a valid Czech or Slovak birth number
// Parse a valid birth number
const parsed = parseBirthNumber('9007203117');
if (parsed) {
console.log('Parsed Birth Number:', parsed);
// { birthDate: Date, gender: 'MALE' }
// { birthDate: Date, gender: 'MALE', age: 33, ... }
} else {
console.log('Invalid birth number.');
}

// Attempt to parse an invalid birth number
const invalidParse = parseBirthNumber('9902291118'); // 29th Feb 1999 does not exist
Expand All @@ -82,21 +64,19 @@ console.log('Parse Result:', invalidParse); // false

## Features

- **Generate** valid Czech and Slovak birth numbers.
- **Validate** existing birth numbers for correctness.
- **Parse** birth numbers to extract information such as birth date and gender.
- Supports both **formatted** (with `/`) and **raw** formats.
- **TypeScript support** with strong typing for all APIs.
- Comprehensive test coverage for edge cases.
- Uses **dayjs** for robust date handling.
- **Generate** valid birth numbers following Czech/Slovak standards
- **Validate** existing birth numbers for correctness
- **Parse** birth numbers to extract information such as birth date and gender
- Supports both **formatted** (with \`/\`) and **raw** formats
- **TypeScript support** with strong typing for all APIs
- Comprehensive test coverage for edge cases
- Uses **dayjs** for robust date handling

## API Reference

### Generators
### Generator

#### `generateCzechBirthNumber(options?: GeneratorOptions): string`
#### `generateSlovakBirthNumber(options?: GeneratorOptions): string`
#### \`generateBirthNumber(options?: GeneratorOptions): string\`

**Options**:

Expand All @@ -105,7 +85,7 @@ console.log('Parse Result:', invalidParse); // false

**Returns**:

- A birth number in the format `YYYYMM/DDXX` (Czech and Slovak standards).
- A birth number in the format `YYYYMM/DDXX` (following Czech/Slovak standards)

---

Expand All @@ -115,27 +95,27 @@ console.log('Parse Result:', invalidParse); // false

**Parameters**:

- `birthNumber`: A string containing the birth number to validate (formatted or raw).
- `birthNumber`: A string containing the birth number to validate (formatted or raw)

**Returns**:

- `true` if the birth number is valid.
- `false` otherwise.
- `true` if the birth number is valid
- `false` otherwise

---

### Parsers

#### `parseBirthNumber(birthNumber: string): { birthDate: Date; gender: string } | false`
#### `parseBirthNumber(birthNumber: string): BirthNumberDetails | false`

**Parameters**:

- `birthNumber`: A string containing the birth number to parse (formatted or raw).
- `birthNumber`: A string containing the birth number to parse (formatted or raw)

**Returns**:

- An object containing the `birthDate` and `gender` if valid.
- `false` if the birth number is invalid.
- An object containing birth date, gender, and other details if valid
- `false` if the birth number is invalid

---

Expand Down Expand Up @@ -168,16 +148,12 @@ rc.age(); // returns current age
rc.error(); // returns error message or null
```

---
## Contributing

We welcome contributions to enhance this library. If you find a bug or have an idea for improvement, feel free to open an issue or submit a pull request.

Please make sure to include tests for your changes.

---
## License

[MIT](https://choosealicense.com/licenses/mit/) © [Peter Pasmik]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ppasmik/birth-number-utils",
"version": "2.0.4",
"version": "2.0.5",
"description": "A TypeScript/JavaScript library for generating, validating, and parsing Czech and Slovak birth numbers (rodné číslo).",
"author": "Peter Pasmik",
"license": "MIT",
Expand Down

0 comments on commit c3ba50f

Please sign in to comment.