Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
prime-util
Advanced tools
Your utilities for prime
npm install prime-util
Mixin other primes into another prime
var mixin = require('prime-util/prime/mixin')
mixin(MyPrime, Options, Events)
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 mixin = require("prime-util/prime/mixin")
var MyPrime = prime({
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]
}
})
mixin(MyPrime, bound)
Parentize makes it easier to call overridden parent methods.
var parentize = require('prime-util/prime/parentize')
var array = require('prime/array')
var mixin = require('prime-util/prime/mixin')
var A = prime({
a: function(){
return array.join(arguments)
}
})
var B = prime({
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'
}
})
mixin(B, parentize)
var b = new B
console.log(b) // logs "b,c,d"
Provide "setOptions" method.
var prime = require('prime')
var Options = require('prime-util/prime/options')
var A = prime({
options: {
'a': 'aaa',
'b': 'bbb',
'c': {
'd': 'ddd',
'e': 'eee'
}
},
constructor: function(options){
this.setOptions(options)
}
})
mixin(A, Options)
var a = new A({'b': 'B', 'c': {'e': 'E'}})
console.log(a.options); // {'a': 'aaa', 'b': 'B', 'c': {'d': 'ddd', 'e': 'E'}}
Familiar MooTools Array functions. This module puts the array functions listed below in the prime array shell.
var array = require('prime-util/shell/array')
array.contains([1, 2, 3], 2) // true
Create a new array with all elements that are not null or undefined.
var clean = require('prime-util/array/clean')
clean([null, 2, "foo", undefined]) // [2, "foo"]
Return an array with the named method applied on the array's content.
invoke([
{a: function(arg){ console.log("first", arg)}},
{a: function(arg){ console.log("second", arg)}}
], 'a', "thing") // logs "first thing" "second thing"
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'}
Returns true if a value is in the array, otherwise it returns false.
Appends the passed array to the end of the current array.
append([1, 2, 3], [4, 5, [6]]) // [1, 2, 3, 4, 5, [6]]
Returns the last value of the array.
last([1, 2, 3]) // 3
Returns a random item from the array.
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']
Combines an array with all the items of another. Does not allow duplicates and is case and type sensitive.
var animals = ['Cow', 'Pig', 'Dog']
combine(animals, ['Cat', 'Dog']; //animals = ['Cow', 'Pig', 'Dog', 'Cat']
Empties an array.
var myArray = ['old', 'data']
empty(myArray)) // myArray is now []
Returns the first defined value of the array passed in, or null.
pick(["foo", "bar"]) // "foo"
pick([null, "bar"]) // "bar"
Returns the first item in the array for which the function returns true.
find([1, 2, 3, 4, 5], function(number){
return number == 2
}) // returns 2
Add the object functions to the prime object shell
var object = require('prime-util/shell/object')
object.fromPath({a: {b: 1}}, 'a.b')
Merges different objects into one object.
var merge = require('prime-util/object/merge')
merge({a: 1}, {a: 2, b: 3}, {c: 4}) // {a: 2, b: 3, c: 4}
Returns the value at a given path
var fromPath = require('prime-util/object/fromPath')
var demo = {'a': {'b': {'c': 'prime!'}}};
fromPath(demo, 'a.b.c') // prime!
FAQs
Extra Utilities using Prime
The npm package prime-util receives a total of 0 weekly downloads. As such, prime-util popularity was classified as not popular.
We found that prime-util demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.