
Security News
Node.js Homepage Adds Paid Support Link, Prompting Contributor Pushback
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
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 452 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
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.
Research
Security News
The Socket Research Team investigates a malicious Python typosquat of a popular password library that forces Windows shutdowns when input is incorrect.