daily-color 1.0.1 → 1.1.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,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.0](https://github.com/aimeerivers/daily-color/compare/v1.0.1...v1.1.0) (2024-11-09)
4
+
5
+
6
+ ### Features
7
+
8
+ * 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))
9
+
3
10
  ## [1.0.1](https://github.com/aimeerivers/daily-color/compare/v1.0.0...v1.0.1) (2024-11-09)
4
11
 
5
12
 
package/README.md CHANGED
@@ -15,7 +15,7 @@ In a JavaScript/TypeScript project:
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
19
  ```
20
20
 
21
21
  Using the CLI:
@@ -38,6 +38,12 @@ Run tests:
38
38
  npm run test
39
39
  ```
40
40
 
41
+ Compile the dist code, for projects without NPM:
42
+
43
+ ```bash
44
+ npm run webpack
45
+ ```
46
+
41
47
  The project uses ESLint and Prettier to ensure consistent coding standards.
42
48
 
43
49
  ```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.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.1.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
+ };