Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
A sort-of Moand type thing for reading objects. Bascially a way to avoid doing a ton if if
statements to check the data is the way you expect it to be before using it. Quizas will endevaour to do these checks for you and return something without erroring.
npm i --save quizas
var result = quizas(obj, 'path.to.value')
quizas(obj:Object, path:string):Quizas
The factory function to call. The first param is the object to want to read from (usually a bunch of JSON data you just got from a http request or something), the 2nd is the path you want to drill down to. So given this object:
var obj = {
foo: {
bar: [
{
baz: 1
}
]
}
Calling quizas(obj, 'foo.bar.0.baz').value
. value
will be 1
;
The Quizas object has the folling properties and methods:
.hasValue
Boolean - true is the path given to the function resulted in a value, false if not
.value
The value if one was found, null
if not
.extract(...props):Object
If value
is an object this will extract the following properties from it and return a new object. It will not alter the source object. If value
is null, this will return an empty object. For example:
var obj = {
foo: {
bar: {
prop1: '1',
prop2: '2',
prop3: '3
}
}
var result = quizas(obj, 'foo.bar').extract('prop1', 'prop3');
// result === {prop1:'1',prop:'2'}
you can also rename properties as you extract:
var obj = {
foo: {
bar: {
prop1: '1',
prop2: '2',
prop3: '3
}
}
var result = quizas(obj, 'foo.bar').extract(['prop1', 'one'], ['prop3', 'two']);
// result === {one:'1',two:'2'}
.pluck(...props):Array
Similar to extract()
except this is for arrays of objects. When value
is an array this will loop through the array grabbing the given properties from each element. Example:
var obj = {
foo: {
bar: [
{prop1:'1', prop2:'2', prop3:'3'},
{prop1:'1', prop2:'2', prop3:'3'},
{prop1:'1', prop2:'2', prop3:'3'}
]
}
}
var result = quizas(obj, 'foo.bar').pluck(['prop1', 'one'], 'prop3')
// result === [{'one':'1', 'prop3:'3'}, {'one':'1', 'prop3:'3'}, {'one':'1', 'prop3:'3'}];
.copy(target:Object):Object
If value
is not null add it to target
and return a new object. Note: this will not alter target but return a new object
This is written using pure ES5 so should work in most places. Tested in:
Not tested on android as I don't have one and Suacelabs won't let me use theirs. It should work pretty much everywhere, though - if it doesn't let me know!
FAQs
A sort-of monad for reading values from objects
The npm package quizas receives a total of 0 weekly downloads. As such, quizas popularity was classified as not popular.
We found that quizas 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.