All files / datamodel/src value.js

100% Statements 5/5
100% Branches 0/0
100% Functions 4/4
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66                                      1125x             1125x                       308x                     1x                     61x          
/**
 * The wrapper class on top of the
 * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types | primitive} value of a
 * field.
 *
 * @todo Need to have support for StringValue, NumberValue, DateTimeValue and GeoValue.
 *
 * @class Value
 * @public
 */
class Value {
 
  /**
   * Creates new Value instance.
   *
   * @param {*} val - the primitive value from the field cell.
   * @param {string | Field} field - The field from which the value belongs.
   */
    constructor (val, field) {
        Object.defineProperty(this, '_value', {
            enumerable: false,
            configurable: false,
            writable: false,
            value: val
        });
 
        this.field = field;
    }
 
  /**
   * Returns the underlaying wrapped value.
   *
   * @public
   * @getter
   *
   * @return {*} Returns the current value.
   */
    get value () {
        return this._value;
    }
 
  /**
   * String representation of the underlying value. If there is a hint of string operations, this function gets called.
   *
   * @override
   *
   * @return {string} Returns a human readable string of the field value.
   */
    toString () {
        return String(this.value);
    }
 
  /**
   * Returns the value of the field. If there is a hint of converting the value to integer, this gets called.
   *
   * @override
   *
   * @return {*} Returns the field value.
   */
    valueOf () {
        return this.value;
    }
}
 
export default Value;