DEV Community

Cover image for I Built a Lightweight JavaScript Library for Dark/Light Mode β€” DayniteJs πŸŒ—
suhaib Muhammad Babangda
suhaib Muhammad Babangda

Posted on

I Built a Lightweight JavaScript Library for Dark/Light Mode β€” DayniteJs πŸŒ—

πŸš€ 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
Enter fullscreen mode Exit fullscreen mode

πŸ› οΈ Usage

import DayniteJs from 'daynitejs';

const daynite = new DayniteJs();

daynite.toggle();
Enter fullscreen mode Exit fullscreen mode

🎨 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);
}
Enter fullscreen mode Exit fullscreen mode

🧠 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)