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

prime-util

v0.5.0

Published

Extra Utilities using Prime

Downloads

31

Readme

Prime-Util

Build Status

Your utilities for prime

Install

npm install prime-util

Current Modules Docs

prime/bound

Provides an alternative way to bind class methods. Stores references to bound methods internally without any manual setup and does not modify the original methods.

var bound = require("prime-util/prime/bound")

var MyPrime = prime({
    mixin: [bound],
    constructor: function(){
        this.results = []
    },
    method: function(i){
        this.results.push(i)
    },
    run: function(){
        [1, 2, 3].forEach(function(this.bound('method')))
        console.log(this.results) // [1, 2, 3]
    }
})

prime/parentize

Parentize makes it easier to call overridden parent methods.

var parentize = require('prime-util/prime/parentize')
var array = require('prime/array')

var A = prime({
    mixin: [parentize],
    a: function(){
        return array.join(arguments)
    }
})
var B = prime({
    mixin: [parentize],
    inherits: A,
    a: function(){
        // first argument is the parent method name, in this case 'a'
        // the other parameters are passed as the parent method arguments
        return this.parent('a', 'b', 'c') + ',d'
    }
})

var b = new B
console.log(b) // logs "b,c,d"

prime/options

Provide "setOptions" method.

var prime = require('prime')
var Options = require('prime-util/prime/options')

var A = prime({
    mixin: [Options],

    options: {
        'a': 'aaa',
        'b': 'bbb',
        'c': {
            'd': 'ddd',
            'e': 'eee'
        }
    },

    constructor: function(options){
        this.setOptions(options)
    }

})

var a = new A({'b': 'B', 'c': {'e': 'E'}})
console.log(a.options); // {'a': 'aaa', 'b': 'B', 'c': {'d': 'ddd', 'e': 'E'}}

array/associate

Creates an object with key-value pairs based on the array of keywords passed in and the current content of the array.

var animals = ['Cow', 'Pig', 'Dog', 'Cat']
var sounds = ['Moo', 'Oink', 'Woof', 'Miao']
associate(sounds, animals)
// returns {'Cow': 'Moo', 'Pig': 'Oink', 'Dog': 'Woof', 'Cat': 'Miao'}

array/include

Pushes the passed element into the array if it's not already present (case and type sensitive).

include(['Cow', 'Pig', 'Dog'], 'Cat') // returns ['Cow', 'Pig', 'Dog', 'Cat']
include(['Cow', 'Pig', 'Dog'], 'Dog') // returns ['Cow', 'Pig', 'Dog']

array/empty

Empties an array.

var myArray = ['old', 'data']
empty(myArray)) // myArray is now []

array/pick

Returns the first defined value of the array passed in, or null.

pick(["foo", "bar"]) // "foo"
pick([null, "bar"]) // "bar"

object/fromPath

Returns the value from an object by its path

fromPath({
    food: {
        fruits: {
            apples: "red",
            lemon: "yellow"
        }
    }
}, 'food.fruits.apples') // 'red'

Removed Modules

The following modules have been removed:

  • prime/mixin - use mixin property of prime
  • array/clean - use (mout/array/compact)
  • array/invoke - use (mout/array/invoke)
  • array/contains - use (mout/array/contains)
  • array/append - use (mout/array/append)
  • array/random - use (mout/random/choice)
  • array/combine - use (mout/array/combine)
  • array/find - use (mout/array/find)
  • object/merge - use (mout/array/merge)