
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
lite-router
Advanced tools
I needed some simple routing solution for my rxjs-experiments project (not based on any framework or libraries that provides routers out of the box). So, I made a micro router, based on history@2.x.x.
The next step was to publish it as an npm package (my main interest being the build workflow to setup on an es6+ code base specific to npm packages with multiples files).
Read the blog post about the packaging workflow to npm in multiple formats
This package is available as multiple formats: commonjs
, umd
and ecmascript modules
.
npm install lite-router
import router from 'lite-router';
/**
* Simple handler on route "/home" and any routes (since using the wildcard "*")
*/
const mountHome = () => {
// code to run on route match
document.getElementById('home-content').style.display = 'block';
const unMount = () => {
// code to run on route leave (you wight wanna clean listeners or others)
document.getElementById('home-content').style.display = 'none';
};
// always return the unMount method
return unMount;
};
/**
* Param matching on route "/router/posts/:category/:title/edit"
* params will contain an object like {category: "foo", title: "bar"}
*
* Also using Regexp matching: /^\/router\/user\/([^\/?#]+)\/([^\/?#]+)$/i
*/
const mountParams = ({ location, params, history }) => {
document.getElementById('params-content').style.display = 'block';
console.log(location, params, history);
const unMount = () => {
document.getElementById('params-content').style.display = 'none';
};
return unMount;
}
const routes = [
{ pattern: '/', handler: mountHome },
{ pattern: '/router/posts/:category/:title/edit', handler: mountParams },
{ pattern: /^\/router\/user\/([^\/?#]+)\/([^\/?#]+)$/i, handler: routerHandler },
{ pattern: '/defered-mounting', handler: mountHome, resolve: new Promise(res => setTimeout(res, 1000)) } // will mount mountHome handler on /defered-mounting once the resolve promise is resolve
{ pattern: '*' handler: mountHome }
];
// init router and return the unlisten function to use eventually when you'll be done
const unlisten = router(routes);
You'll find the example folder which contains basic examples. A DEMO is available here.
More advanced examples can be found on rxjs-experiments:
import router from lite-router
router(routes)
The routes
array contains objects with the following properties:
pattern
: can be:
/foo/bar
/posts/:category/:title/edit
params
parameter of the handler/^\/router\/user\/([^\/?#]+)\/([^\/?#]+)$/i
handler
: the function that will mount your view, must return an unmount
function (to cleanup eventually)
({ location, params, history }) => [Function] unmount
Promise
, that when resolved, will let the matched handler mountgit clone https://github.com/topheman/lite-router.git
cd lite-router
yarn
Install, then eventually, npm link
the library to use it in local.
In your own project where you want to locally test lite-router
, just run npm link lite-router
.
npm run build
lib
dir): npm run build:commonjs
es
dir): npm run build:es
dist/lite-router.js
) : npm run build:umd
dist/lite-router.min.js
) : npm run build:umd:min
npm run build:watch
or npm run build:commonjs:watch
npm run build:umd:watch
npm run build:es:watch
npm test
(will also lint the source code)npm run jest
npm run jest:watch
The tests are in the tests
folder, it is ran via jest.
npm run build
npm publish
The gh-pages tracking branch is binded in build/dist
folder. If you haven't it yet:
mkdir build
cd build
mkdir dist
cd dist
git init
git remote add origin https://github.com/topheman/lite-router.git
git fetch origin gh-pages
git checkout gh-pages
If you already have a build/dist
folder, to update the github pages:
npm run example:build
cd build/dist
git add .
git commit -m "Update gh-pages"
git push origin gh-pages
Copyright 2017 © Christophe Rosset
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the Software.
FAQs
A very light router based on history package
The npm package lite-router receives a total of 0 weekly downloads. As such, lite-router popularity was classified as not popular.
We found that lite-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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.