1.0.3 • Published 9 months ago
bortle-astro-utils v1.0.3
bortle-astro-utils
bortle-astro-utils is a TypeScript library that provides utility functions for astrophotography. It includes functions for converting between different units, calculating solar and lunar times, and handling date and time conversions for different time zones.
Installation
To install bortle-astro-utils, use npm or yarn:
npm install bortle-astro-utilsor
yarn add bortle-astro-utilsUsage
Importing the library
import {
  kelvinToCelsius,
  kelvinToFahrenheit,
  celsiusToFahrenheit,
  fahrenheitToCelsius,
  fahrenheitToKelvin,
  celsiusToKelvin,
  metersPerSecondToKmph,
  metersPerSecondToMph,
  getTransparencyDescription,
  getSeeingDescription,
  mpsas2bortle,
  useStarfrontDateTimeZoneContext,
  StarfrontDateTimeZoneProvider,
  TemperatureString,
  ObservatoryDateTime,
} from "bortle-astro-utils";Temperature Conversion
const celsius = kelvinToCelsius(300); // 26.85
const fahrenheit = kelvinToFahrenheit(300); // 80.33Speed Conversion
const kmph = metersPerSecondToKmph(10); // 36
const mph = metersPerSecondToMph(10); // 22.37Transparency and Seeing Descriptions
const transparency = getTransparencyDescription(10); // "Average (10)"
const seeing = getSeeingDescription(3); // "Average"MPSAS to Bortle Scale
const bortleScale = mpsas2bortle(21.5); // 3Date and Time Context
import React from "react";
import { StarfrontDateTimeZoneProvider, useStarfrontDateTimeZoneContext } from "bortle-astro-utils";
const App = () => {
  return (
    <StarfrontDateTimeZoneProvider>
      <MyComponent />
    </StarfrontDateTimeZoneProvider>
  );
};
const MyComponent = () => {
  const { starfrontDateTimeZone, setStarfrontDateTimeZone } = useStarfrontDateTimeZoneContext();
  return (
    <div>
      <p>Current Time Zone: {starfrontDateTimeZone}</p>
      <button onClick={() => setStarfrontDateTimeZone("utc")}>Set to UTC</button>
    </div>
  );
};Temperature String Component
import React from "react";
import { TemperatureString } from "bortle-astro-utils";
const MyComponent = () => {
  return <TemperatureString temperature={300} units="K" />;
};Observatory DateTime
import { ObservatoryDateTime } from "bortle-astro-utils";
const dateTime = new ObservatoryDateTime(new Date(), "America/Chicago");
console.log(dateTime.getLocalDateTime()); // Local date and time
console.log(dateTime.getChicagoDateTime()); // Chicago date and time
console.log(dateTime.getUTCDateTime()); // UTC date and time
console.log(dateTime.getRelativeTime()); // Relative time