@function buildMockAttribute

create the correct mock method or property based on the configuration
value

@param {*} val

@returns {*}
970986
function buildMockAttribute (val) {
    // if value is not a function then this is a property not a method
    // if value is a regular function then it is a custom method
    if (typeof val !== 'function' || val.toString().match(/^\s*function/)) {
        return val
    }
    // if value is an arrow function then the value return by this function
    // is the value to be returned by the mock method
    else {
        // get actual value by calling function
        val = val()
        // if value is anything other than array then convert it to first element
        // of single element array so that it will always be returned when the
        // method is called
        if (!Array.isArray(val)) {
            val = [val]
        }
        // counter to keep track of how many times method has been called
        var callIndex = 0
        // return new method for object
        return function () {
            // loop through list of values on multiple calls
            if (callIndex > val.length - 1) {
                callIndex = 0
            }
            // get the next value and increment index
            var ret = val[callIndex++]
            // if value is a plain function or not a function then return it
            if (typeof ret !== 'function' || ret.toString().match(/^\s*function/)) {
                return ret
            }
            // otherwise val is an arrow function - call with original args
            else {
                return ret.apply(this, arguments)
            }
        }
    }
}
33151
public HttpClientMockBuilder withParameter(String name, String value) {
        return withParameter(name, equalTo(value));
    }
915791
function buildViewAttribsFire( def, code ) {
    code.pm = true;
    const attribs = def[ "view.attribs" ];
    if ( typeof attribs !== 'object' ) return;
    try {
        for ( const attName of Object.keys( attribs ) ) {
            const camelCaseAttName = camelCase( attName );
            if ( !code.isAction( attName ) ) {
                buildViewAttribsInitFire( camelCaseAttName, code );
            }
        }
    } catch ( ex ) {
        bubble( ex, `...in buildViewAttribsFire - view.attribs: ${JSON.stringify(attribs, null, "  ")}` );
    }
}
302067
public static void assertVarValue( Object val) throws IllegalArgumentException
    {
    if( !isVarValue( val))
      {
      throw new IllegalArgumentException( "\"" + String.valueOf( val) + "\"" + " is not a valid variable value");
      }
    }
873402
static <T extends FunctionMeta> T createAttributeFunctionMeta(Class<T> metaClass, String formula, IDataModel model) throws Exception {
        T meta = (T) metaClass.newInstance().parse(formula);
        meta.setDataModelId(model.getDataModelId());
        if (meta.getName() == null) { meta.setName(model.getName()); }

        return meta;
    }
991932
function buildViewAttribsSpecial( attName, attValue, code ) {
    const
        type = attValue[ 0 ],
        init = attValue[ 1 ];
    let requireConverter = false;

    try {
        if ( typeof attValue.behind !== 'undefined' ) {
            buildViewAttribsSpecialCodeBehind( attName, attValue.behind, code );
        }
        if ( typeof attValue.debug !== 'undefined' ) {
            buildViewAttribsSpecialDebug( attName, attValue.debug, code );
        }
        if ( Array.isArray( type ) ) {
            // Enumerate.
            code.addCast( "enum" );
            code.section.attribs.define.push(
                "pm.create(" + JSON.stringify( attName ) +
                `, { cast: conv_enum(${JSON.stringify(type)}), init: ${JSON.stringify(init)} });` );
            buildViewAttribsInit( attName, init, code );
        } else {
            switch ( type ) {
            case 'action':
                code.actions.push( attName );
                code.section.attribs.define.push(
                    "pm.createAction(" + JSON.stringify( attName ) + ")" );
                break;
            case 'any':
                code.section.attribs.define.push(
                    "pm.create(" + JSON.stringify( attName ) + ");" );
                buildViewAttribsInit( attName, init, code );
                break;
            case 'boolean':
            case 'booleans':
            case 'date':
            case 'color':
            case 'string':
            case 'strings':
            case 'array':
            case 'list':
            case 'intl':
            case 'time':
            case 'unit':
            case 'units':
            case 'multilang':
            case 'validator':
                requireConverter = true;
                code.vars[ "conv_" + type ] = "Converters.get('" + type + "')";
                code.section.attribs.define.push(
                    "pm.create(" + JSON.stringify( attName ) +
                    ", { cast: conv_" + type + " });" );
                buildViewAttribsInit( attName, init, code );
                break;
            case 'integer':
            case 'float':
                requireConverter = true;
                code.vars[ "conv_" + type ] = "Converters.get('" + type + "')";
                // Is Not a number, take this default value.
                let nanValue = attValue.default;
                if ( typeof nanValue !== 'number' || isNaN( nanValue ) ) {
                    nanValue = 0;
                }
                code.section.attribs.define.push(
                    "pm.create(" + JSON.stringify( attName ) +
                    ", { cast: conv_" + type + "(" + nanValue + ") });" );
                buildViewAttribsInit( attName, init, code );
                break;
            default:
                throw "Unknown type \"" + type + "\" for attribute \"" + attName + "\"!";
            }
        }

        if ( requireConverter ) {
            code.requires.Converters = "require('tfw.binding.converters')";
        }
    } catch ( ex ) {
        bubble(
            ex,
            `buildViewAttribsSpecial(${attName}: ${JSON.stringify(attValue)})`
        );
    }
}
1250166
function updateOrCreate(val) {
        var res = _resources[val._id];
        if (!res) {
          res = new Resource(val, false, new Date().getTime());
        } else {
          res.$updateServer(val);
        }

        return res;
      }
