Prime-Util
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)
}
})
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(){
return this.parent('a', 'b', 'c') + ',d'
}
})
var b = new B
console.log(b)
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);
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)
array/last
Returns the last value of the array.
last([1, 2, 3])
array/include
Pushes the passed element into the array if it's not already present (case and
type sensitive).
include(['Cow', 'Pig', 'Dog'], 'Cat')
include(['Cow', 'Pig', 'Dog'], 'Dog')
array/empty
Empties an array.
var myArray = ['old', 'data']
empty(myArray))
array/pick
Returns the first defined value of the array passed in, or null.
pick(["foo", "bar"])
pick([null, "bar"])
object/merge
Merges different objects into one object.
var merge = require('prime-util/object/merge')
merge({a: 1}, {a: 2, b: 3}, {c: 4})
Removed Modules
The following modules have been removed:
- prime/mixin
- 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)