Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
altr-accessors
Advanced tools
generate lookup functions that call a callback each time the computed value changes.
var accessors = new require('altr-accrssors')
var update = accessors.create('a.b + 5', function(val) {
console.log(val)
})
update({a: {b: 5}}) // logs 10
update({a: {b: 5}}) // callback is not called
update({a: {b: '5'}}) // logs 55
By defaut accessor strings are treated as dot path lookups into the current contextt
a.b.c
will look for an a
key in the current context, then it will look up b in the value of that key. and finally look up c in that result. if at any point a value is not found undefined will be returned rather than throwing an error.
accessors may also contain litteral numbers and strings.
5.5
"abc"
altr-accessors suport a most of javascripts operators out of the box (including parentheses, and follow javascripts order of operations.
!
, +
, -
, ~
||
, &&
, |
, ^
, &
, ===
, !==
, ==
, !=
, >=
, <=
, >
, <
, in
, instanceof
, +
, -
, *
, /
, %
a ? b : c
the ->
operator will use the result of the left side as the context for the expression on the right.
a.b -> c + d
is equivelent to a.b.c + a.b.d
filters a simple way to transform the values you are accessing in an accessor.
accessors.addFilter('double', function(args, change) {
return function(args, ctx) {
change(args[0] * 2)
}
})
accessors.create('double(5)', console.log)() //logs 10
accessors.create('double(double(5))', console.log)() //logs 20
accessors.addFilter('mult', function(args, change) {
return function(args, ctx) {
change(args[0] * args[1])
}
})
accessors.create('mult(mult(4, 5), x)', console.log)({x: 3}) //logs 60
accessors.addFilter('mult', function(args, change) {
return function(args, ctx) {
change(ctx * args[0])
}
})
accessors.create('x -> mult(5)', console.log)({x: 3}) //logs 15
alter-accessors([filters[, delay]])
-> instancecreates an accessors instance with its own set of filters.
instance.create(str, change[, all])
-> update functioncreates a new lookup function. this function takes a state, and if the new state changes the output, calls the callback with the new state.
instance.createPart(str, change)
-> update functionthe same as create, but does not debounce changes and will callback even if the resulting value did not change.
instance.createParts(parts, change)
-> update functionsimilar to createPart, but takes an array of parts, and calls back with an array of values.
instance.addFilter(name, constructor)
Adds a filter for use in lookups created by this insance. constructor should implement the api below.
filter_constructor(change)
-> updatewhen update is called, the filter should look at the passed in value and call change with the filters result and the original context. (passing context is not required but is recomended).
The filter constructor will be called with the altr-accessor instance as its context so instance methods such as createPart and split will be avaialbe on this
instance.split(str, key, pairs, all)
-> Array of stringsSplits a string on a key, but does not split in the middle of matching pairs (parens by default).
FAQs
altr-accessors =============
The npm package altr-accessors receives a total of 4 weekly downloads. As such, altr-accessors popularity was classified as not popular.
We found that altr-accessors 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.