today-day 1.5.0 โ 1.5.2
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.
- package/README.md +79 -47
- package/index.js +58 -58
- package/languages.js +5 -5
- package/package.json +43 -43
package/README.md
CHANGED
|
@@ -1,74 +1,106 @@
|
|
|
1
|
-
#
|
|
1
|
+
# today-day ๐
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/today-day)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
A simple, lightweight JavaScript library to quickly get the current day of the week, calculate future or past days, and generate random days.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
Whether you are working in Node.js or directly in the browser, `today-day` comes with built-in Internationalization (i18n) support, so you can easily localize your days without pulling in a massive date-formatting library like Moment.js.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
---
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
## โจ Features
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
- **Lightweight & Fast:** Get the day of the week instantly without heavy date manipulation overhead.
|
|
15
|
+
- **Time Travel:** Easily add or subtract days to find out what day it will be in the future or was in the past.
|
|
16
|
+
- **Built-in i18n:** Native support for English (`en_US`), Hebrew (`he_IL`), and French (`fr_FR`).
|
|
17
|
+
- **Universal:** Works seamlessly in Node.js (v4.9.1+) and directly in the browser via CDN.
|
|
18
|
+
- **Fully Tested:** Backed by Jest to ensure rock-solid reliability.
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
---
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
## ๐ฆ Installation
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
**Using npm:**
|
|
25
|
+
```bash
|
|
26
|
+
npm install today-day
|
|
27
|
+
```
|
|
20
28
|
|
|
29
|
+
**Using a CDN (Browser):**
|
|
30
|
+
```html
|
|
31
|
+
<script src="[https://cdn.jsdelivr.net/npm/today-day@1.5.1/dist/today-day.min.js](https://cdn.jsdelivr.net/npm/today-day@1.5.1/dist/today-day.min.js)"></script>
|
|
21
32
|
```
|
|
22
|
-
const todayDay = require('today-day')
|
|
23
33
|
|
|
24
|
-
|
|
25
|
-
todayDay.today();
|
|
34
|
+
---
|
|
26
35
|
|
|
27
|
-
|
|
28
|
-
todayDay.random();
|
|
36
|
+
## ๐ Quick Start & API
|
|
29
37
|
|
|
30
|
-
|
|
31
|
-
todayDay.addDays(4);
|
|
38
|
+
### Basic Usage
|
|
32
39
|
|
|
33
|
-
|
|
34
|
-
todayDay
|
|
40
|
+
```javascript
|
|
41
|
+
const todayDay = require('today-day');
|
|
35
42
|
|
|
43
|
+
// Get the current day
|
|
44
|
+
console.log(todayDay.today());
|
|
45
|
+
// => "Friday"
|
|
36
46
|
|
|
37
|
-
//
|
|
38
|
-
todayDay.
|
|
47
|
+
// Get a completely random day of the week
|
|
48
|
+
console.log(todayDay.random());
|
|
49
|
+
// => "Monday"
|
|
50
|
+
```
|
|
39
51
|
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
### Adding & Subtracting Days
|
|
53
|
+
Need to know what day it will be in 4 days, or what day it was 29 days ago?
|
|
42
54
|
|
|
43
|
-
|
|
44
|
-
|
|
55
|
+
```javascript
|
|
56
|
+
// 4 days from today
|
|
57
|
+
console.log(todayDay.addDays(4));
|
|
58
|
+
// => "Tuesday"
|
|
45
59
|
|
|
60
|
+
// 29 days ago
|
|
61
|
+
console.log(todayDay.addDays(-29));
|
|
62
|
+
// => "Wednesday"
|
|
46
63
|
```
|
|
47
64
|
|
|
48
|
-
|
|
65
|
+
### Localization (i18n)
|
|
66
|
+
Easily switch between supported languages.
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
// Set language to Hebrew
|
|
70
|
+
todayDay.locale('he_IL');
|
|
71
|
+
|
|
72
|
+
// Get today's day in Hebrew
|
|
73
|
+
console.log(todayDay.today());
|
|
74
|
+
// => "ืฉืืฉื"
|
|
75
|
+
|
|
76
|
+
// See all currently supported language codes
|
|
77
|
+
console.log(todayDay.getSupportedLanguages());
|
|
78
|
+
// => ["en_US", "fr_FR", "he_IL"]
|
|
49
79
|
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## ๐งช Testing
|
|
84
|
+
|
|
85
|
+
This project uses Jest for testing. To run the test suite locally:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
50
88
|
npm run test
|
|
51
89
|
```
|
|
52
90
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
- Added addDays function
|
|
68
|
-
- 1.1.1
|
|
69
|
-
- Changed function name setLanguages to locale
|
|
70
|
-
- Removed todayUpperCase
|
|
71
|
-
- Removed todayLowerCase
|
|
72
|
-
- 1.1.0
|
|
73
|
-
- Added Jest library for tests.
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## ๐ค Contributing
|
|
94
|
+
|
|
95
|
+
Contributions, issues, and feature requests are welcome!
|
|
96
|
+
|
|
97
|
+
1. Fork the project.
|
|
98
|
+
2. Clone your fork.
|
|
99
|
+
3. Install dependencies: `npm install`
|
|
100
|
+
4. Make your changes and write tests if applicable.
|
|
101
|
+
5. Ensure tests pass: `npm run test`
|
|
102
|
+
6. Create a Pull Request!
|
|
103
|
+
|
|
104
|
+
## ๐ License
|
|
74
105
|
|
|
106
|
+
This project is [MIT](https://opensource.org/licenses/MIT) licensed.
|
package/index.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
const languages = require('./languages');
|
|
2
|
-
|
|
3
|
-
const supportedLanguage = ['en_US', 'fr_FR', 'he_IL'];
|
|
4
|
-
let translateLanguage = languages.en_US;
|
|
5
|
-
|
|
6
|
-
const privateMethods = {
|
|
7
|
-
getDay: (dayNumber) => {
|
|
8
|
-
const day = dayNumber !== undefined ? dayNumber : new Date().getDay();
|
|
9
|
-
return translateLanguage[day];
|
|
10
|
-
},
|
|
11
|
-
|
|
12
|
-
calculateAddedDays: (number) => {
|
|
13
|
-
return (new Date().getDay() + number) % 7;
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const publicMethods = {
|
|
18
|
-
getSupportedLanguages: () => {
|
|
19
|
-
return supportedLanguage;
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
locale: (language) => {
|
|
23
|
-
if (language && supportedLanguage.includes(language)) {
|
|
24
|
-
translateLanguage = languages[language];
|
|
25
|
-
} else {
|
|
26
|
-
throw Error('Not supported language');
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
today: () => {
|
|
31
|
-
return privateMethods.getDay();
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
random: () => {
|
|
35
|
-
const randomDay = Math.floor(Math.random() * 6);
|
|
36
|
-
return privateMethods.getDay(randomDay);
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
addDays: (number) => {
|
|
40
|
-
let dayAfterAdded;
|
|
41
|
-
if (number !== undefined && !Number.isNaN(number)) {
|
|
42
|
-
let daysToAdd = number;
|
|
43
|
-
if (number < 0) {
|
|
44
|
-
daysToAdd = ((number % 7) + 7) % 7;
|
|
45
|
-
}
|
|
46
|
-
const dayToGet = privateMethods.calculateAddedDays(daysToAdd);
|
|
47
|
-
dayAfterAdded = privateMethods.getDay(dayToGet);
|
|
48
|
-
} else {
|
|
49
|
-
throw Error('Not a number!');
|
|
50
|
-
}
|
|
51
|
-
return dayAfterAdded;
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
module.exports = publicMethods;
|
|
56
|
-
if (typeof window !== 'undefined') {
|
|
57
|
-
window.todayDay = publicMethods;
|
|
58
|
-
}
|
|
1
|
+
const languages = require('./languages');
|
|
2
|
+
|
|
3
|
+
const supportedLanguage = ['en_US', 'fr_FR', 'he_IL'];
|
|
4
|
+
let translateLanguage = languages.en_US;
|
|
5
|
+
|
|
6
|
+
const privateMethods = {
|
|
7
|
+
getDay: (dayNumber) => {
|
|
8
|
+
const day = dayNumber !== undefined ? dayNumber : new Date().getDay();
|
|
9
|
+
return translateLanguage[day];
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
calculateAddedDays: (number) => {
|
|
13
|
+
return (new Date().getDay() + number) % 7;
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const publicMethods = {
|
|
18
|
+
getSupportedLanguages: () => {
|
|
19
|
+
return supportedLanguage;
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
locale: (language) => {
|
|
23
|
+
if (language && supportedLanguage.includes(language)) {
|
|
24
|
+
translateLanguage = languages[language];
|
|
25
|
+
} else {
|
|
26
|
+
throw Error('Not supported language');
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
today: () => {
|
|
31
|
+
return privateMethods.getDay();
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
random: () => {
|
|
35
|
+
const randomDay = Math.floor(Math.random() * 6);
|
|
36
|
+
return privateMethods.getDay(randomDay);
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
addDays: (number) => {
|
|
40
|
+
let dayAfterAdded;
|
|
41
|
+
if (number !== undefined && !Number.isNaN(number)) {
|
|
42
|
+
let daysToAdd = number;
|
|
43
|
+
if (number < 0) {
|
|
44
|
+
daysToAdd = ((number % 7) + 7) % 7;
|
|
45
|
+
}
|
|
46
|
+
const dayToGet = privateMethods.calculateAddedDays(daysToAdd);
|
|
47
|
+
dayAfterAdded = privateMethods.getDay(dayToGet);
|
|
48
|
+
} else {
|
|
49
|
+
throw Error('Not a number!');
|
|
50
|
+
}
|
|
51
|
+
return dayAfterAdded;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
module.exports = publicMethods;
|
|
56
|
+
if (typeof window !== 'undefined') {
|
|
57
|
+
window.todayDay = publicMethods;
|
|
58
|
+
}
|
package/languages.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
en_US: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
|
3
|
-
fr_FR: ['dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'samedi'],
|
|
4
|
-
he_IL: ['ืจืืฉืื', 'ืฉื ื', 'ืฉืืืฉื', 'ืจืืืขื', 'ืืืืฉื', 'ืฉืืฉื', 'ืฉืืช'],
|
|
5
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
en_US: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
|
3
|
+
fr_FR: ['dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'samedi'],
|
|
4
|
+
he_IL: ['ืจืืฉืื', 'ืฉื ื', 'ืฉืืืฉื', 'ืจืืืขื', 'ืืืืฉื', 'ืฉืืฉื', 'ืฉืืช'],
|
|
5
|
+
};
|
package/package.json
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "today-day",
|
|
3
|
-
"version": "1.5.
|
|
4
|
-
"description": "Get today day",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "jest",
|
|
8
|
-
"test:coverage": "jest --coverage",
|
|
9
|
-
"eslint": "eslint index.js",
|
|
10
|
-
"build": "browserify index.js > dist/today-day.min.js -p tinyify",
|
|
11
|
-
"npm-publish": "npm publish --access public"
|
|
12
|
-
},
|
|
13
|
-
"homepage": "https://github.com/davidfrid02/today-day#readme",
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "https://github.com/davidfrid02/today-day.git"
|
|
17
|
-
},
|
|
18
|
-
"keywords": [
|
|
19
|
-
"date",
|
|
20
|
-
"day",
|
|
21
|
-
"today",
|
|
22
|
-
"day-today",
|
|
23
|
-
"today-day",
|
|
24
|
-
"random-day"
|
|
25
|
-
],
|
|
26
|
-
"author": "",
|
|
27
|
-
"license": "ISC",
|
|
28
|
-
"prettier": {
|
|
29
|
-
"trailingComma": "es5",
|
|
30
|
-
"tabWidth": 4,
|
|
31
|
-
"semi": true,
|
|
32
|
-
"singleQuote": true,
|
|
33
|
-
"printWidth": 120
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"eslint": "^7.32.0",
|
|
37
|
-
"eslint-config-airbnb-base": "^14.2.1",
|
|
38
|
-
"eslint-plugin-import": "^2.24.2",
|
|
39
|
-
"husky": "^7.0.2",
|
|
40
|
-
"jest": "^27.1.1",
|
|
41
|
-
"tinyify": "^3.0.0"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "today-day",
|
|
3
|
+
"version": "1.5.2",
|
|
4
|
+
"description": "Get today day",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest",
|
|
8
|
+
"test:coverage": "jest --coverage",
|
|
9
|
+
"eslint": "eslint index.js",
|
|
10
|
+
"build": "browserify index.js > dist/today-day.min.js -p tinyify",
|
|
11
|
+
"npm-publish": "npm publish --access public"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/davidfrid02/today-day#readme",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/davidfrid02/today-day.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"date",
|
|
20
|
+
"day",
|
|
21
|
+
"today",
|
|
22
|
+
"day-today",
|
|
23
|
+
"today-day",
|
|
24
|
+
"random-day"
|
|
25
|
+
],
|
|
26
|
+
"author": "",
|
|
27
|
+
"license": "ISC",
|
|
28
|
+
"prettier": {
|
|
29
|
+
"trailingComma": "es5",
|
|
30
|
+
"tabWidth": 4,
|
|
31
|
+
"semi": true,
|
|
32
|
+
"singleQuote": true,
|
|
33
|
+
"printWidth": 120
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"eslint": "^7.32.0",
|
|
37
|
+
"eslint-config-airbnb-base": "^14.2.1",
|
|
38
|
+
"eslint-plugin-import": "^2.24.2",
|
|
39
|
+
"husky": "^7.0.2",
|
|
40
|
+
"jest": "^27.1.1",
|
|
41
|
+
"tinyify": "^3.0.0"
|
|
42
|
+
}
|
|
43
|
+
}
|