luci-utils-tejpal
v1.0.1
Published
Luci utility functions - formatList, jwtDecode and more
Readme
luci-utils
Tejpal Singh
📦 Install
# Local project mein use karne ke liye
npm install ../luci\ Edtior
# Ya npm publish karne ke baad
npm install luci-utils🚀 Usage
// CommonJS (Node.js)
const { formatList, jwtDecode } = require("luci-utils");
// ES Module (React/Next.js)
import { formatList, jwtDecode } from "luci-utils";📝 formatList(text, options?)
HTML ya plain text ko display ke liye format karta hai. Chat messages, comments, descriptions ke liye best.
import { formatList } from "luci-utils";
// Basic use
const html = formatList("<p>Hello <span data-id='user1'>@Tejpal</span></p>");
// Custom userId pass karo
const html = formatList(text, { currentUserId: "user123" });React / Next.js Use (dangerouslySetInnerHTML)
Kyunki formatList proper HTML tags return karta hai, isliye React mein directly {formatList(text)} likhne se waisa hi text dikhega. Ise proper render karne ke liye dangerouslySetInnerHTML use karein:
import { formatList } from "luci-utils"; // (ya aapka npm package name luci-utils-tejpal)
export default function TaskCard({ task }) {
return (
<div
className="prose list-disc subtext-1-weight-medium list-inside pl-0 space-y-1 max-w-full break-words"
dangerouslySetInnerHTML={{ __html: formatList(task.Task) }}
/>
);
}Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| currentUserId | string | auto (from token) | Logged-in user ka ID |
| mentionColor | string | #5D56BD | Dusron ke mention ka color |
| selfMentionColor | string | #FAA307 | Apne aap ke mention ka color |
Features
- ✅ Images & documents remove karta hai
- ✅ Mentions highlight karta hai
- ✅ URLs ko clickable links banata hai
- ✅ Lists aur paragraphs style karta hai
- ✅ Plain text ko HTML mein convert karta hai
🔐 jwtDecode(token)
JWT token decode karta hai bina kisi external package ke!
import { jwtDecode } from "luci-utils";
const token = localStorage.getItem("token");
const decoded = jwtDecode(token);
console.log(decoded.id); // user ID
console.log(decoded.email); // email🔍 getTokenField(token, field)
Token se specific field nikalta hai.
import { getTokenField } from "luci-utils";
const userId = getTokenField(token, "id");
const email = getTokenField(token, "email");⏰ isTokenExpired(token)
Check karta hai ki token expire ho gaya hai ya nahi.
import { isTokenExpired } from "luci-utils";
if (isTokenExpired(token)) {
// Redirect to login
}🧪 Test Run
node test.jsAuthor
Tejpal Singh - luci-utils v1.0.0
