balacolor 1.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.
- package/README.md +233 -0
- package/index.js +9 -4
- 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,17 @@
|
|
|
1
1
|
const palettes = {
|
|
2
|
-
"ocean": ["#0077be"
|
|
3
|
-
"sunset": ["#ff5f6d"
|
|
4
|
-
"forest": ["#2d5a27",
|
|
2
|
+
"ocean": ["#0077be"],
|
|
3
|
+
"sunset": ["#ff5f6d"],
|
|
4
|
+
"forest": ["#2d5a27"],
|
|
5
|
+
"desert": ["#edc9af"],
|
|
6
|
+
"mountain": ["#6b8e23"],
|
|
7
|
+
"rose": ["#ff007f"],
|
|
8
|
+
"yellow": ["#ffea00"],
|
|
9
|
+
"purple": ["#9b30ff"],
|
|
5
10
|
};
|
|
6
11
|
|
|
7
12
|
function getPalette(name) {
|
|
8
13
|
const palette = palettes[name.toLowerCase()];
|
|
9
|
-
return palette || "Palette not found. Try 'ocean', 'sunset', or '
|
|
14
|
+
return palette || "Palette not found. Try 'ocean', 'sunset', 'forest', 'desert', 'mountain', 'rose', 'yellow', or 'purple'.";
|
|
10
15
|
}
|
|
11
16
|
|
|
12
17
|
// This is the important part for npm!
|