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

computed-properties

v0.2.2

Published

A data store with support for computed properties

Readme

Computed Properties

JavaScript Style Guide Travis npm

This package helps deriving data from other data. It's especially well suited for computation-heavier dependencies since it caches and lazy-evaluates computed properties.

It conceptually borrows heavily from Vue.js' computed properties, supports all evergreen browsers and IE 11 and features a reasonably small size (1.6 KB minified & gzipped).

Installation

Install it from npm:

npm install --save computed-properties

Include in the Browser

You can use this package in your browser with one of the following snippets:

  • The most common version. Compiled to ES5, runs in all major browsers down to IE 11:

    <script src="node_modules/computed-properties/dist/store.umd.js"></script>
    
    <!-- or from CDN: -->
    
    <script src="https://unpkg.com/computed-properties"></script>
  • If you're really living on the bleeding edge and use ES modules directly in the browser, you can import the package as well:

    import Store from "./node_modules/computed-properties/dist/store.mjs"
    
    // or from CDN:
    
    import Store from "https://unpkg.com/computed-properties/dist/store.mjs"

    As opposed to the snippets above, this will not create a global Store function.

Include in Node.js

Include this package in Node.js like you usually do:

const Store = require('computed-properties')

Usage

Create a store by passing a configuration object to the Store function:

const programmer = Store({
  firstName: 'Jane',
  lastName: 'Doe',
  hobbies: [ 'programming', 'reading' ],
  skills: {
    communication: 3,
    cleverness: 4
  },
  fullName () {
    return this.firstName + ' ' + this.lastName
  },
  bestAt () {
    return Object.entries(this.skills).sort(([,ratingA], [,ratingB]) => ratingB - ratingA)[0][0]
  },
  developerStory () {
    return `Hi, I'm ${this.fullName}.
I like ${this.hobbies.slice(0, -1).join(', ')}${this.hobbies.length > 1 ? ' and ' : ''}${this.hobbies[this.hobbies.length - 1]}.
I'm especially good with ${this.bestAt}.`
  }
})

You can play with this example on CodePen.

All functions in the configuration object (fullName, bestAt and developerStory in our case) will be treated as computed properties. You can get their values just like with any regular property:

programmer.fullName // "Jane Doe"

Now if we adjust the first name of our programmer, the fullName will also be updated:

programmer.firstName = 'John'
programmer.fullName // "John Doe"

Context-free Computed Properties

If you don't like the style of computed properties accessing the this object, they also get passed the store as their first parameter.

The programmer.fullName computed property, for example, could also have been written as follows:

Store({
  // ...

  fullName: store => store.firstName + ' ' + store.lastName

  // or even:

  fullName: ({ firstName, lastName }) => firstName + ' ' + lastName
})

Watch Properties

You can watch any regular or computed property on the created programmer using the $watch() method:

const unwatch = programmer.$watch('fullName', (newValue, oldValue) => {
  // This is executed when the `fullName` computed property changes
})

// Calling unwatch() will stop watching the `fullName` property

Set a new Property in an Object

All properties of an object present at initialization time will be tracked. However, if you want to add a new property, you have to use the $set() method:

programmer.skills.$set('experience', 5)

Set an Array Item's Value

While all array methods (e.g. push()) are tracked, setting an array's item via bracket access cannot be tracked:

programmer.hobbies[0] = 'Cycling' // Will not update the `developerStory`

To trigger dependency changes you'd either have to replace the whole hobbies array, or set the respective item via the $set() method:

programmer.hobbies.$set(0, 'Cycling') // Will update the `developerStory`

Functions as Properties

Since all functions in a Store's configuration object are treated as computed properties, there's no way that a regular property can contain a function.

Store({
  // Evaluated as a computed property
  someProp: function () {
    // ...
  }
})

However, there's a very simple workaround: Create a computed property that returns the desired function.

Store({
  someProp () {
    return function () {
      // ...
    }
  }
})

Methods

The Store function has no built-in way to attach methods to it, but you can assign them onto the created store:

// Possibly update last name on marriage
programmer.marry = function (newLastName) {
  if (newLastName) {
    this.lastName = newLastName
  }
}