1.0.1 • Published 2 years ago

k-toolbox v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

k-toolbox

It is small set for util functions

Installation

Install k-toolbox with npm or yarn

npm i k-toolbox
yarn add k-toolbox

Functions List

NameDescription
factoryUsed for creating object instances
extendit is equivalent to extends keyword for class but here we can extend factory instances

Usage/Examples

factory

import { factory } from 'k-toolbox'

const Vehicle = factory((t) => {
  
    let fuel = 100 // private variable
  
    t.drive = () => fuel--
  
    t.checkFuel = () => console.log(fuel)
  
    t.refill = (f) => fuel += Math.min(f, 100 - fuel)
  
})

const vehicle = Vehicle()

vehicle.drive()
vehicle.drive()

vehicle.checkFuel() // 98

vehicle.refill(2) 

vehicle.checkFuel() // 100

Authors