A lightweight and versatile theme manager that allows you to set, get, and control themes across JavaScript, TypeScript, React, Next.js, and Node.js, including support for system default theme detection.
Using npm:
npm i @meshal10613/themeOr using yarn:
yarn add @meshal10613/themeCommonJS (Node.js)
const { setTheme, getTheme } = require('@meshal10613/theme');
setTheme("dark");
console.log(getTheme()); // "dark"ES Module (if your project uses "type": "module")
import { setTheme, getTheme } from '@meshal10613/theme';
setTheme("light");
console.log(getTheme()); // "light"square(number)
| Function | Parameter | Type | Description |
|---|---|---|---|
setTheme(theme) |
"light" |
"dark" |
"system" |
getTheme() |
- | "light" |
"dark" |
"light" — Light mode
"dark" — Dark mode
"system" — Follows system preference
setTheme("dark");
console.log(getTheme()); // "dark"
setTheme("system");
console.log(getTheme()); // "light" or "dark" depending on system settings- ✅ Works in frontend (React, Next.js) and backend (Node.js)
- ✅ Supports CommonJS and ES Modules
- ✅ Automatically respects system dark/light mode
- ✅ Minimal and dependency-free
- ✅ Simple API for quick theme control
✅ Minimal and dependency-free ✅ Type-safe input validation ✅ Works in both CommonJS and ESM environments ✅ Great for small math utilities or teaching purposes
theme/
├── src/
│ ├── index.ts # main entry
│ └── themeManager.ts # theme logic
├── dist/ # compiled files (CJS + ESM)
├── tests/
│ └── theme.test.ts # tests
├── package.json
├── tsconfig.json
└── README.mdMIT License © 2025 Syed Mohiuddin Meshal
NPM: https://www.npmjs.com/package/@meshal10613/theme
GitHub Repository: https://github.com/meshal10613/theme