CerberusMVC Documentation

Library


This is a good place to put tools, static classes full of helper stuff, or load in 3rd party things not in npm. There is no structure here or stipulation, as library tools they should not have any interaction with the stack apart from what is written. Nothing will be exposed to a library apart from what you pass in, therefore we do not extend anything when creating library tools.

Bundled Libary Classes

The following bundled library classes already exist in cerberus-mvc...

cerberus-mvc/Library/Comms

exports Comms

A generic communications class. Currently supports SES thorugh AWS. This class will be extended to act as a singular way to send communications regardless of provider. All current emails will be sent via SES only.

cerberus-mvc/Library/Crypto

exports Crypto

A generic crypto library bundling some usefull static methods such as md5, sha256, passwordHash, encoding, decoding and more.

cerberus-mvc/Library/DataTools

exports DataTools

A generic tool class to give you some nice data methods such as camelToSnake and snakeToCamel. These tools revolve around conversion and data checking.

cerberus-mvc/Library/ObjectTools

exports ObjectTools

A generic tool class to give you some nice object methods such as property checking and property searching. These tools revolve around object manipulation.

Example Library Tool

The following code is an example of how we structure possible library code, where we may place nice to use functions.

This particular library is actually part of the MVC stack and can be imported from the stack with...

const ObjectTools = require('cerberus-mvc/Library/ObjectTools')

cerberus-mvc/Library/ObjectTools.js (library)

'use strict';

/**
 * @namespace MVC/Library
 * @class ObjectTools
 * @description Set of tools for playing with objects
 * @author Paul Smith (ulsmith)  
 * @copyright 2020 Paul Smith (ulsmith) all rights reserved
 * @license MIT 
 */
class ObjectTools {

	/**
	 * @public @static @name propertiesMatch
	 * @description Check properties match in two objects, to ensure they have the same properties in both
	 * @param {String} obj1 The first object
	 * @param {String} obj2 The second object
	 * @return {Boolean} True is both objects have the same properties
	 */
	static propertiesMatch(obj1, obj2) {
		let i = Object.keys(Object.assign({}, obj1, obj2)).length;
		return i === Object.keys(obj1).length && i === Object.keys(obj2).length;
	}

	/**
	 * @public @static @name propertiesExist
	 * @description Check properties from obj1 exist in obj2, to ensure min requirement is met
	 * @param {String} obj1 The first object
	 * @param {String} obj2 The second object
	 * @return {Boolean} True is both objects have the same properties
	 */
	static propertiesExist(obj1, obj2) {
		for (const key in obj1) if (!obj2[key]) return false;
		return true
	}
}

module.exports = ObjectTools;