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

@spirex/js-boot

v1.0.0

Published

Efficient JavaScript app initialization library with staged execution and dependency management

Downloads

10

Readme

SpireX's JS Application Bootstrapper

GitHub License npm version TypeScript

Description

This small library helps solve the problem of initializing JavaScript applications. It can be used in any JS project.

The library provides an initializer class that allows you to break the initialization process into multiple stages and execute them depending on their interdependencies with other stages.

If any stage of the initialization is paused due to an asynchronous task, the initializer does not wait for its completion but proceeds to the next stage, provided that the tasks related to this stage have been completed.

Installing

You can get the latest release and the type definitions using your preferred package manager:

$ npm install @spirex/js-boot
# OR
$ yarn add @spirex/js-boot
# OR
$ bun i @spirex/js-boot

Usage

1. Import the initializer class

Almost all operations are performed using the AppBoot class. Therefore, it needs to be imported into all files where initialization tasks are defined.

import { AppBoot } from "@spirex/js-boot";

2. Create initialization tasks

The AppBoot.task() method is used to create initialization tasks. It accepts a function containing the executable code for the task. The function can be synchronous or asynchronous. The task name is optional, but helps with logging tasks to the console.

After the function, you can pass an array of dependencies. This ensures that the task will start execution as soon as all dependencies are completed.

const taskA = AppBoot.task('A', async () => {
    console.log('Run task A');
    await someAsyncFunction();
});

const taskB = AppBoot.task('B', () => {
    console.log('Run task B');
}, [taskA]); // Depends on 'A'

3. Create the initializer and add tasks

Tasks are added to the created initializer using the add(..) method. You can add tasks one by one or multiple at once as an array.

const boot = new AppBoot()
    .add([taskA, taskB]);

4. Run the Initialization

Once the initializer is created and all necessary tasks for the application are added, you can start the initialization process. The runAsync() method will return a Promise that resolves when all tasks are completed.

await boot.runAsync();
console.log('Done!');

By default, all tasks are mandatory. Therefore, if any task fails, the initialization process will be aborted, and an exception will be thrown.