π I Built a Lightweight JavaScript Library for Dark/Light Mode β DayniteJs π
As a frontend developer, one thing I kept repeating in projects was implementing light/dark mode toggle.
Every time:
- I rewrote the same logic
- Managed localStorage again
- Handled system preferences manually
So I thoughtβ¦
π Why not build a reusable solution?
Thatβs how DayniteJs was born.
π‘ What is DayniteJs?
DayniteJs is a lightweight JavaScript library that helps you easily:
- π Toggle between light & dark mode
- πΎ Save user preference automatically
- π₯οΈ Detect system theme (
prefers-color-scheme) - β‘ Use a simple, clean API
π¦ Installation
npm install daynitejs
π οΈ Usage
import DayniteJs from 'daynitejs';
const daynite = new DayniteJs();
daynite.toggle();
π¨ CSS Setup
[data-theme="light"] {
--bg-color: #ffffff;
--text-color: #1f2937;
}
[data-theme="dark"] {
--bg-color: #1f2937;
--text-color: #f3f4f6;
}
body {
background-color: var(--bg-color);
color: var(--text-color);
}
π§ What I Learned
Building this library taught me:
- How npm publishing works
- Handling real-world bugs after release
- Why versioning matters (you canβt overwrite versions π )
- Writing reusable and maintainable code
β οΈ Challenges I Faced
- Fixing bugs after publishing
- npm authentication issues
- Version conflicts
- Making the library work across different environments
π Try It Out
π npm: https://www.npmjs.com/package/daynitejs
π GitHub: https://github.com/suhaibmuhd01/DayniteJs
π¬ I Need Your Feedback
This is my first open-source library.
Iβd really appreciate:
- Feedback
- Suggestions
- Contributions
π Final Thoughts
This is just the beginning.
More tools and libraries coming soon π₯
If you like it, please β the repo and share!
β Question
How do you usually implement dark mode in your projects?
Letβs discuss π
Top comments (0)