Gathering detailed insights and metrics for base
Gathering detailed insights and metrics for base
Gathering detailed insights and metrics for base
Gathering detailed insights and metrics for base
Base is the foundation for creating modular, unit testable and highly pluggable, server-side node.js applications.
npm install base
76
Supply Chain
97.3
Quality
75.3
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
103 Stars
217 Commits
20 Forks
6 Watching
5 Branches
9 Contributors
Updated on 24 Sept 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-3.8%
2,807,443
Compared to previous day
Last week
6.1%
16,407,378
Compared to previous week
Last month
37.2%
59,233,380
Compared to previous month
Last year
-20.7%
603,867,281
Compared to previous year
5
5
Base is a foundation for creating modular, unit testable and highly pluggable server-side node.js APIs.
Most importantly, once you learn Base, you will be familiar with the core API of all applications built on Base. This means you will not only benefit as a developer, but as a user as well.
The core team follows these principles to help guide API decisions:
Compact API surface: The smaller the API surface, the easier the library will be to learn and use.
Easy to extend: Implementors can use any npm package, and write plugins in pure JavaScript. If you're building complex apps, Base dramatically simplifies inheritance.
Easy to test: No special setup should be required to unit test Base
or base plugins
100% Node.js core style
The API was designed to provide only the minimum necessary functionality for creating a useful application, with or without plugins.
Base core
Base itself ships with only a handful of useful methods, such as:
.set
: for setting values on the instance.get
: for getting values from the instance.has
: to check if a property exists on the instance.define
: for setting non-enumerable values on the instance.use
: for adding pluginsBe generic
When deciding on method to add or remove, we try to answer these questions:
Plugin system
It couldn't be easier to extend Base with any features or custom functionality you can think of.
Base plugins are just functions that take an instance of Base
:
1var base = new Base(); 2 3function plugin(base) { 4 // do plugin stuff, in pure JavaScript 5} 6// use the plugin 7base.use(plugin);
Add "smart plugin" functionality with the base-plugins plugin.
Inheritance
Easily inherit Base using .extend
:
1var Base = require('base'); 2 3function MyApp() { 4 Base.call(this); 5} 6Base.extend(MyApp); 7 8var app = new MyApp(); 9app.set('a', 'b'); 10app.get('a'); 11//=> 'b';
Inherit or instantiate with a namespace
By default, the .get
, .set
and .has
methods set and get values from the root of the base
instance. You can customize this using the .namespace
method exposed on the exported function. For example:
1var Base = require('base'); 2// get and set values on the `base.cache` object 3var base = Base.namespace('cache'); 4 5var app = base(); 6app.set('foo', 'bar'); 7console.log(app.cache.foo); 8//=> 'bar'
NPM
Install with npm:
1$ npm install --save base
yarn
Install with yarn:
1$ yarn add base && yarn upgrade
1var Base = require('base'); 2var app = new Base(); 3 4// set a value 5app.set('foo', 'bar'); 6console.log(app.foo); 7//=> 'bar' 8 9// register a plugin 10app.use(function() { 11 // do stuff (see API docs for ".use") 12});
Create an instance of Base
with the given cache
and options
. Learn about the cache object.
Params
cache
{Object}: If supplied, this object is passed to cache-base to merge onto the the instance.options
{Object}: If supplied, this object is used to initialize the base.options
object.Example
1// initialize with `cache` and `options` 2const app = new Base({isApp: true}, {abc: true}); 3app.set('foo', 'bar'); 4 5// values defined with the given `cache` object will be on the root of the instance 6console.log(app.baz); //=> undefined 7console.log(app.foo); //=> 'bar' 8// or use `.get` 9console.log(app.get('isApp')); //=> true 10console.log(app.get('foo')); //=> 'bar' 11 12// values defined with the given `options` object will be on `app.options 13console.log(app.options.abc); //=> true
Set the given name
on app._name
and app.is*
properties. Used for doing lookups in plugins.
Params
name
{String}returns
{Boolean}Example
1app.is('collection'); 2console.log(app.type); 3//=> 'collection' 4console.log(app.isCollection); 5//=> true
Returns true if a plugin has already been registered on an instance.
Plugin implementors are encouraged to use this first thing in a plugin to prevent the plugin from being called more than once on the same instance.
Params
name
{String}: The plugin name.register
{Boolean}: If the plugin if not already registered, to record it as being registered pass true
as the second argument.returns
{Boolean}: Returns true if a plugin is already registered.Events
emits
: plugin
Emits the name of the plugin being registered. Useful for unit tests, to ensure plugins are only registered once.Example
1const base = new Base(); 2base.use(function(app) { 3 if (app.isRegistered('myPlugin')) return; 4 // do stuff to `app` 5}); 6 7// to also record the plugin as being registered 8base.use(function(app) { 9 if (app.isRegistered('myPlugin', true)) return; 10 // do stuff to `app` 11});
Call a plugin function or array of plugin functions on the instance. Plugins are called with an instance of base, and options (if defined).
Params
name
{String|Function|Array}: (optional) plugin nameplugin
{Function|Array}: plugin function, or array of functions, to call.returns
{Object}: Returns the item instance for chaining.Example
1const app = new Base() 2 .use([foo, bar]) 3 .use(baz)
The .define
method is used for adding non-enumerable property on the instance. Dot-notation is not supported with define
.
Params
key
{String}: The name of the property to define.value
{any}returns
{Object}: Returns the instance for chaining.Example
1// example of a custom arbitrary `render` function created with lodash's `template` method 2app.define('render', (str, locals) => _.template(str)(locals));
Getter/setter used when creating nested instances of Base
, for storing a reference to the first ancestor instance. This works by setting an instance of Base
on the parent
property of a "child" instance. The base
property defaults to the current instance if no parent
property is defined.
Example
1// create an instance of `Base`, this is our first ("base") instance 2const first = new Base(); 3first.foo = 'bar'; // arbitrary property, to make it easier to see what's happening later 4 5// create another instance 6const second = new Base(); 7// create a reference to the first instance (`first`) 8second.parent = first; 9 10// create another instance 11const third = new Base(); 12// create a reference to the previous instance (`second`) 13// repeat this pattern every time a "child" instance is created 14third.parent = second; 15 16// we can always access the first instance using the `base` property 17console.log(first.base.foo); 18//=> 'bar' 19console.log(second.base.foo); 20//=> 'bar' 21console.log(third.base.foo); 22//=> 'bar'
Static method for adding global plugin functions that will be added to an instance when created.
Params
fn
{Function}: Plugin function to use on each instance.returns
{Object}: Returns the Base
constructor for chainingExample
1Base.use(function(app) { 2 app.foo = 'bar'; 3}); 4const app = new Base(); 5console.log(app.foo); 6//=> 'bar'
Cache
User-defined properties go on the cache
object. This keeps the root of the instance clean, so that only reserved methods and properties on the root.
1Base { cache: {} }
You can pass a custom object to use as the cache
as the first argument to the Base
class when instantiating.
1const myObject = {}; 2const Base = require('base'); 3const base = new Base(myObject);
Base is part of the Toolkit suite of applications.
Toolkit is a collection of node.js libraries, applications and frameworks for helping developers quickly create high quality node.js applications, web projects, and command-line experiences. There are many other libraries on NPM for handling specific tasks, Toolkit provides the systems and building blocks for creating higher level workflows and processes around those libraries.
Toolkit can be used to create a static site generator, blog framework, documentaton system, command line, task or plugin runner, and more!
Building Blocks
The following libraries can be used as "building blocks" for creating modular applications.
Lifecycle Applications
The following applications provide workflows and automation for common phases of the software development lifecycle. Each of these tools can be used entirely standalone or bundled together.
data
method to base-methods. | homepagebase
application. | homepageoption
, enable
and disable
. See the readme… more | homepagepkg
method that exposes pkg-store to your base application. | homepageRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
1$ npm install && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
If Base doesn't do what you need, please let us know.
See the changelog;
Jon Schlinkert
Brian Woodward
Copyright © 2018, Jon Schlinkert. MIT
This file was generated by verb-generate-readme, v0.6.0, on March 29, 2018.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 3/25 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More