vital-utils
v1.1.9
Published
A collection of utility functions
Downloads
21
Readme
Vital Utils
It is always a good idea to have a set of utilities that you can use in your projects. This is a collection of utilities that I have found useful in my projects. I will keep adding to this list as I find more utilities that I find useful.
Installation
bun add vital-utils@latest
Usage
Currently, the following utilities are available:
1. Expand Menu
To expand a nested object into an array of objects. Useful in case of creating a sidebar menu from a nested object.
import { expandMenu } from 'vital-utils'
const object = {
Admin: {
_icon_: 'admin', // _icon_ will be added "icon": "admin" to the parent object i.e. Admin in this case
Dashboard: '/dashboard',
Orders: {
_href_: '/dashboard/orders', // _href_ will be added "href": "/dashboard/orders" to the parent object i.e. Orders in this case
Pending: '/dashboard/orders/pending',
},
Products: '/dashboard/products',
},
}
// _keys_ are used as properties to be added to the parent object
const array = expandMenu(object)
Output:
[
{
"title": "Admin",
"icon": "admin",
"items": [
{
"title": "Dashboard",
"href": "/dashboard"
},
{
"title": "Orders",
"href": "/dashboard/orders",
"items": [
{
"title": "Pending",
"href": "/dashboard/orders/pending"
}
]
},
{
"title": "Products",
"href": "/dashboard/products"
}
]
}
]
Features are yet to be documented. Please refer to the source code for more information.