324108
function attr(name, value) {
    var self = this;
    if (arguments.length === 0) {
      return self._attrs;
    }
    if (Util.isObject(name)) {
      // self._attrs = Util.deepMix(self._attrs, name);
      for (var k in name) {
        this._setAttr(k, name[k]);
      }
      self.clearBBox();
      this._cfg.hasUpdate = true;
      return self;
    }
    if (arguments.length === 2) {
      this._setAttr(name, value);
      self.clearBBox();
      this._cfg.hasUpdate = true;
      return self;
    }
    return self._attrs[name];
  }
617388
function(model, attrConfig, value, computed, validators, depth) {
      var attr, indices;

      if (_.isArray(attrConfig)) {
        return _.reduce(attrConfig, function(memo, nestedAttrConfig) {
          memo.push(validateWithOpenArrayHelper(model, nestedAttrConfig, value, computed, validators, depth + 1));
          return memo;
        }, []);
      } else {
        indices = attrConfig.index;
        attr = attrConfig.attr;
        // if the value wasn't passed in and the attribute is nested, get the value
        if (_.isUndefined(value) && isNestedAttr(attr)) {
          value = model.get(attr);
        }
        return invokeValidator(validators, model, value, attr, computed, indices);
      }
    }
230918
function defineBooleanAttribute (key, handler) {
    var attr = $attrs.$normalize('md-' + key);
    if (handler) defineProperty(key, handler);
    if ($attrs.hasOwnProperty(attr)) updateValue($attrs[attr]);
    $attrs.$observe(attr, updateValue);
    function updateValue (newValue) {
      ctrl[ key ] = newValue !== 'false';
    }
  }
