daily-color 1.0.1 → 1.2.0

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/.prettierignore CHANGED
@@ -1,2 +1,3 @@
1
+ dist
1
2
  package-lock.json
2
3
  CHANGELOG.md
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.2.0](https://github.com/aimeerivers/daily-color/compare/v1.1.0...v1.2.0) (2024-11-09)
4
+
5
+
6
+ ### Features
7
+
8
+ * Add an HTML page to show the current color of the day ([#8](https://github.com/aimeerivers/daily-color/issues/8)) ([e702363](https://github.com/aimeerivers/daily-color/commit/e702363cbb73e358742c2cb59874b9a2b55baa52))
9
+
10
+ ## [1.1.0](https://github.com/aimeerivers/daily-color/compare/v1.0.1...v1.1.0) (2024-11-09)
11
+
12
+
13
+ ### Features
14
+
15
+ * Provide a webpack bundle, for projects that don't use NPM ([#6](https://github.com/aimeerivers/daily-color/issues/6)) ([6d53597](https://github.com/aimeerivers/daily-color/commit/6d535973e9f8f601bf4e908911665eb9fda5ee67))
16
+
3
17
  ## [1.0.1](https://github.com/aimeerivers/daily-color/compare/v1.0.0...v1.0.1) (2024-11-09)
4
18
 
5
19
 
package/README.md CHANGED
@@ -10,12 +10,21 @@ npm install daily-color
10
10
 
11
11
  ## Use
12
12
 
13
- In a JavaScript/TypeScript project:
13
+ In a JavaScript/TypeScript project, using NPM:
14
14
 
15
15
  ```javascript
16
16
  const getDailyColor = require("daily-color");
17
17
 
18
- console.log("Today's color is: ", getDailyColor());
18
+ console.log("Today's color is:", getDailyColor());
19
+ ```
20
+
21
+ Directly loading the bundled JavaScript, for static projects not using NPM:
22
+
23
+ ```html
24
+ <script src="https://www.aimeerivers.com/daily-color/dist/daily-color.js"></script>
25
+ <script>
26
+ console.log("Today's color is:", getDailyColor());
27
+ </script>
19
28
  ```
20
29
 
21
30
  Using the CLI:
@@ -38,6 +47,12 @@ Run tests:
38
47
  npm run test
39
48
  ```
40
49
 
50
+ Compile the dist code, for projects without NPM:
51
+
52
+ ```bash
53
+ npm run webpack
54
+ ```
55
+
41
56
  The project uses ESLint and Prettier to ensure consistent coding standards.
42
57
 
43
58
  ```bash
@@ -0,0 +1 @@
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.getDailyColor=e():t.getDailyColor=e()}(self,(()=>{return t={237:t=>{t.exports=function(){const t=function(t){const e=t.getDate(),o=t.getMonth()+1,r=`${t.getFullYear()}-${o}-${e}`;let n=0;for(let t=0;t<r.length;t++)n=(n<<5)-n+r.charCodeAt(t),n|=0;return Math.abs(n)}(new Date),e=t>>8&255,o=255&t;return`#${(t>>16&255).toString(16).padStart(2,"0")}${e.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}}},e={},function o(r){var n=e[r];if(void 0!==n)return n.exports;var a=e[r]={exports:{}};return t[r](a,a.exports,o),a.exports}(237);var t,e}));
package/index.html ADDED
@@ -0,0 +1,59 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Daily Color</title>
7
+ <style>
8
+ body,
9
+ html {
10
+ align-items: center;
11
+ display: flex;
12
+ font-family: sans-serif;
13
+ height: 100%;
14
+ justify-content: center;
15
+ margin: 0;
16
+ }
17
+ #color {
18
+ border-radius: 0.2em;
19
+ color: #fff;
20
+ font-size: 4em;
21
+ font-weight: bold;
22
+ padding: 0.5em;
23
+ text-align: center;
24
+ }
25
+ #color.light {
26
+ background-color: rgba(0, 0, 0, 0.2);
27
+ box-shadow: 0 0 1em rgba(0, 0, 0, 0.3);
28
+ }
29
+ #color.dark {
30
+ background-color: rgba(255, 255, 255, 0.2);
31
+ box-shadow: 0 0 1em rgba(255, 255, 255, 0.3);
32
+ }
33
+ </style>
34
+ </head>
35
+
36
+ <body>
37
+ <div id="color"></div>
38
+ <script src="https://www.aimeerivers.com/daily-color/dist/daily-color.js"></script>
39
+ <script>
40
+ const color = getDailyColor();
41
+ const colorDiv = document.getElementById("color");
42
+ document.body.style.backgroundColor = color;
43
+ colorDiv.innerText = color;
44
+ colorDiv.style.color = color;
45
+
46
+ const brightness = getBrightness(color.substring(1));
47
+ if (brightness < 128) {
48
+ colorDiv.classList.add("dark");
49
+ } else {
50
+ colorDiv.classList.add("light");
51
+ }
52
+
53
+ function getBrightness(color) {
54
+ const rgb = color.match(/\w\w/g).map((hex) => parseInt(hex, 16));
55
+ return 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]; // Luminosity formula
56
+ }
57
+ </script>
58
+ </body>
59
+ </html>
package/index.js CHANGED
@@ -1,11 +1,29 @@
1
- const crypto = require("crypto");
2
-
3
1
  function getDailyColor() {
4
- const date = new Date().toISOString().split("T")[0];
5
- const hash = crypto.createHash("sha256").update(date).digest("hex");
6
- const color = `#${hash.slice(0, 6)}`;
2
+ const date = new Date();
3
+ const hash = getSimpleHash(date);
4
+
5
+ const r = (hash >> 16) & 0xff; // Red
6
+ const g = (hash >> 8) & 0xff; // Green
7
+ const b = hash & 0xff; // Blue
8
+
9
+ return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
10
+ }
11
+
12
+ function getSimpleHash(date) {
13
+ const day = date.getDate();
14
+ const month = date.getMonth() + 1; // getMonth() is zero-based
15
+ const year = date.getFullYear();
16
+
17
+ const dateString = `${year}-${month}-${day}`;
18
+ let hash = 0;
19
+
20
+ // Simple hash function: Iterate over each character in the date string
21
+ for (let i = 0; i < dateString.length; i++) {
22
+ hash = (hash << 5) - hash + dateString.charCodeAt(i); // hash * 31 + charCodeAt
23
+ hash |= 0; // Convert to 32-bit integer
24
+ }
7
25
 
8
- return color;
26
+ return Math.abs(hash);
9
27
  }
10
28
 
11
29
  module.exports = getDailyColor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "daily-color",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "Provides a unique hex code each day",
5
5
  "keywords": [
6
6
  "color",
@@ -29,10 +29,13 @@
29
29
  "lint": "eslint . --ext .ts,.js --fix",
30
30
  "lint:check": "eslint . --ext .ts,.js",
31
31
  "package:lint": "npx npm-package-json-lint .",
32
- "test": "node test/index.js"
32
+ "test": "node test/index.js",
33
+ "webpack": "npx webpack"
33
34
  },
34
35
  "devDependencies": {
35
- "eslint-config-plus-prettier": "1.7.1"
36
+ "eslint-config-plus-prettier": "1.7.1",
37
+ "webpack": "5.96.1",
38
+ "webpack-cli": "5.1.4"
36
39
  },
37
40
  "prettier": "eslint-config-plus-prettier/.prettierrc.json"
38
41
  }
@@ -0,0 +1,12 @@
1
+ const path = require("path");
2
+
3
+ module.exports = {
4
+ entry: "./index.js",
5
+ output: {
6
+ path: path.resolve(__dirname, "dist"),
7
+ filename: "daily-color.js",
8
+ library: "getDailyColor",
9
+ libraryTarget: "umd",
10
+ },
11
+ mode: "production",
12
+ };