UNPKG

abolish

Version:

A javascript object validator.

103 lines (102 loc) 2.33 kB
"use strict"; const inbuilt_fn_1 = require("./inbuilt.fn"); const lodash_1 = require("lodash"); /** * ObjectOnValidation * Handles object being validated. */ class ObjectModifier { constructor(data, param, name = false) { this.data = data; this.path = param; this.name = name; this.pathHasDotNotation = (0, inbuilt_fn_1.hasDotNotation)(param); return this; } // flagNoData() { // this.$hasData = false; // return this; // } setData(data) { this.data = data; // this.$hasData = true; return this; } // get hasData() { // return this.$hasData; // } /** * Get path of object or return * @method * @param path * @return {*} */ get(path) { return (0, inbuilt_fn_1.abolish_Get)(this.data, path); } /** * Get path of current key being validated * @method */ getThis() { return this.get(this.path); } /** * Has path in object * @method * @param path * @return {boolean} */ has(path) { return (0, lodash_1.has)(this.data, path); } /** * abolish_Set value to path of object * @method * @param path * @param value * @return {object} */ set(path, value) { return (0, inbuilt_fn_1.abolish_Set)(this.data, path, value); } /** * abolish_Set value to this param path * @methods * @param value * @return {*} */ setThis(value) { return (0, inbuilt_fn_1.abolish_Set)(this.data, this.path, value, this.pathHasDotNotation); } /** * Unset a path in object * @method * @param path * @return {boolean} */ unset(path) { return (0, lodash_1.unset)(this.data, path); } /** * Unset this path in object * @method * @return {boolean} */ unsetThis() { return (0, lodash_1.unset)(this.data, this.path); } /** * Get current path but with abolish_StartCase */ getName() { return this.name || (0, inbuilt_fn_1.abolish_StartCase)(this.path); } /** * Get current path but with abolish_StartCase */ getNameRaw() { return this.name || this.path; } } module.exports = ObjectModifier;