![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
duck
Advanced tools
Readme
duck.js allows you to perform assertions on complex objects. When those assertions fail, duck.js will try to produce helpful error messages. For instance, suppose you want to assert the same property on an array of objects:
var duck = require("duck");
var isArray = duck.isArray;
var hasProperties = duck.hasProperties;
var users = fetchUsers();
duck.assertThat(users, isArray([
hasProperties({name: "Bob"}),
hasProperties({name: "Jim"}),
]));
which might produce an error message like:
Expected [object with properties {
name: 'Bob'
}, object with properties {
name: 'Jim'
}]
but element at index 0 didn't match:
value of property "name" didn't match:
was 'Jim'
expected 'Bob'
expected object with properties {
name: 'Bob'
}
element at index 1 didn't match:
value of property "name" didn't match:
was 'Bob'
expected 'Jim'
expected object with properties {
name: 'Jim'
}
The below is a quick reference to the API. For more examples, take a look at the tests.
Assert that value
satifies matcher
.
If value
satifies matcher
, return normally, otherwise throw an
AssertionError describing the mismatch.
If value
is a matcher, return that matcher,
otherwise return duck.equalTo(value)
.
Matcher for deep equality on value
.
An object obj
matches duck.isObject(matcherObj)
if:
obj
matches duck.hasProperties(matcherObj)
, andobj
but not in matcherObj
Sample usage:
duck.isObject({
name: "Bob",
address: duck.isObject({
city: "Cambridge",
county: "UK"
})
})
duck.is
is called on each value of the matcher object, meaning that the
above is equivalent to:
duck.isObject({
name: duck.is("Bob"),
address: duck.isObject({
city: duck.is("Cambridge"),
county: duck.is("UK")
})
})
An object obj
matches duck.hasProperties(matcherProperties)
if,
for each key
in matcherProperties
, matcherProperties[key].matches(obj[key])
Sample usage:
duck.hasProperties({
name: "Bob",
address: duck.hasProperties({
city: "Cambridge",
county: "UK"
})
})
duck.is
is called on each value of the matcher object, meaning that the
above is equivalent to:
duck.hasProperties({
name: duck.is("Bob"),
address: duck.hasProperties({
city: duck.is("Cambridge"),
county: duck.is("UK")
})
})
An array blah
matches duck.isArray(matcherArray)
if:
blah.length == matcherArray.length
, and0 <= i < array.length
, matcherArray[i].matches(blah[i])
Sample usage:
duck.isArray([
duck.hasProperties({name: "Bob"}),
duck.hasProperties({name: "Jim"}),
]))
duck.is
is called on each element of the matcher array, meaning that the
following are equivalent:
duck.isArray(["apple", "banana"])
duck.isArray([duck.is("apple"), duck.is("banana")])
Each matcher has the following methods:
Return true
if value
satifies this matcher, false otherwise.
Generate a string describing why value
doesn't satisfy this matcher.
Behaviour is undefined if value
actually satisifies the matcher.
Equivalent to:
var isMatch = this.matches(value);
return {
matches: isMatch,
description: isMatch ? "" : this.describeMismatch(value)
};
Useful if you're likely to want both the boolean and the mismatch description.
Generate a string describing the matcher.
Thanks to Hamcrest for inspiration.
FAQs
Rich matchers inspired by Hamcrest. Useful for generating helpful assertion failure messages in tests.
The npm package duck receives a total of 171,364 weekly downloads. As such, duck popularity was classified as popular.
We found that duck 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
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.