1193543
function ImageMock() {

	var _complete = true;
	var _width = 0;
	var _height = 0;
	var _src = '';
	var _onLoad = null;
	var _loadTimeoutId;

	Object.defineProperties(this, {
		complete: {
			get: function getComplete() {
				return _complete;
			},
			enumerable: true
		},
		onload: {
			get: function getOnload() {
				return _onLoad;
			},
			set: function setOnload(callback) {
				_onLoad = callback;
			},
			enumerable: true
		},
		width: {
			get: function getWidth() {
				return _width;
			},
			enumerable: true
		},
		height: {
			get: function getHeight() {
				return _height;
			},
			enumerable: true
		},
		src: {
			get: function getSrc() {
				return _src;
			},
			set: function setSrc(src) {
				_complete = false;
				platform.global.clearTimeout(_loadTimeoutId);
				if (src) {
					_loadTimeoutId = platform.global.setTimeout(function () {
						_width = 10;
						_height = 10;
						_complete = true;
						if (this.onload) this.onload(/*no event used*/);
					}.bind(this), 200);
					_src = src;
				} else {
					_width = 0;
					_height = 0;
					_src = '';
				}
			},
			enumerable: true
		}
	});
}
839909
function compileCoercion( attributes ) {
	if ( !attributes || typeof attributes !== "object" || Array.isArray( attributes ) ) {
		throw new TypeError( "definition of attributes must be object" );
	}

	const attributeNames = Object.keys( attributes );
	const numAttributes = attributeNames.length;
	const coercion = [];

	for ( let ai = 0; ai < numAttributes; ai++ ) {
		const attributeName = attributeNames[ai];
		const attribute = attributes[attributeName];

		const handler = Types.selectByName( attribute.type );

		const { args, body } = extractBody( handler.coerce );
		if ( args.length < 2 ) {
			throw new TypeError( `coerce() of ModelType for handling ${attribute.type} values must accept two arguments` );
		}

		coercion[ai] = `
{
	let ${args[0]} = __props["${attributeName}"];
	const ${args[1]} = __attrs["${attributeName}"];

	{
		${body.replace( ptnTrailingReturn, ( all, term ) => `__props["${attributeName}"] = ${term.trim()};` )}
	}
}
		`;
	}

	// eslint-disable-next-line no-new-func
	return new Function( `
const __attrs = this.constructor.schema.attributes;
const __props = this.properties;

${coercion.join( "" )}
` );
}
731322
function handleUnit (prop, val) {
    if (val !== +val) {
      return val
    }

    testEl.style[prop] = 0
    let propValue = testEl.style[prop]
    let match = propValue.match && propValue.match(/^\d+([a-zA-Z]+)/)
    if (match) {
      return val + match[1]
    }

    return val
  }
1272627
private AttributeValue[] buildAttributeValue(final String[] real_names) throws DevFailed {
	// Allocate memory for the AttributeValue structures
	AttributeValue[] back = new AttributeValue[0];
	// noinspection ErrorNotRethrown
	try {
	    back = new AttributeValue[real_names.length];
	    for (int i = 0; i < real_names.length; i++) {
		back[i] = new AttributeValue();
	    }
	} catch (final OutOfMemoryError ex) {
	    Except.throw_exception("API_MemoryAllocation", "Can't allocate memory in server",
		    "DeviceImpl.read_attributes");
	}

	// Build the sequence returned to caller for readable attributes and
	// check
	// that all the wanted attributes set value has been updated
	for (int i = 0; i < real_names.length; i++) {
	    final Attribute att = dev_attr.get_attr_by_name(real_names[i]);
	    if (att.get_value_flag()) {
		final AttrWriteType w_type = att.get_writable();
		if (w_type == AttrWriteType.READ || w_type == AttrWriteType.READ_WRITE
			|| w_type == AttrWriteType.READ_WITH_WRITE) {
		    if (w_type == AttrWriteType.READ_WRITE
			    || w_type == AttrWriteType.READ_WITH_WRITE) {
			dev_attr.add_write_value(att);
		    }

		    if (att.is_alarmed() == true
			    && att.get_quality().value() != AttrQuality._ATTR_INVALID) {
			att.check_alarm();
		    }
		}
		back[i].time = att.get_when();
		back[i].quality = att.get_quality();
		back[i].name = att.get_name();
		back[i].dim_x = att.get_x();
		back[i].dim_y = att.get_y();

		final Util tg = Util.instance();
		back[i].value = tg.get_orb().create_any();

		switch (att.get_data_type()) {
		case Tango_DEV_BOOLEAN:
		    DevVarBooleanArrayHelper.insert(back[i].value, att.get_boolean_value());
		    break;

		case Tango_DEV_SHORT:
		    DevVarShortArrayHelper.insert(back[i].value, att.get_short_value());
		    break;

		case Tango_DEV_USHORT:
		    DevVarUShortArrayHelper.insert(back[i].value, att.get_short_value());
		    break;

		case Tango_DEV_LONG:
		    DevVarLongArrayHelper.insert(back[i].value, att.get_long_value());
		    break;

		case Tango_DEV_ULONG:
		    DevVarULongArrayHelper.insert(back[i].value, att.get_long_value());
		    break;

		case Tango_DEV_LONG64:
		    DevVarLong64ArrayHelper.insert(back[i].value, att.get_long64_value());
		    break;

		case Tango_DEV_ULONG64:
		    DevVarULong64ArrayHelper.insert(back[i].value, att.get_long64_value());
		    break;

		case Tango_DEV_DOUBLE:
		    DevVarDoubleArrayHelper.insert(back[i].value, att.get_double_value());
		    break;

		case Tango_DEV_STRING:
		    DevVarStringArrayHelper.insert(back[i].value, att.get_string_value());
		    break;
		case Tango_DEV_STATE:
		    DevVarStateArrayHelper.insert(back[i].value, att.get_state_value());
		    break;

		/*
		 * //======================================================== //
		 * Not possible (DevEncoded type is not transfered inside an
		 * any)
		 * //========================================================
		 * case Tango_DEV_ENCODED :
		 * DevEncodedHelper.insert(back[i].value,att.get_enc_value());
		 * break;
		 */
		default:
		    Except.throw_exception("API_DatTypeNotSupported", "Attribute " + att.get_name()
			    + " data type not supported !", "Device_2Impl.read_attributes()");
		}
	    } else {
		Except.throw_exception("API_AttrValueNotSet", "Read value for attribute "
			+ att.get_name() + " has not been updated", "DeviceImpl.read_attributes");
	    }
	} // End of for ( ; ; )
	return back;
    }
