Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
core-router
Advanced tools
Readme
Primitives for building your own router.
match()
match()
provides flexible rule-based URL matching.
You can:
match({ path: "/account/:accountId" }, "/account/123");
result = {
params: {
accountId: "123";
}
}
match(
{
path: "/account/:accountId",
search: {
from: ":fromDate?",
to: ":toDate?"
},
condition: ({ params }) => {
return isDate(params.fromDate) && isDate(params.toDate);
}
},
"/account/123?from=2020-01-01&to=2020-01-31"
);
result = {
params: {
accountId: "123",
fromDate: "2020-01-01",
toDate: "2020-01-31"
}
};
match(
{
condition: ({ url }) => {
return url.hash === "#secret";
}
},
"/you/must/have/the#secret"
);
result = {
params: {}
};
Absolute URLs will only match if they belong to the same domain:
// On https://foo.com:
match({ path: "/hello" }, "https://bar.com/hello");
result = null;
Params will be decoded for you:
match({ search: { q: ":searchTerms" } }, "/?q=hello%20world");
result = {
params: {
searchTerms: "hello world"
}
};
toHref()
Any rule that can be used for match()
can also be used to generate a relative URL.
toHref({ path: "/account/:accountId" }, { accountId: "123" });
result = "/account/123";
If required params are not supplied, an error will be thrown:
toHref({ path: "/account/:accountId" }, {});
// Error!
Similarly, if the condition
is not met, an error will alos be thrown:
toHref(
{
condition: ({ url }) => url.hash === "#secret"
},
"/#incorrect"
);
// Error!
This ensures that for any rule, a URL generated by toHref()
will also match()
:
const href = toHref(myRule, myParams);
const matchResult = match(myRule, href);
expect(matchResult).not.toBe(null);
expect(matchResult.params).toEqual(myParams);
FAQs
Primitives for building your own router
The npm package core-router receives a total of 7 weekly downloads. As such, core-router popularity was classified as not popular.
We found that core-router 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.