
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
@phasor/array
Advanced tools
Lightweight ordered function execution; phases.
Add "phases" and add functions to the phases and they will be executed in order.
The main concept is functions can be ordered in groups, phases, without needing to be ordered within each phase.
For example, a client router may want phases:
This allows expanding third party modules by adding your own phases and functions to a phasor
they made.
$ npm install @phasor/array --save
Used to both add a phase and add a function to a phase.
You may add a phase and add a function to it at the same time.
Instead of specifying a single object argument you may specify a string for the first argument as the id
and optionally a function as the second argument.
// specify the phase via the `id` property.
// with no `before` or `after` property the phase will
// be added last
phasor.add({ id: 'some phase name' })
// add the phase *before* another phase by specifying the `before`
phasor.add({ id: 'diff phase name', before: 'other phase' })
// add the phase *after* another phase by specifying the `after`
phasor.add({ id: 'third phase name', after: 'other phase' })
// NOTE: if you specify both before and after the before will be ignored
var fn = function() {} # some function
// specify the phase via the `id` property.
// specify the function via the `fn` property
phasor.add({ id: 'phase name', fn:fn })
// add a new phase and add a function to it at the same time
phasor.add({ id: 'new phase', before:'phase name', fn:fn })
// use individual arguments
// NOTE: you can't specify after/before values using this style
phasor.add('third phase', fn)
Executes the functions for each phase in order.
The specified object is provided to each function as both the argument and the this context.
Note:
this
in each function is the object passed to phasor.run(object)
.false
.var fn = function(context) {
if (this.someValue) { // same as context.someValue
// set a new value into the context for future functions
this.newValue = 'blah'
} else {
// false causes the run() to stop
return false
}
}
var context = { someValue:'value' }
phasor.run(context)
I can think of several other implementation styles for the phasor
idea. I made the @phasor
scope so those implementations can be grouped together. Please let me know if you have an idea for an implementation or you'd like to add your module to the @phasor
scope.
For example, a phasor could be implemented with async
utilities, or, chain-builder
(I made chain-builder...). These could provide some more advanced features for execution.
FAQs
Lightweight ordered function execution; phases
We found that @phasor/array 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.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.