996443
function(attr, val) {
      return val === undefined ? (this.length ? this[0].getAttribute(attr) : null) : this.each(function(index, el) {
        el.setAttribute(attr, val);
      });
    }
1095487
function createMockFS(files) {
    files = Immutable.fromJS(files);
    var mtime = new Date();

    function getFile(filePath) {
        var parts = path.normalize(filePath).split(path.sep);
        return parts.reduce(function(list, part, i) {
            if (!list) return null;

            var file;

            if (!part || part === '.') file = list;
            else file = list.get(part);

            if (!file) return null;

            if (is.string(file)) {
                if (i === (parts.length - 1)) return file;
                else return null;
            }

            return file;
        }, files);
    }

    function fsExists(filePath) {
        return Boolean(getFile(filePath) !== null);
    }

    function fsReadFile(filePath) {
        var file = getFile(filePath);
        if (!is.string(file)) {
            throw error.FileNotFoundError({
                filename: filePath
            });
        }

        return new Buffer(file, 'utf8');
    }

    function fsStatFile(filePath) {
        var file = getFile(filePath);
        if (!file) {
            throw error.FileNotFoundError({
                filename: filePath
            });
        }

        return {
            mtime: mtime
        };
    }

    function fsReadDir(filePath) {
        var dir = getFile(filePath);
        if (!dir || is.string(dir)) {
            throw error.FileNotFoundError({
                filename: filePath
            });
        }

        return dir
            .map(function(content, name) {
                if (!is.string(content)) {
                    name = name + '/';
                }

                return name;
            })
            .valueSeq();
    }

    return FS.create({
        root: '',
        fsExists: fsExists,
        fsReadFile: fsReadFile,
        fsStatFile: fsStatFile,
        fsReadDir: fsReadDir
    });
}
658790
function isMatch(config, mock) {
		if (angular.isFunction(mock)) {
			return !!mock(config.method, config.url, config.params, config.data, config.headers);
		}
		mock = mock || {};
		var fail = false;
		if (mock.method) {
			fail = fail || (config.method ? config.method.toLowerCase() : 'get') != mock.method.toLowerCase();
		}
		if (mock.url && angular.isString(config.url) && angular.isString(mock.url)) {
			fail = fail || config.url.split('?')[0] != mock.url.split('?')[0];
		}
		if (mock.params || angular.isString(config.url) && config.url.split('?')[1]) {
			var configParams = angular.extend(queryParams(config.url.split('?')[1]), config.params);
			var mockParams = angular.isString(mock.url) ? queryParams(mock.url.split('?')[1]) : {};
			mockParams = angular.extend(mockParams, mock.params);
			fail = fail || !angular.equals(configParams, mockParams);
		}
		if (mock.data) {
			fail = fail || !angular.equals(config.data, mock.data);
		}
		// Header props can be functions
		if (mock.headers) {
			var headers = {};
			angular.forEach(config.headers, function(value, key) {
				if (angular.isFunction(value)) {
					value = value(config);
				}
				if (value) {
					headers[key] = value;
				}
			});
			fail = fail || !angular.equals(headers, mock.headers);
		}
		return !fail;
	}