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.
brisky-struct
Advanced tools
An observable data structure
const struct = require('brisky-struct')
const root = struct.create({ firstKey: 'value' })
root.serialize() // → { "firstKey": "value" }
⚠ Default behaviour is merge.
root.set({ second: { subKey: 'subValue' } })
root.serialize() // → { "firstKey": "value", "second": { "subKey": "subValue" } }
root.get('second').serialize() // → { "subKey": "subValue" }
root.keys() // → [ "firstKey", "second" ]
root.set({ firstKey: null })
root.get('firstKey') // → undefined
root.keys() // → [ "second" ]
const sub = root.get(['second', 'subKey'])
sub.compute() // → "subValue"
sub.key // → "subKey"
sub.path() // → ["second", "subKey"]
sub.parent().key // → "second"
sub.parent().serialize() // → { "subKey": "subValue" }
sub.root().serialize() // → { "second": { "subKey": "subValue" } }
sub.root() === root // → true
var results = []
root.set({ on: val => results.push(val) })
root.set({ third: 3 })
results // → [ { "third": 3 } ]
root.set({ on: { data: val => results.push(val) } })
root.set({ fourth: 4 })
results // → [ { "third": 3 }, { "fourth": 4 } ]
⚠ Only named listeners won't override existing listeners. Notice that fifth
appears twice in the results array.
root.set({ on: { data: { namedListener: val => results.push(val) } } })
root.set({ fifth: 5 })
results // → [ { "third": 3 }, { "fourth": 4 }, { "fifth": 5 }, { "fifth": 5 } ]
results = []
const third = root.get('third')
third.on(val => results.push(val))
third.set('changed')
results // → [ "changed" ]
root.set({ third: 'again' })
results // → [ "changed", "again" ]
results = []
const fourth = root.get('fourth')
fourth.once('four', val => results.push(val))
fourth.set('will be ignored')
results // → [ ]
fourth.set('four')
results // → [ "four" ]
results = []
fourth.once().then(val => results.push(val))
fourth.set('changed')
results // → [ "changed" ]
fourth.set('will be ignored')
results // → [ "changed" ]
⚠ Events fired on a path can be listened only at exact same path.
const errors = []
root.on('error', err => errors.push(err))
root.emit('error', 'satellites are not aligned')
errors // → [ "satellites are not aligned" ]
sub.once('error', err => errors.push(err))
sub.emit('error', 'splines are not reticulated')
errors // → [ "satellites are not aligned", "splines are not reticulated" ]
Second parameter of get is a default value for the path.
⚠ It'll be set
and returned in absence of given path otherwise it'll be ignored.
root.get('firstKey', 'newValue').compute() // → "newValue"
root.get('firstKey').compute() // → "newValue"
root.get('fifth', 'newValue').compute() // → 5
⚠ Available methods are root
, parent
and compute
.
root.get(['firstKey', 'compute']) // → "newValue"
root.get(['second', 'subKey', 'parent']).serialize() // → { "subKey": "subValue" }
sub.get(['root', 'fifth', 'compute']) // → 5
Third parameter of set is a reset flag.
⚠ Second parameter is a stamp, will come to our plate on further chapters.
const second = root.get('second')
second.set({ newSubKey: 'newSubValue' })
second.serialize() // → { "subKey": "subValue", "newSubKey": "newSubValue" }
second.set({ onlySubKey: 'onlySubValue' }, void 0, true)
second.serialize() // → { "onlySubKey": "onlySubValue" }
const master = struct.create({
movies: {
tt0130827: {
year: 1998,
imdb: 7.7,
title: 'Run Lola Run'
},
tt0301357: {
year: 2003,
imdb: 7.7,
title: 'Good Bye Lenin'
},
tt0408777: {
year: 2004,
imdb: 7.5,
title: 'The Edukators'
}
}
})
const branchM = master.create({
userName:'Mustafa',
movies: {
tt0130827: { favourite: true },
tt0408777: { favourite: true }
}
})
const branchJ = master.create({
userName:'Jim',
movies: {
tt0301357: { favourite: true }
}
})
master.get('userName') // → undefined
branchM.get(['movies', 'tt0408777']).serialize()
// → { "year": 2004, "imdb": 7.5, "title": "The Edukators", "favourite": true }
branchJ.get(['movies', 'tt0408777']).serialize()
// → { "year": 2004, "imdb": 7.5, "title": "The Edukators" }
master.get(['movies', 'tt0408777']).serialize()
// → { "year": 2004, "imdb": 7.5, "title": "The Edukators" }
master.get(['movies', 'tt0130827', 'rating'], 'R')
branchJ.get(['movies', 'tt0130827', 'rating', 'compute']) // → "R"
branchM.get(['movies', 'tt0130827', 'rating', 'compute']) // → "R"
branchJ.get(['movies', 'tt0130827', 'rating']).set('G')
branchM.get(['movies', 'tt0130827', 'rating', 'compute']) // → "R"
master.get(['movies', 'tt0130827', 'rating']).set('PG')
branchM.get(['movies', 'tt0130827', 'rating', 'compute']) // → "PG"
branchJ.get(['movies', 'tt0130827', 'rating', 'compute']) // → "G"
FAQs
An observable data structure
The npm package brisky-struct receives a total of 0 weekly downloads. As such, brisky-struct popularity was classified as not popular.
We found that brisky-struct 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.