
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Functional client-side router in ~570 bytes, built on HTML5 History API
You might also be interested in mitt - a 200 bytes event emitter, and hyperapp - build rich UI apps with 1kb.
:sparkles: Pull requests for client-side tests or any other features/fixes are welcome! :rocket:
(TOC generated by verb using markdown-toc)
Install with npm
$ npm install gibon --save
or install using yarn
$ yarn add gibon
The UMD build is also available on unpkg CDN
<script src="https://unpkg.com/gibon/dist/gibon.umd.js"></script>
or on RawGit CDN
<script src="https://cdn.rawgit.com/tunnckoCore/gibon/master/dist/gibon.umd.js"></script>
For more use-cases see the tests
const router = gibon({
'/': (state) => console.log('home'),
'/about': (state) => console.log('about'),
'/users/:user': (state, params) => console.log('user:', params.user),
'/users/:user/edit': (state, params) => {
console.log('edit user:', params.user)
},
'/groups/:group/users/:user': (state, params) => {
console.log('user:', params.user, 'group:', params.group)
}
})
router.start()
Object with key/value pairs, where key is the route and value should be a function that has (state, params) signature.
route - path like /users/:uservalue - function that has (state, params) signatureThe route path syntax is based on the same syntax found in Express.
const userView = (state, params) => {
console.log('user:', params.user)
}
const router = gibon({
'/users/:user': userView
})
router.start()
It should be function that is triggered every time when given route is accessed. Completely optional, but useful for higher level things such as seen in hyperapp.
It is passed with (view, state, el) signature. See public/dom.js example.
view - always a function for the routestate - value that is passed as second argument to .render() methodel - previous dom element (if bel is used for example) or undefinedconst html = requre('bel')
const state = {
title: 'Welcome!'
}
const routes = {
'/users/:user': (state, params) => html`<div>
<h1>${state.title}</h1>
<h2>${params.user}</h2>
</div>`
}
// some entry point
const main = document.querySelector('#app')
const helper = (parent, child) => {
return parent.replaceChild(child, parent.childNodes[0])
}
const onRoute = (view, _, el) => {
return helper(main, view(state))
}
const router = gibon(routes, onRoute)
router.start()
For complete working example see public/nanomorph.js, which uses nanomorph to do the diffing and updating only needed dom elements.
It should be function that controls behaviour of clicking on links. We intercept all <a href="/path">...</a> clicks. If you want to opt out of this, add the custom attribute data-no-routing to any anchor element that should be handled differently.
It is passed with (e, render) signature.
e - the clicked a elementrender - function which is the .render() methodAll that just means that it is perfectly configured by default to work on pushState servers, so page won't refresh while you move through pages of the defined routes.
Try out some of the provided examples in public/.
Starts the router. Function that starts the router to listen on routes. If you not call it, it won't attach any listeners, so it won't work.
We can use .render() without .start()ing the router.
You can use that to manually render view with optional state. It returns what the view returns, so if
the view returns a DOM element, then el will be that element.
view - string path to route, or function like userViewstate - optional, any value that you wantconst router = gibon()
const userView = (state, params) => {
console.log('title is', state.title)
}
router.render(userView, { title: 'hello world' })
The cool thing comes when you use some Virtual or Real DOM builder, such as bel or hyperx.
In the next example we are using bel to define some HTML without breaking the JavaScript and we "render" some specific route with some context/state, and finally we append it ot the page body.
const html = require('bel')
const router = gibon({
'/users/:user': (state, params) => html`<div>
<h1>${state.title}</h1>
<h2>user is ${params.user}</h2>
</div>`
})
const el = router.render('/users/tunnckoCore', { title: 'hello world' })
document.body.appendChild(el)
So we'll get such that div in the document body
<div>
<h1>hello world</h1>
<h2>user is tunnckoCore</h2>
</div>
Run some of the examples by cloning the repo and calling them through npm scripts
npm run example:nanomorph
npm run example:simple
npm run example:dom
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guidelines for advice on opening issues, pull requests, and coding standards.
If you need some help and can spent some cash, feel free to contact me at CodeMentor.io too.
In short: If you want to contribute to that project, please follow these things
npm run commit to commit changes instead of git commit, because it is interactive and user-friendly. It uses commitizen behind the scenes, which follows Conventional Changelog idealogy.npm run release, which is standard-version and follows Conventional Changelog idealogy.Thanks a lot! :)
Documentation and that readme is generated using verb-generate-readme, which is a verb generator, so you need to install both of them and then run verb command like that
$ npm install verbose/verb#dev verb-generate-readme --global && verb
Please don't edit the README directly. Any changes to the readme must be made in .verb.md.
Clone repository and run the following in that cloned directory
$ npm install && npm test
Charlike Mike Reagent
Copyright © 2016-2017, Charlike Mike Reagent. MIT
This file was generated by verb-generate-readme, v0.6.0, on May 04, 2017.
Project scaffolded using charlike cli.
FAQs
Functional client-side router in ~570 bytes, built on HTML5 History API
The npm package gibon receives a total of 0 weekly downloads. As such, gibon popularity was classified as not popular.
We found that gibon 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.