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

137 lines (110 loc) 4.3 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _bunyan = require('bunyan'); var _bunyan2 = _interopRequireDefault(_bunyan); var _types = require('../constants/types'); var _fieldFunctions = require('../methods/field-functions'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var log = _bunyan2.default.createLogger({ name: "AccessorsOMat" }); var _accessorMethods = { /** * sets this field to become a simple getter in the target class * ( NOTE: for performance reasons, * Getter function operates as a function with no parameters, * not as a traditional getter field ) * @return {FieldOMat} this */ getter: function getter() { var _default = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _types.NONE; this._params.accessorGetter = _fieldFunctions.getter; this.default(_default); return this; }, /** * sets this field to become a simple setter in the target class * ( NOTE: for performance reasons, * Setter function operates as a function with a value parameter, * not a * @return {FieldOMat} this */ setter: function setter() { var _default = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _types.NONE; this._params.accessorGetter = _fieldFunctions.setter; this.default(_default); return this; }, staticSetter: function staticSetter() { var staticValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _types.NONE; this._params.accessorGetter = _fieldFunctions.staticSetter; this._params.staticValue = staticValue; return this; }, /** * sets this field to become a getter or setter depending upon if a * value argument is passed in. * If [fieldName]() is called, this is a getter, * if [fieldName](someValue) is called, this sets the value to someValue * NOTE: This type of function uses an internal symbol to represent a null * value, which means that passing in falsey values ( false, 0, -x, null) * will SET that falsey value as a parameter. * @return {FieldOMat} this */ getterSetter: function getterSetter() { var _default = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _types.NONE; this._params.accessorGetter = _fieldFunctions.getterSetter; this.default(_default); return this; }, /** * sets this field to become a getter or setter depending upon if a * value argument is passed in.. However, provides an option to trigger * either an error or a fail gracefully when setting * to ensure that null values return a chain. * If [fieldName]() is called, this is a getter, * if [fieldName](someValue) is called, this sets the value to someValue * NOTE: This type of function uses an internal symbol to represent a null * value, which means that passing in falsey values ( false, 0, -x, null) * will SET that falsey value as a parameter. * @return {FieldOMat} this */ getterSetterSafe: function getterSetterSafe() { var _default = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _types.NONE; this._params.accessorGetter = _fieldFunctions.getterSetterSafe; this.default(_default); return this; }, /** * setter that will toggle true or false. * @return {FieldOMat} this */ toggler: function toggler() { var _default = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; this._params.accessorGetter = _fieldFunctions.toggler; this.default(_default); return this; }, /** * A Setter that will return the original value. * @return {FieldOMat} this */ swapper: function swapper() { var _default = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _types.NONE; this._params.accessorGetter = _fieldFunctions.swapper; this.default(_default); return this; }, queue: function queue() { this._params.isStack = false; this._params.isQueue = true; return this; }, stack: function stack() { this._params.isQueue = false; this._params.isStack = true; return this; } }; exports.default = _accessorMethods; //# sourceMappingURL=_accessor-methods.js.map