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

vigour-base

v3.6.6

Published

'injectacble classes'

Downloads

118

Readme

vigour-base

Build Status js-standard-style npm version Coverage Status

Extendable object constructors, build for speed, low memory consumption and simplicity

  • set method

  • easy extendable property defintions

  • deep, memory efficient prototypes

  • parent and key fields

  • types (easy inheritance)

  • inject pattern

###Properties The properties field is used to add property definitions for certain keys within set objects.

There are 4 types of property definitions:

  • true clears any special base behaviour for the key
  • function calls the function when the key is set instead of the normal behaviour
  • null removes property definition and any existing instances
  • anything else uses the set function

basic

var base = new Base({
  properties: {
    normal: true,
    special (val, stamp) {
      this.special = val * 10
    },
    base: { nested: true }
  }
})

base.set({
  normal: 'hello', // → 'hello'
  special: 10, // → 100
  base: 'a base' // → Base { val: 'a base', nested: true }
})

base.set({
  properties: {
    normal: null
    // removes property defintion and removes "normal"
  }
})

set

var special = new Base({
  type: 'special'
})

var base = new Base({
  properties: {
    // uses "noReference" for a base
    special: special
  }
})

base.set({
  special: 10 // → Special 10
})

// add something to the "special" property
base.set({
  properties: {
    special: {
      aField: true
    }
  }
})
// → base.special.aField.val === true, inherits from the property

define

Allows for extra customisation of property definitions.

It has 3 options:

  • :key when a property is set uses this key to store its value
  • :reset resets a previously defined property
  • :val property value
var base = new Base({
  properties: {
    define: {
      x: { key: 'y' },
      something: {
        key: 'else',
        val: {
          a: true,
          b: true
        }
      },
      hello: {
        key: 'bye',
        val: 100
      }
    }
  },
  x: 10 // → y: 10
  something: { c: true }, // → else: Base { a: true, b: true, c: true }
  hello: { field: true } // → bye: Base { val: 100, field: true }
})

base.set({
  properties: {
    define: {
      something: {
        // removes the "else" field on base
        // creates a new property definition for "something"
        reset: true,
        val: 'hello'
      },
      x: {
        key: 'z',
        reset: false // will not move "y"
      },
      hello: {
        // moves "bye" → "hello"
        key: null
      }
    }
  }
})

###Context Context enables deep memory efficient prototypes. Stores information on fields about first non-shared ancestors.

basic

Notice that base.a.b.c === instance.a.b.c is true but the paths are different

const base = new Base({
  key: 'base'
  a: { b: { c: 'its c' } }
})
const instance = new base.Constructor({
  key: 'instance'
})
console.log(base.a.b.c === instance.a.b.c) // → true
console.log(instance.a.b.c.path()) // → [ 'instance', 'a', 'b', 'c' ]
console.log(base.a.b.c.path()) // → [ 'base', 'a', 'b', 'c' ]

store and apply context

Allows storage and restoration of context. Usefull for edge cases where you need to make a handle to a nested field in a certain context

Consists of 2 methods

  • applyContext(context)
  • storeContext()
const base = new Base({
  key: 'base'
  a: { b: { c: 'its c' } }
})
const instance = new base.Constructor({
  key: 'instance'
})
const b = instance.a.b
const context = b.storeContext()
console.log(base.a.b.c) // this will remove the context "instance", and replace it with base
b.applyContext(context) // will reset the context of b to instance

Apply context can return 3 different types

  • undefined Context is restored without any differences
  • Base A set has happened in the path leading to the target of apply context
  • null A remove has happened in the path leading to the target of apply co ntext