balacolor 3.0.0 β†’ 3.0.1

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 (3) hide show
  1. package/README.md +233 -0
  2. package/index.js +8 -8
  3. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,233 @@
1
+ # πŸ“¦ Creating & Publishing an npm Package (`balacolor`)
2
+
3
+ ---
4
+
5
+ ## 1️⃣ Create the Package Folder
6
+
7
+ 1. Create a folder named **`balacolor`** (this will be your **package name**).
8
+ 2. Inside the folder, create an **`index.js`** file.
9
+ 3. Initialize npm:
10
+
11
+ ```bash
12
+ npm init
13
+ ```
14
+
15
+ - Fill in **Name**, **Version**, and **Entrypoint** when prompted.
16
+
17
+ ---
18
+
19
+ ## 2️⃣ Create an npm Account
20
+
21
+ 1. Create a new account at **npmjs.com**.
22
+ 2. Log in to your account.
23
+ 3. Complete **2FA (Two-Factor Authentication)**.
24
+
25
+ ---
26
+
27
+ ## 3️⃣ Publish the Package to the npm Registry
28
+
29
+ > ⚠️ Make sure **Chrome** is set as your default browser before logging in, as I
30
+ > faced an issue with **2FA** in other browsers. Otherwise, you may get a
31
+ > **403** Forbidden error when running the **npm publish** command before
32
+ > completing 2FA.
33
+
34
+ ```bash
35
+ npm notice Publishing to https://registry.npmjs.org/ with tag latest and default access
36
+ npm ERR! code E403
37
+ npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/balacolor - Two-factor authentication or granular
38
+ access token with bypass 2fa enabled is required to publish packages.
39
+
40
+ npm ERR! 403 In most cases, you or one of your dependencies are requesting
41
+ npm ERR! 403 a package version that is forbidden by your security policy, or
42
+ npm ERR! 403 on a server you do not have access to.
43
+ ```
44
+
45
+ 1. Log in to npm from the VS code terminal:
46
+
47
+ ```bash
48
+ npm login
49
+ ```
50
+
51
+ 2. Publish the package:
52
+
53
+ ```bash
54
+ npm publish
55
+ ```
56
+
57
+ > πŸŽ‰ **Reload the npm website and search for your package. That’s it you’ve
58
+ > completed the process.πŸ‘πŸΌ**
59
+
60
+ ---
61
+
62
+ ## 4️⃣ Next version update & publish procedure (npm): Process for Updating the Package Version (Very Important)
63
+
64
+ You **must update the version** in `package.json` before publishing again.
65
+
66
+ You can do this **manually** or by using the commands below:
67
+
68
+ ### Version Types
69
+
70
+ - **Patch (1.0.1)** – Small bug fixes
71
+
72
+ ```bash
73
+ npm version patch
74
+ ```
75
+
76
+ - **Minor (1.1.0)** – New features (example: adding a new `"neon"` palette)
77
+
78
+ ```bash
79
+ npm version minor
80
+ ```
81
+
82
+ - **Major (2.0.0)** – Breaking changes
83
+
84
+ ```bash
85
+ npm version major
86
+ ```
87
+
88
+ ### Publish Again
89
+
90
+ ```bash
91
+ npm publish
92
+ ```
93
+
94
+ > πŸŽ‰ Now, your package got updated in the npm registry
95
+
96
+ ---
97
+
98
+ ## 5️⃣ How to uUpdate the Package in Your Project
99
+
100
+ After publishing a new version, update it in your project:
101
+
102
+ ```bash
103
+ npm install balacolor@latest
104
+ ```
105
+
106
+ ---
107
+
108
+ ## 6️⃣ Publishing Public vs Scoped Packages
109
+
110
+ ```bash
111
+ npm publish
112
+ npm publish --access public
113
+ ```
114
+
115
+ | Package Name Example | Command to Use | Result |
116
+ | -------------------- | ----------------------------- | --------------------------- |
117
+ | `balacolor` | `npm publish` | βœ… Public (Free) |
118
+ | `@johndoe/balacolor` | `npm publish` | ❌ Error 402 (Paid account) |
119
+ | `@johndoe/balacolor` | `npm publish --access public` | βœ… Public (Free) |
120
+
121
+ ---
122
+
123
+ ## πŸ’‘Basic Code to Publish on npm / Old Package Version
124
+
125
+ This is the **initial version** of the code that we will publish to npm.
126
+
127
+ ```jsx
128
+ const palettes = {
129
+ ocean: ["#0077be"],
130
+ sunset: ["#ff5f6d"],
131
+ forest: ["#2d5a27"],
132
+ };
133
+
134
+ functiongetPalette(name) {
135
+ const palette = palettes[name.toLowerCase()];
136
+ return palette ||"Palette not found. Try 'ocean', 'sunset', or 'forest'.";
137
+ }
138
+
139
+ // Required for npm export
140
+ module.exports = getPalette;
141
+ ```
142
+
143
+ ---
144
+
145
+ ## πŸ’‘ Updated Package Version
146
+
147
+ ```jsx
148
+ const palettes = {
149
+ ocean: ["#0077be"],
150
+ sunset: ["#ff5f6d"],
151
+ forest: ["#2d5a27"],
152
+ desert: ["#edc9af"],
153
+ mountain: ["#6b8e23"],
154
+ rose: ["#ff007f"],
155
+ yellow: ["#ffea00"],
156
+ purple: ["#9b30ff"],
157
+ };
158
+
159
+ functiongetPalette(name) {
160
+ const palette = palettes[name.toLowerCase()];
161
+ return (
162
+ palette ||
163
+ "Palette not found. Try 'ocean', 'sunset', 'forest', 'desert', 'mountain', 'rose', 'yellow', or 'purple'."
164
+ );
165
+ }
166
+
167
+ // Required for npm export
168
+ module.exports = getPalette;
169
+ ```
170
+
171
+ ---
172
+
173
+ ## πŸ’‘ Updated Package (`node_modules/balacolor/index.js`)
174
+
175
+ ---
176
+
177
+ ## 🧩 Using `balacolor` NPM Package in a React App
178
+
179
+ ### πŸ“¦ Install the Package
180
+
181
+ ```bash
182
+ npm install balacolor
183
+ ```
184
+
185
+ ---
186
+
187
+ ## πŸ§ͺ Example: `App.jsx`
188
+
189
+ ```jsx
190
+ import "./App.css";
191
+ import getPalette from "balacolor";
192
+
193
+ function App() {
194
+ // Get the "purple" color palette
195
+ const colors = getPalette("purple");
196
+
197
+ // Use the first color from the palette
198
+ const myColor = colors[0];
199
+
200
+ return (
201
+ <div style={{ padding: "50px" }}>
202
+ <h1 style={{ color: myColor }}>
203
+ Hello! This H1 is colored using Balacolor.
204
+ </h1>
205
+
206
+ <p>The hex code is: {myColor}</p>
207
+ </div>
208
+ );
209
+ }
210
+
211
+ export default App;
212
+ ```
213
+
214
+ ---
215
+
216
+ ## πŸ“„ `package.json` Dependencies
217
+
218
+ ```json
219
+ {
220
+ "dependencies": {
221
+ "balacolor": "^3.0.0",
222
+ "react": "^19.2.0",
223
+ "react-dom": "^19.2.0"
224
+ }
225
+ }
226
+ ```
227
+
228
+ ---
229
+
230
+ ## 🎨 Result
231
+
232
+ - The `<h1>` text color is dynamically applied from the **Balacolor palette**
233
+ - The selected hex code is displayed below the heading
package/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  const palettes = {
2
- "ocean": ["#0077be", "#5f9ea0", "#4682b4", "#b0c4de"],
3
- "sunset": ["#ff5f6d", "#ffc371", "#ff9a9e", "#fecfef"],
4
- "forest": ["#2d5a27", "#4b7a47", "#76a665", "#a8c69f"],
5
- "desert": ["#edc9af", "#c2b280", "#a67b5b", "#8b5e3c"],
6
- "mountain": ["#6b8e23", "#556b2f", "#8fbc8f", "#a9ba9d"],
7
- "rose": ["#ff007f", "#ff66a3", "#ff99c2", "#ffb3d1"],
8
- "yellow": ["#ffea00", "#fff176", "#fff59d", "#fff9c4"],
9
- "purple": ["#9b30ff", "#ba55d3", "#dda0dd", "#800080"],
2
+ "ocean": ["#0077be"],
3
+ "sunset": ["#ff5f6d"],
4
+ "forest": ["#2d5a27"],
5
+ "desert": ["#edc9af"],
6
+ "mountain": ["#6b8e23"],
7
+ "rose": ["#ff007f"],
8
+ "yellow": ["#ffea00"],
9
+ "purple": ["#9b30ff"],
10
10
  };
11
11
 
12
12
  function getPalette(name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "balacolor",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "demo project for npm registry",
5
5
  "main": "index.js",
6
6
  "scripts": {