akuira-ad-bs
v1.0.10
Published
A fully offline **Nepali (BS) to English (AD) Date Converter** with **unlimited date range, leap year support, and custom formats**.
Downloads
25
Readme
@akuira/ad-bs 🚀
A fully offline Nepali (BS) to English (AD) Date Converter with unlimited date range, leap year support, and custom formats.
📌 Installation
Install the package using NPM:
npm install @akuira-ad-bs
📌 Usage
Import the package into your project:
import { convertADToBS, convertBSToAD } from "akuira-ad-bs";
Here’s an example of how to use the package in a React app:
import React, { useState } from "react";
import { convertADToBS, convertBSToAD } from "akuira-ad-bs";
function App() {
const [adDate, setAdDate] = useState("");
const [bsDate, setBsDate] = useState("");
const [error, setError] = useState("");
const handleADtoBS = () => {
if (!adDate) {
setError("Please enter a valid AD date.");
return;
}
const [year, month, day] = adDate.split("-").map(Number);
try {
const result = convertADToBS(year, month, day);
setBsDate(result.bsDate);
setError("");
console.log("BS Date:", result.bsDate, "Month:", result.bsMonthName);
} catch (err) {
setError("Failed to convert AD to BS. Please check the input.");
}
};
const handleBStoAD = () => {
if (!bsDate) {
setError("Please enter a valid BS date.");
return;
}
const [year, month, day] = bsDate.split("-").map(Number);
try {
const result = convertBSToAD(year, month, day);
setAdDate(result.adDate);
setError("");
console.log("AD Date:", result.adDate, "Month:", result.bsMonthName);
} catch (err) {
setError("Failed to convert BS to AD. Please check the input.");
}
};
return (
<div>
<h1>Date Converter</h1>
{error && <p style={{ color: "red" }}>{error}</p>}
<div>
<label>Gregorian (AD) Date</label>
<input
type="date"
value={adDate}
onChange={(e) => setAdDate(e.target.value)}
/>
<button onClick={handleADtoBS}>Convert to BS</button>
</div>
<div>
<label>Bikram Sambat (BS) Date</label>
<input
type="date"
value={bsDate}
onChange={(e) => setBsDate(e.target.value)}
/>
<button onClick={handleBStoAD}>Convert to AD</button>
</div>
</div>
);
}
export default App;