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

@bad-cards/theseus

v1.0.7

Published

Functionality to create and modify data fluently and narratively

Downloads

2

Readme

Theseus

Theseus offers fluent state manipulation and management for JavaScript applications, streamlining state changes with clarity and enforceable rules.

Goals

  • Clarity in State Management: Ensure that state changes are transparent and understandable.
  • Ease of Compliance: Encourage adherence to best practices with a design that makes it easier to follow rules than to break them.
  • Smart, Automatic Typing: Leverage intelligent data typing detection to reduce boilerplate and increase efficiency.

Installation

npm install theseus

Quick Start

A brief introduction on how to get started with Theseus. For example:

import { Evolver, AsyncEvolver } from 'theseus-library';

// Example of using Evolver
const myEvolver = Evolver.as<MyDataType>()
    .withParamName('myData')
    .withMutators({...});

// Example of using AsyncEvolver
const myAsyncEvolver = AsyncEvolver.build<MyAsyncDataType>()
    .named('asyncData')
    .withActions({...});

Core Concepts

Evolvers

Evolvers in Theseus enable flexible state evolution in JavaScript applications, suitable for complex or asynchronous state manipulation. They follow a one-to-many relationship, where one Evolver applies many Mutators. Evolvers always use mutable data and return the same data type, ensuring consistency and predictability in state changes.

  • Evolver: An Evolver manages synchronous state evolution, integrating multiple Mutators for different aspects of state transformation. It uses mutable data as input and returns the same data type, maintaining state integrity.

    • AsyncEvolver: Asynchronous version of Evolver, containing mutators which always return a promise of the Evolver's data type.
  • Mutator: Mutators are functions within an Evolver, each specifying a unique rule for how the state evolves. They define the logic for state changes, ensuring that each modification is controlled and deliberate.

Refineries

Refineries in Theseus offer structured data transformation, following a one-to-many relationship where one Refinery manages many Forges. Refineries always use immutable data as input, and output any other type.

  • RefineryComplex: A RefineryComplex manages multiple Refineries, each with their own Forges, enabling interconnected data transformation workflows.

  • Refinery: A Refinery orchestrates data transformation, using multiple Forges to handle complex data processing tasks.

  • Forge: Each Forge in a Refinery performs a specific data transformation with immutable input, returning data of some other type.

Flags

Flags in Theseus provide an efficient way to manage binary state representations like bitwise flags or toggles, handling flag enumerations, offering methods for manipulation, testing, and querying of flag values.

Examples - To Do Application

ToDoEvolver

Show a real-world example of using Evolver for state management.

import { Evolver } from 'theseus';

// Evolver for managing a single ToDo
const ToDoEvolver = Evolver.as<ToDo>().withParamName("list").withMutators({
    setTitle: ({mutableList}, newTitle: string) => {
        mutableList.title = newTitle;
        return mutableList;
    },
    setPriority: ({mutableList}, newPriority: number) => {
        mutableList.priority = newPriority;
        return mutableList;
    },
    togglePinned: ({mutableList}) => {
        mutableList.pinned = !mutableList.pinned;
        return mutableList;
    },
    setDescription: ({mutableList}, newDescription: string) => {
        mutableList.description = newDescription;
        return mutableList;
    },
    addListItem: ({mutableList}, listItem: ListItem) => {
        mutableList.listItem = mutableList.listItem || [];
        mutableList.listItem.push(listItem);
        return mutableList;
    },
    removeListItem: ({mutableList}, listItemToRemove: ListItem) => {
        mutableList.listItem = mutableList.listItem.filter(listItem => listItem !== listItemToRemove);
        return mutableList;
    },
    moveItemToSection: ({mutableList}, itemIndex: number, sectionIndex: number) => {
        mutableList.itemToSectionIndexMap[itemIndex] = sectionIndex;
        return mutableList;
    }
});

// Evolver for managing a single Section
const SectionEvolver = Evolver.as<Section>().withParamName("section").withMutators({
    setTitle: ({mutableSection}, newTitle: string) => {
        mutableSection.title = newTitle;
        return mutableSection;
    },
    setType: ({mutableSection}, newType: SectionType) => {
        mutableSection.type = newType;
        return mutableSection;
    },
    updateOrder: ({mutableSection}, newOrder: number[]) => {
        // Assuming mutableSection has a property that keeps track of the order of ToDo items
        mutableSection.itemOrder = newOrder;
        return mutableSection;
    },
    // Additional mutators as needed...
});

// Usage example

const todoId = (new URLSearchParams(location.search)).get("list-id");
const todo: ToDo = async fetchToDoById(todoId); // Fetch a list from the server

const updatedToDo = ToDoEvolver.mutate(myToDo)
    .setTitle('New Title')
    .togglePinned()
    .getFinalForm();

Asynchronous State Evolution

Illustrate the use of AsyncEvolver for managing asynchronous state changes.

// Example code here

Mutating State

Demonstrate how to define and use a MutatorSet.

// Example code here

Data Transformation with Refineries

Provide an example of creating and using a Refinery.

// Example code here

API Documentation

Link to detailed API documentation or include a section that covers the main API methods and their usage.

Contributing

Instructions for contributing to the Theseus project, including coding standards, testing practices, and how to submit pull requests.

License

Specify the license under which Theseus is released.