Skip to content

Commit

Permalink
Add today method
Browse files Browse the repository at this point in the history
  • Loading branch information
nevadavid committed Jul 10, 2021
1 parent 2a20e3d commit e6c91f1
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
# nevnap

Névnap is a minimalist JavaScript library that displays hungarian namedays.

## Installation

```
npm i nevnap
```

## API

### Methods

#### `today(): string`

Getting namedays on the current day.

```javascript
import { today } from 'nevnap';

today(); // Tamás
```


#### `on(date: string): string`

Getting namedays on a specific date.

```javascript
import { on } from 'nevnap';

on('04-22'); // Csilla, Noémi
```

#### `to(name: string): string`

Getting date on a specific name.

```javascript
import { to } from 'nevnap';

to('Csilla'); // 04-22
```
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
"url": "git+https://github.com/nevadavid/nevnap.git"
},
"author": "David Uri",
"license": "ISC",
"keywords": [
"namedays",
"typescript"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/nevadavid/nevnap/issues"
},
Expand Down
29 changes: 27 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@ function getNumberFromIndex(index: number) {
return `${index + 1}`.padStart(2, '0');
}

export function on(date: string) {
/**
* Getting namedays on a specific date.
*
* @param {string} date
* @returns {string}
*/
export function on(date: string): string {
const [month, day] = date.split('-');
const monthIndex = parseInt(month, 10) - 1;
const dayIndex = parseInt(day, 10) - 1;

return namedays[monthIndex][dayIndex];
}

export function to(name: string) {
/**
* Getting date on a specific name.
*
* @param {string} name
* @returns {string}
*/
export function to(name: string): string | undefined {
for (const [monthIndex, month] of namedays.entries()) {
for (const [dayIndex, day] of month.entries()) {
const names = day.split(',');
Expand All @@ -26,3 +38,16 @@ export function to(name: string) {
}
}
}

/**
* Getting namedays on the current day.
*
* @returns {string}
*/
export function today(): string {
const now = new Date();
const month = now.getMonth();
const day = now.getDate();

return namedays[month][day - 1];
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"strict": true,
"declaration": true,
"esModuleInterop": true,
"downlevelIteration": true
"downlevelIteration": true,
"sourceMap": true
},
"include": [
"src/**/*",
Expand Down

0 comments on commit e6c91f1

Please sign in to comment.