1.0.10 β€’ Published 10 months ago

akuira-ad-bs v1.0.10

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

@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;

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago