Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

minibase

node-minibase37MIT1.0.1

Minimalist alternative for Base. Build complex APIs with small units called plugins. Works well with most of the already existing [base][] plugins.

app, app-base, application, apps, async, base, baseplugin, basic, boilerplate, callback, cb, core, corebase, define, elegance, foundation, kickstart, main, methods, micro, microbase, mini, minibase, minimal, minimalist, nano, nanobase, node, nodejs, plugin, plugins, small, smart, smart-plugins, starter, starterkit, sync, synchronous, use

readme

minibase NPM version NPM downloads npm total downloads

Minimalist alternative for Base. Build complex APIs with small units called plugins. Works well with most of the already existing base plugins.

code climate standard code style linux build status windows build status coverage status dependency status

You might also be interested in base.

Table of Contents

(TOC generated by verb using markdown-toc)

Install

Install with npm

$ npm install minibase --save

or install using yarn

$ yarn add minibase

Usage

For more use-cases see the tests

const minibase = require('minibase')

API

MiniBase

Creates an instance of MiniBase with optional options object - if given, otherwise the minibase.options defaults to empty object. Never throws - emit events!™

Params

  • [options] {Object}: optional, written to this.options

Example

const MiniBase = require('minibase').MiniBase

// main export is instance
const app = require('minibase')

app.once('error', (err) => {
  console.log('error:', err)
})

app.use((self) => {
  // this === self === app
  console.log(self.use) // => 'function'
  console.log(self.define) // => 'function'
  self.define('foo', 'bar')
})

app.use(() => {
  throw new Error('qux')
})

.delegate

Copy properties from provider to this instance of MiniBase, using delegate-properties lib.

Params

  • <provider> {Object}: object providing properties
  • returns {Object}: Returns instance 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 with value on the instance, using define-property lib.

Params

  • key {String}: name of the property to be defined or modified
  • value {any}: descriptor for the property being defined or modified
  • returns {Object}: Returns instance 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 synchronous plugin fn function to be called immediately upon init. Never throws - emit events!™

Params

  • fn {Function}: plugin passed with ctx which is the instance
  • returns {Object}: Returns instance for chaining

Events

  • emits: error when plugin fn throws an error

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 to receiver and make them non-enumerable.

See delegate-properties for more details, it is exact mirror.

Params

  • receiver {Object}: object receiving properties
  • provider {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 property
  • prop {Object}: The name of the property to be defined or modified
  • descriptor {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 extend
  • methods {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

Contributing

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

  1. Please DO NOT edit README.md, CHANGELOG.md and .verb.md files. See "Building docs" section.
  2. Ensure anything is okey by installing the dependencies and run the tests. See "Running tests" section.
  3. Always use 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.
  4. Do NOT bump the version in package.json. For that we use npm run release, which is standard-version and follows Conventional Changelog idealogy.

Thanks a lot! :)

Building docs

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.

Running tests

Clone repository and run the following in that cloned directory

$ npm install && npm test

Author

Charlike Mike Reagent

License

Copyright © 2016, Charlike Mike Reagent. Released under the MIT license.


This file was generated by verb-generate-readme, v0.2.0, on December 05, 2016.

changelog

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.0.1 (2016-12-05)

Bug Fixes

  • deps: update deps (2e2d41c)
  • package: update isobject to version 3.0.0 (#10) (0910ffe)
  • update: fix link (f409b59)

1.0.0 (2016-11-17)

Bug Fixes

  • license: fix license year in banner comments (5b9dabb)
  • package: bump minibase-tests to laltest (b2b3f0e)

BREAKING CHANGES

  • license: First stable release. No real breaking changes. It's just time for v1.

0.4.8 (2016-11-17)

Bug Fixes

  • appveyor: update appveyor, no failures are allowed (c100048)
  • package: bump minibase-tests (4a80c3d)

0.4.7 (2016-11-15)

Bug Fixes

  • remove: remove use emitting and default error handler (724f35b)

0.4.6 (2016-11-14)

Bug Fixes

  • tests: update tests, bump minibase-tests (571e2c5)
  • tests: update tests, use "minibase-tests" (381c1d1)

0.4.5 (2016-11-14)

Bug Fixes

  • errors: improve default error handler message (37fa883)
  • plugins: force synchronous plugins (b2e720d)

0.4.4 (2016-11-13)

Bug Fixes

  • node: support node >= 0.10.0 (af929e8)

0.4.3 (2016-11-13)

Bug Fixes

  • options: extend options (bd59ed2)

0.4.2 (2016-11-09)

Bug Fixes

  • deps: dependencies update related changes (2cfde06)
  • emits: emit use on successful completion (46e4407)
  • logo: fix logo links (3282577)
  • names: fix anonymous plugins, fallback (0a506b7), closes #1

0.0.0 - 2016-10-24

  • Inital commit