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

creature

v0.7.0

Published

Identify agents in the world, and track their memories

Downloads

15

Readme

var creature = require("creature")

creature is an in-memory store for tracking sets of memories of characters in a virtual world:

creature("dr", "Doctor Rabbit")
creature.see("dr", "bird", "the bird has brown wings and a floofy head")

That creates a creature named "Doctor Rabbit" with the ID "dr" and notes that they saw something named "bird".

Another creature might see a different thing at the same place in the namespace:

creature("ted", "Tod Blosby")
creature.see("ted", "bird", "get away from me bird")

Either of those creatures could then remember the bird:

var bird = creature.remember("dr", "bird")
// Returns "the bird has brown wings and a floofy head"

Why would I ever want to do that?

The above is a contrived example, but if you're a more pragmatic person, you can think of these as cookies, or user-relative values in a key value store. User "f901j3" with the name "Joe Schmoe" might see "session-id" "139jf013" for example:

creature("f901j3", "Joe Schmoe")
creature.see("f901j3", "session-id", "139jf013")

Then later on we might remember that to make a request:

var makeRequest = require("make-request")

makeRequest({
  method: "get",
  url: "http://my-very-practical-web-site.com/important-secret-stuff",
  headers: {
    "Session-Id": creature.remember("f901j3", "session-id"),
  },
})

Persisting memories in a log

Creature is designed to use only simple function calls so that they can be logged by a-wild-universe-appeared:

var creature = require("creature")
var aWildUniverseAppeared = require("a-wild-universe-appeared")

var doctors = aWildUniverseAppeared("memories of various doctors", {creature: "creature"})

doctors.do("creature", "dr", "Doctor Rabbit")
doctors.do("creature.see", "dr", "bird", "the bird has brown wings and a floofy head")

var bird = creature.remember("dr", "bird")
// Wont return anything because creature.see hasn't been called yet

doctors.playItBack()
bird = creature.remember("dr", "bird")
// Now it returns "the bird has brown wings..."

Why not use one of many existing key-values stores?

It's slightly more constrictive than a typical key-value store, in that it does go two levels deep, so it forces you to namespace. That's so we always know which creature owns a key.

We could namespace in a normal key-value store, but the point of creature is that every key belongs to someone.

Because creature's API is all function calls, and is amenable to use for event-sourcing, that means we can shard the store up into multiple different realities, which makes it natural to only have a subset of the global store at any given time.

Everything being namespaced to a specific creature helps make those shards more mergeable. Although sometimes different universes will have different opinions about what a given creature has seen, for the most part, any given creatures memories will tend to be localized and internally consistent, with lower probability of namespace conflict with other creatures logs.