UNPKG

class-o-mat

Version:

ALPHA VERSION ONLY: class-o-mats will help to create getter-setter functionality with validations that can be attached to a container class for easier coding. Some basic validations are included. class-o-mats also has the ability to store params as bloc

47 lines (39 loc) 1.25 kB
import Bunyan from 'bunyan'; const log = Bunyan.createLogger({name: "ApiOMat"}); import merger from 'lodash.merge'; import { NONE } from '../constants/types'; import { getterSetter as gs, toggler as tg } from './class-o-mat-field-functions'; const apiMethods = { /** * getter setter for key * @param {string} name * @return {string|ClassOMat} */ key(key=NONE) { return gs(this, 'key', key) }, /** * get or set the params object. If merge === NONE * the new params completely override existing ones. * If merge = true, the new params are merged into the * existing params, and the existing params take precedence. * * If merge = false, the existing params are merged * into the new params * ( new params take precedence ) * @param {object} params * @param {Boolean} merge ( default = true) * @return {object|Paramset} the params or this */ params(params=NONE, merge=NONE) { if (params===NONE) return this._params; if (merge === true) { params = merger(this._params, params); } else if (merge === false) { params = merger(params, this._params); } this._params = params; return this; } } export default apiMethods;