@basekits/core
Super extensible utility library for javascript apps.
As an alternative to lodash or underscore, basekits is a modular, fast and powerful helper library for javascript apps.
Introduction
The core package has no utility or helper. Utility and helper functions are provided by kits. A kit, is a group of helper functions. The core allows you to add/update/remove kits.
Installation
Through npm:
npm i @basekits/core
Usage and Sample Kit
Let's create a sample kit that has two functions which are isString
and isUUID
:
const sampleKit = {
name: 'sample',
items: {
isString: function isString(v) {
return typeof v == 'string'
},
isUUID: function isUUID(v) {
return this.regexes.uuid.test(v)
}
},
opts: {
regexes: {
uuid: /[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/g
}
}
}
name
, items
and opts
are the three main properties that creates the kit. Now we are going to see how core eats them:
const kit = require('@basekits/core')
// add kit
kit.addKit(sampleKit)
// all valid items registered
kit.isString('some string') // returns true
kit.isString(12) // returns false
kit.isUUID('109156be-c4fb-41ea-b1b4-efe1671c5836') // returns true
As you see above, all items registered as a property for kit
and ready to use. regexes
property in opts indicates that the kit is going to need some regular expressions in order to work. core stores regular expressions in its regexes
property and they can be accessible in this.regexes
property as you can see above in isUUID
.
If you would like to add, update or remove an item in the sample kit:
kit.sample.removeItem('isString')
// kit.isString is not available anymore
kit.sample.addItem('isString', function isString() {/*...*/})
kit.isString('') // returns true
// replace existing function with the new one
kit.sample.updateItem('isString', function isString() {/**/})
Kits Available To Use
No one needs to write its own kit unless there is a special need. There are many kits written already and anyone can start using it right away:
- @basekits/kit-type
- @basekits/kit-array
- @basekits/kit-error
- @basekits/kit-object
- @basekits/kit-validator
- @basekits/kit-dom
- @basekits/kit-hashing
- @basekits/kit-function
- @basekits/kit-string
Development & Contributing
Clone this repo and run test:
npm run test
Run builds:
npm run builds
Make a pull request.