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.
Files changed (4) hide show
  1. package/README.md +79 -47
  2. package/index.js +58 -58
  3. package/languages.js +5 -5
  4. package/package.json +43 -43
package/README.md CHANGED
@@ -1,74 +1,106 @@
1
- # Project Title
1
+ # today-day ๐Ÿ“…
2
2
 
3
- Simple library to get today day.
3
+ [![npm version](https://img.shields.io/npm/v/today-day.svg)](https://www.npmjs.com/package/today-day)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
5
 
5
- ## Description
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
- When you dont know what day today, use this library.
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
- ### Dependencies
10
+ ---
10
11
 
11
- - Node.js 4.9.1+
12
+ ## โœจ Features
12
13
 
13
- ### Installing
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
- - npm i today-day
20
+ ---
16
21
 
17
- ### Executing program
22
+ ## ๐Ÿ“ฆ Installation
18
23
 
19
- - How to run the program
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
- //Friday
25
- todayDay.today();
34
+ ---
26
35
 
27
- //Monday
28
- todayDay.random();
36
+ ## ๐Ÿš€ Quick Start & API
29
37
 
30
- //Tuesday
31
- todayDay.addDays(4);
38
+ ### Basic Usage
32
39
 
33
- //Wednesday
34
- todayDay.addDays(-29);
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
- //set language to hebrew
38
- todayDay.locale('he_IL');
47
+ // Get a completely random day of the week
48
+ console.log(todayDay.random());
49
+ // => "Monday"
50
+ ```
39
51
 
40
- //ืฉื™ืฉื™
41
- todayDay.today();
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
- //["en_US", "fr_FR", "he_IL"]
44
- todayDay.getSupportedLanguages();
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
- - How to run tests
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
- ## i18n
54
- - English (en_US)
55
- - Hebrew (he_IL)
56
- - French (fr_FR)
57
-
58
- ## Version History
59
-
60
- - 1.5.0
61
- - Added browser Support
62
- - 1.2.0
63
- - Algorithm Improvements
64
- - Changed Languages object
65
- - 1.1.2
66
- - Added random function
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.0",
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
+ }