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 🙏

© 2026 – Pkg Stats / Ryan Hefner

tsamagotchi

v1.0.0

Published

A TypeScript implementation of a digital pet.

Readme

Tsamagotchi

A Typescript digital pet implementation.

Tsamagotchi is a digital pet class that you can include for your projects. I started this project to learn how to publish node packages.

Install

Install the tsamagotchi package to your project by using

npm install --save tsamagotchi

Usage

You can include the Tsamagotchi in your node project by requiring the package like so:

const { Tsamagotchi } = require('tsamagotchi');

var myTsamagotchi = new Tsamagotchi("Cutie π");

How to play nice with your Tsamagotchi

A Tsamagotchi does not abide the laws of time, thus you can mature it in any way you seem fit. The only (human understandable) time unit is its birthDate, which is a javascript Date object created on the time of creation of the Tsamagotchi instance.

There are many ways to interact with your Tsamagotchi:

  • Create a Tsamagotchi
  • Ask it about its information (instance variables)
  • Feed it
  • Let it mature
  • Let it digest
  • Heal it
  • Love it
  • Decrease its happiness
  • Decrease its health
  • Kill it :<

Creating a Tsamagotchi

A Tsamagotchi can be created without supplying parameters to its constructor, but you can supply 2 optional ones:

// Create a Tsamagotchi with default values: name = "Your new Tsamagotchi", foodLimit = 100
var defaultTsamagotchi = new Tsamagotchi();

// Create a Tsamagotchi with default food limit: foodLimit = 100
var namedTsamagotchi = new Tsamagotchi("Cutie π");

// Create a Tsamagotchi with custom name and food limit
var customTsamagotchi = new Tsamagotchi("Cutie π", 100000);

Ask it about its information

The Tsamagotchi class has a few instance variables but these are the ones you can ask it about:

  1. Its name
var name = myTsamagotchi.name; // e.g. Cutie π

This instance variable can be updated.

  1. Its age

The age of the Tsamagotchi is the amount of time it has been matured.

var age = myTsamagotchi.age; // e.g. 25

This instace variable can only be retrieved, not updated.

  1. Its Birtdate
var birthDate = myTsamagotchi.birthDate // Will return a javascript Date object

This instace variable can only be retrieved, not updated.

  1. Its health

If the Tsamagotchis health reaches zero, it will die. The health has no upper limit.

var health = myTsamagotchi.health // e.g. 75

This instace variable can only be retrieved, not updated.

  1. Its satiety

The satiety of the Tsamagotchi represents how satiated it is. If its satiety reaches zero, it will lose health. You can increase the satiety level by feeding your Tsamagotchi.

var satiety = myTsamagotchi.satiety; // e.g. 40

This instace variable can only be retrieved, not updated.

  1. Its happiness

If your Tsamagotchis happiness reaches zero, it will lose health.

var happiness = myTsamagotchi.happiness; // hopefully a high number

This instace variable can only be retrieved, not updated.

  1. Whether its alive or not

Your Tsamagotchi will contain a boolean value that represents whether it is alive or not.

var areYouAlive = myTsamagotchi.isAlive; // Hopefully true

This instace variable can only be retrieved, not updated.

  1. Its food limit

A Tsamagotchi has a limit on how much it can be fed. If you feed it above its food level, it will lose health.

var foodLimit = myTsamagotchi.foodLimit; e.g. 100

This instace variable can only be retrieved, not updated.

Feed it

Feed your Tsamagotchi a certain amount, which it can digest when it matures:

// Feed it the default value of 1
myTsamagotchi.feed();

// Feed it a whole lot at once
myTsamagotchi.feed(20);

If you feed your Tsamagotchi, its satiety goes up by the amount you fed it. If the satiety level reaches more than the foodLimit value, your Tsamagotchi will lose health.

Let it mature

You created your Tsamagotchi to raise it. Therefore, you need a way to let it mature. When it matures, its happiness and satiety decreases but its age goes up. Try to age it as much as you can for bragging rights.

// Let it mature the default amount of 1
myTsamagotchi.mature();

// Mature it a whole lot at once
myTsamagotchi.mature(33);

Let it digest

Your Tsamagotchi will digest the food you gave it all the way untill its satiety level reaches zero. If it does, it will lose health.

// Let it digest the default amount of 1
myTsamagotchi.digest();

// Let it digest a whole lot at once
myTsamagotchi.digest(75);

Heal it

Increase the health level by healing your Tsamagotchi, because if its health reaches zero, it will die.

// Heal it the default amount of 1
myTsamagotchi.heal();

// Heal it a whole lot at once
myTsamagotchi.heal(666);

Love it

You want your pet to be happy, so you can increase its happiness level by loving it. If its happiness level reaches zero, it will lose health.

// Love it the default amount of 1
myTsamagotchi.love();

// Heal it a whole lot at once
myTsamagotchi.love(69);

Decrease its happiness

You can also decrease its happiness. I don't know why you would want that but I exposed the function anyway. If its happiness reaches zero, it will lose health.

// Make it sad for the default amount of 1
myTsamagotchi.decreaseHappiness();

// Decrease its happiness a whole lot at once
myTsamagotchi.love(9001);

Decrease its health

You can also decrease its health. Again, this function should be private but I included it anyway. If its health reaches zero, it will die.

// Decrease its health by the default amount of 1
myTsamagotchi.decreaseHealth();

// Decrease its health a whole lot at once
myTsamagotchi.decreaseHealth(400);

Kill it :<

As with all objects, it will eventually have to be destroyed. You monster!

// Goodnight, sweet prince
myTsamagotchi.die();