Package Exports
- minibase
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (minibase) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
minibase

MiniBase is minimalist approach to Base - @node-base, the awesome framework. Foundation for building complex APIs with small units called plugins. Works well with most of the already existing base plugins.
Table of Contents
Install
Install with npm
$ npm i minibase --save
Usage
For more use-cases see the tests
const MiniBase = require('minibase').MiniBase
// or instance directly
const minibase = require('minibase')
API
MiniBase
Creates an instance of
MiniBase
with optionaloptions
object - if given, otherwise theminibase.options
defaults to empty object. Never throws - emit events!™
Params
[options]
{Object}: optional, passsilent: true
to not add default error listener
Example
const MiniBase = require('minibase').MiniBase
const app = require('minibase')
// when `silent: true` it will not add
// the default event listener to `error` event
const minibase = MiniBase({ silent: true })
// nothing is printed, until you add
// listener `.on('error', fn)`
minibase.use(() => {
throw new Error('foo bar')
})
// if you work with defaults
// you will get this error printed
// because the default error handler
app.use(function () {
console.log(this.options.silent) // => undefined
throw new Error('default error handler works')
})
.delegate
Copy properties from
provider
tothis
instance ofMiniBase
, using delegate-properties lib.
Params
<provider>
{Object}: object providing propertiesreturns
{Object}: Returns instance ofMiniBase
for chaining
Example
const minibase = require('minibase')
minibase.use((app) => {
// `app` is `minibase`
app.delegate({
foo: 'bar',
qux: (name) => {
console.log(`hello ${name}`)
}
})
})
// or directly use `.delegate`,
// not through plugin
minibase.delegate({ cats: 'dogs' })
console.log(minibase.cats) // => 'dogs'
console.log(minibase.foo) // => 'bar'
console.log(minibase.qux('kitty!')) // => 'hello kitty!'
.define
Used for adding non-enumerable property
key
withvalue
on the instance, using define-property lib.
Params
key
{String}: name of the property to be defined or modifiedvalue
{any}: descriptor for the property being defined or modifiedreturns
{Object}: Returns instance ofMiniBase
for chaining
Example
const minibase = require('minibase')
minibase.use(function (app) {
// `app` and `this` are instance of `MiniBase`,
// and so `minibase`
this.define('set', function set (key, value) {
this.cache = this.cache || {}
this.cache[key] = value
return this
})
app.define('get', function get (key) {
return this.cache[key]
})
})
minibase
.set('foo', 'bar')
.set('qux', 123)
.set('baz', { a: 'b' })
// or directly use `.define`,
// not through plugin
minibase.define('hi', 'kitty')
console.log(minibase.hi) // => 'kitty'
console.log(minibase.get('foo')) // => 'bar'
console.log(minibase.get('qux')) // => 123
console.log(minibase.get('baz')) // => { a: 'b' }
// or access the cache directly
console.log(minimist.cache.baz) // => { a: 'b' }
console.log(minimist.cache.qux) // => 123
.use
Define a plugin
fn
function to be called immediately upon init. It is recommendedfn
to be synchronous and should not expect asynchronous plugins to work correctly - use plugins for this. Uses try-catch-callback under the hood to handle errors and completion of that synchronous function. Never throws - emit events!™
See try-catch-callback and/or try-catch-core for more details.
Params
fn
{Function}: plugin to be called withctx, cb
arguments, where bothctx
andthis
offn
are instance ofMiniBase
andcb
is callback - use with caution and in rare casesreturns
{Object}: Returns instance ofMiniBase
for chaining
Events
emits
:error
when pluginfn
throws an erroremits
:use
on successful completion withfn
andresult
arguments, where theresult
is returned value of the plugin
Example
const MiniBase = require('minibase').MiniBase
const app = MiniBase({ silent: true, foo: 'bar' })
app
.once('error', (err) => console.error(err.stack || err))
.use((app) => {
console.log(app.options) // => { silent: true, foo: 'bar' }
return 555
})
.use(function () {
console.log(this.options) // => { silent: true, foo: 'bar' }
// intentionally
foo bar
})
#delegate
Static method to delegate properties from
provider
toreceiver
and make them non-enumerable.
See delegate-properties for more details, it is exact mirror.
Params
receiver
{Object}: object receiving propertiesprovider
{Object}: object providing properties
Example
const MiniBase = require('minibase').MiniBase
const obj = { foo: 'bar' }
MiniBase.delegate(obj, {
qux: 123
})
console.log(obj.foo) // => 'bar'
console.log(obj.qux) // => 123
#define
Static method to define a non-enumerable property on an object.
See define-property for more details, it is exact mirror.
Params
obj
{Object}: The object on which to define the propertyprop
{Object}: The name of the property to be defined or modifieddescriptor
{any}: The descriptor for the property being defined or modified
Example
const MiniBase = require('minibase').MiniBase
const obj = {}
MiniBase.define(obj, 'foo', 123)
MiniBase.define(obj, 'bar', () => console.log('qux'))
console.log(obj.foo) // => 123
console.log(obj.bar()) // => 'qux'
#extend
Static method for inheriting the prototype and static methods of the
MiniBase
class. This method greatly simplifies the process of creating inheritance-based applications.
See static-extend for more details.
Params
Ctor
{Function}: constructor to extendmethods
{Object}: optional prototype properties to mix in
Example
const MiniBase = require('minibase').MiniBase
function MyApp (options) {
MiniBase.call(this, options)
}
MiniBase.extend(MyApp)
console.log(MyApp.extend) // => function
console.log(MyApp.define) // => function
console.log(MyApp.delegate) // => function
const app = new MyApp()
console.log(app.use) // => function
console.log(app.define) // => function
console.log(app.delegate) // => function
Related
- base-app: Starting point for creating a base application, with a few light plugins… more | homepage
- base-plugins-enhanced: Error handling and extras for
.use
and.run
methods of your Base… more | homepage - base-plugins: Upgrade's plugin support in base applications to allow plugins to be called… more | homepage
- base-task: base plugin that provides a very thin wrapper around https://github.com/doowb/composer for adding… more | homepage
- base: base is the foundation for creating modular, unit testable and highly pluggable… more | homepage
- generate: Command line tool and developer framework for scaffolding out new GitHub projects… more | homepage
- lazy-cache: Cache requires to be lazy-loaded when needed. | homepage
- use: Easily add plugin support to your node.js application. | homepage
- verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use… more | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.