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

@nine-worlds/yggdrasil

v1.0.3

Published

A comprehensive package for React Web and React Native development, featuring configuration management, dependency injection, state management, routing, theming, utility functions, and testing tools. Simplify your development process and build scalable, m

Downloads

2

Readme

@nine-worlds/yggdrasil

@nine-worlds/yggdrasil is a comprehensive package designed for React Web and React Native development. It integrates configuration management, dependency injection, state management, routing, theming, utility functions, and testing tools, providing developers with a robust framework to streamline their development process and build scalable, maintainable applications effortlessly.

Features

  • Configuration Management: Centralized and flexible handling of configuration settings.
  • Dependency Injection: Robust system for managing dependencies across your application.
  • Utility Functions: Comprehensive set of utility functions for common tasks.
  • Collection Management: Comprehensive set of collection tools to handle collections similarly to .NET.

Installation

To install @nine-worlds/yggdrasil, use npm or yarn or bun:

npm install @nine-worlds/yggdrasil
# or
yarn add @nine-worlds/yggdrasil
# or
bun install @nine-worlds/yggdrasil

Usage

Below are two ways to implement the package in your startup file.

Using async/await

  1. Import the necessary components from the package.
  2. Define an asynchronous startup function that accepts a ServiceCollection parameter.
  3. Call the startup function and handle the returned Promise.
import { ServiceCollection } from "@nine-worlds/yggdrasil";

const startup = async (serviceCollection: ServiceCollection) => {
  // Configure services here
};

startup(new ServiceCollection()).then(() => {
  // Application initialization logic here
});

Without async/await

  1. Import the necessary components from the package.
  2. Define a synchronous startup function that accepts a ServiceCollection parameter.
  3. Call the startup function directly.
import { ServiceCollection } from "@nine-worlds/yggdrasil";

const startup = (serviceCollection: ServiceCollection) => {
  // Configure services here
};

startup(new ServiceCollection());

Using the DI

Create Injectable Service

export class SampleService extends Injectable {
    constructor() {
        super();
    }

    static get() {
        return new SampleService();
    }
}

Register Injectable Service into the DI

Create register service function

export function registerSampleService(serviceCollection: ServiceCollection): ServiceCollection {
    return serviceCollection.registerSingletonService<SampleService>(SampleService.get())
}

Register the service to the DI with the function

const startup = (serviceCollection: ServiceCollection) => {
    // Configure Services Here
    registerSampleService(serviceCollection);
};

Retrieve the service from the DI

Use the ServiceCollection static method call

const sampleService = ServiceCollection.getServiceByFunction<SampleService>(SampleService);

Use the static method alias

// Alias for .getServiceByFunction<T>(T);
const sampleService = service<SampleService>(SampleService);

Using Configuration

Create the configuration object

export default {
    // Add your properties here either define the values from .env variables
    // or define it here with static values
    simpleValue: "simple value here",
    objectValue: {
        simpleObjectValue: "simple object value here",
        nestedObject: {
            simpleNestedObjectValue: "simple nested object value here"
        }
    }
}

Register the configuration object

import configuration from "./configuration";

const startup = (serviceCollection: ServiceCollection) => {
    // Configure Services Here
    serviceCollection.configuration.addConfiguration(configuration)
};

Retrieve value from configuration

Simple Property

// Retrieve the simpleValue
const genericValue = ServiceCollection.Configuration.getGeneric<string>("simpleValue"); // returns "simple value here" as a string
const value = ServiceCollection.Configuration.get("simpleValue"); // returns the "simple value here" as any

Object Property

// Retrieve the object property
const genericValue = ServiceCollection.Configuration.getGeneric<string>("objectValue.simpleObjectValue"); // returns "simple object value here" as a string
const value = ServiceCollection.Configuration.get("objectValue.simpleObjectValue"); // returns the "simple object value here" as any

Nested Object Property

// Retrieve the object property
const genericValue = ServiceCollection.Configuration.getGeneric<string>("objectValue.nestedObject.simpleNestedObjectValue"); // returns "simple nested object value here" as a string
const value = ServiceCollection.Configuration.get("objectValue.nestedObject.simpleNestedObjectValue"); // returns the "simple nested object value here" as any

Separators that could be used to reference properties

You could either use . or : like objectValue.nestedObject.simpleNestedObjectValue or objectValue:nestedObject:simpleNestedObjectValue

React Wrapper Hooks

useService

import {useMemo} from "react";
import {Injectable, service} from "@nine-worlds/yggdrasil";

export function useService<T extends Injectable>(serviceIdentifier: Function) {
    return useMemo(() => service<T>(serviceIdentifier), [serviceIdentifier]);
}

Usage

const ReactComponent: React.FC = () => {
    const sampleService = useService<SampleService>(SampleService);
}

export default ReactComponent;

useConfiguration

import {useMemo} from "react";
import {ServiceCollection} from "@nine-worlds/yggdrasil";

export function useConfiguration<T>(path: string, afterWiser?: (value: T) => T): T {
    return useMemo(() => {
        const value = ServiceCollection.Configuration.getGeneric<T>(path);
        if (afterWiser) return afterWiser(value);
        return value;
    }, [path]);
}

Usage

const ReactComponent: React.FC = () => {
    const genericValue = useConfiguration<string>("objectValue.nestedObject.simpleNestedObjectValue");
}

export default ReactComponent;

Development

You are welcome to develop with us at GitHub.

bun install
bun build