npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

oge

v0.0.5

Published

OGE is a utility package designed to prevent a servers, especially free instances on hosting platforms like render.com, from going dormant due to inactivity. It offers configurable sleep windows, time zones, and additional utilities for building custom fu

Downloads

4

Readme

OGE

OGE is a utility package designed to prevent servers, especially free instances on hosting platforms like render.com, from going dormant due to inactivity. It offers configurable sleep windows, time zones, and additional utilities for building custom functionalities.

npm version

Installation

npm

npm install oge

yarn

yarn add oge

Usage

Importing the Utility

import { sleepGuard } from "oge";

Available Utilities

sleepGuard

Prevents server dormancy by pinging a specified URL at regular intervals.

sleepGuard(config: {url: URL, intervalMinutes?: number = 14, sleepStart?: string, sleepEnd?: string, timeZone?: string = 'UTC'}): { start: () => void, stop: () => void };
  • config.url: The URL to ping. This is public the url of your server instance.
  • config.intervalMinutes (optional): Interval in minutes between pings.
  • config.sleepStart (optional): Start time of the sleep window in 'HH:MM:SS:MS' format.
  • config.sleepEnd (optional): End time of the sleep window in 'HH:MM:SS:MS' format.
  • config.timeZone (optional): The standard time zone.

Free hosting providers often limit your server uptime. With sleepStart and sleepEnd, you can schedule your server to stay awake only when it is likely to be used .

Example:

const pinger = sleepGuard({
  url: new URL("https://example.com"),
  intervalMinutes: 10,
  sleepStart: "22:00",
  sleepEnd: "06:00",
  timeZone: "America/New_York",
});

pinger.start();

isTimeWithinInterval

Checks if the specified time is within a given interval.

isTimeWithinInterval(timeToCheck: Date,interval: {start: Date, end: Date}): boolean;

Example:

const result = isTimeWithinInterval(new Date(), {
  start: new Date(),
  end: new Date(),
});

parseTimeStringToUTCDate

Parses a time string to a UTC date object.

parseTimeStringToUTCDate(timeString: string, timeZone: string): Date;

Example:

const date = parseTimeStringToUTCDate("22:00", "America/New_York");

getUTCOffset

Returns the UTC offset for the specified time zone.

getUTCOffset(timeZone: string): string;

Example:

const offset = getUTCOffset("America/New_York");

getUTCOffsetInHours

Returns the UTC offset in hours for the specified time zone.

getUTCOffsetInHours(timeZone: string): number;

Example:

const offsetInHours = getUTCOffsetInHours("America/New_York");

getCurrentTimeInTimeZone

Returns the current time in the specified time zone.

getCurrentTimeInTimeZone(timezone: string): string;

Example:

const currentTime = getCurrentTimeInTimeZone("America/New_York");

pingUrl

Pings a URL by sending a fetch request.

pingUrl(url: string): Promise<void>;

Example:

pingUrl("https://example.com");

Contributing

Want to make OGE even better? Fork the repository and submit a pull request to contribute.

License

MIT License - see the LICENSE file for details.