The GetOption abstract operation extracts the value of the property named
property from the provided options object, converts it to the required type,
checks whether it is one of a List of allowed values, and fills in a fallback
value if necessary.
766208
function /*9.2.9 */$$core$$GetOption (options, property, type, values, fallback) {
        var
            // 1. Let value be the result of calling the [[Get]] internal method of
            //    options with argument property.
            value = options[property];

        // 2. If value is not undefined, then
        if (value !== undefined) {
            // a. Assert: type is "boolean" or "string".
            // b. If type is "boolean", then let value be ToBoolean(value).
            // c. If type is "string", then let value be ToString(value).
            value = type === 'boolean' ? Boolean(value)
                      : (type === 'string' ? String(value) : value);

            // d. If values is not undefined, then
            if (values !== undefined) {
                // i. If values does not contain an element equal to value, then throw a
                //    RangeError exception.
                if ($$core$$arrIndexOf.call(values, value) === -1)
                    throw new RangeError("'" + value + "' is not an allowed value for `" + property +'`');
            }

            // e. Return value.
            return value;
        }
        // Else return fallback.
        return fallback;
    }
924169
function validateOptions(options) {
	//Check if options is set and is an object.
	if(! options || ! typeof options === 'object') {
		return {
			country: DEFAULT_COUNTRY,
			amount: DEFAULT_AMOUNT
		}
	}

	//Check if country property is set.
	if (! options.hasOwnProperty('country')) {
		options.country = DEFAULT_COUNTRY;
	}

	//Check if amount property is set.
	if (! options.hasOwnProperty('amount')) {
		options.amount = DEFAULT_AMOUNT;
	}

	return options;
}
704885
@Deprecated
    public Object getOptionObject(String opt)
    {
        try
        {
            return getParsedOptionValue(opt);
        }
        catch (ParseException pe)
        {
            System.err.println("Exception found converting " + opt + " to desired type: " + pe.getMessage());
            return null;
        }
    }
484179
function getValidOptions (options) {
  if (typeof options !== 'object') {
    return DEFAULT_OPTIONS
  }

  var validOptions = {}

  for (var prop in DEFAULT_OPTIONS) {
    if (DEFAULT_OPTIONS.hasOwnProperty(prop)) {
      validOptions[prop] = typeof options[prop] === 'string'
        ? options[prop] : DEFAULT_OPTIONS[prop]
    }
  }

  return validOptions
}
936581
@Override
    public <T extends Option> T getSingleOption(final Class<T> optionType) {
        requestedOptionTypes.add(optionType);
        T[] filter = filter(optionType, combinedOptions);

        if (filter.length > 0) {
            return filter[filter.length - 1];
        }
        else {
            return null;
        }
    }
74419
def _get_option(target_obj, key):
    
    getter_name = 'get_{key}'.format(**locals())
    by_attribute = functools.partial(getattr, target_obj, key)
    getter = getattr(target_obj, getter_name, by_attribute)
    return getter()
1192085
function () {
            /*  determine parameters  */
            var params = $cs.params("value", arguments, {
                name:        { pos: 0, req: true,      valid: "string"   },
                value:       { pos: 1, def: undefined, valid: "any"      },
                force:       { pos: 2, def: false,     valid: "boolean"  },
                injected:    {         def: false,     valid: "boolean"  },
                op:          {         def: [],        valid: "(string|[string?]|[string,number,number])" },
                returnowner: {         def: false,     valid: "boolean"  }
            });

            /*  determine operation  */
            if (typeof params.op === "string")
                params.op = [ params.op ];
            if (params.op.length === 0)
                params.op = (_cs.isdefined(params.value) ? [ "set" ] : [ "get" ]);
            else if (!params.op[0].match(/^(?:get|set|splice|delete|push|pop|shift|unshift)$/))
                throw _cs.exception("value", "invalid operation \"" + params.op[0] + "\"");
            if (   params.op[0] === "splice"
                && (   params.op.length !== 3
                    || typeof params.op[1] !== "number"
                    || typeof params.op[2] !== "number"))
                throw _cs.exception("value", "invalid arguments for operation \"splice\"");

            /*  parse the value name into selection path segments  */
            var path = _cs.select_parse(params.name);

            /*  create new canonical name out of the parsed path segments  */
            var pathName = path.join(".");

            /*  determine component owning model with requested value  */
            var owner = null;
            var model = null;
            var comp  = this;
            while (comp !== null) {
                owner = comp.property({ name: "ComponentJS:model", returnowner: true });
                if (!_cs.isdefined(owner))
                    throw _cs.exception("value", "no model found containing value \"" + path[0] + "\"");
                model = owner.property("ComponentJS:model");
                if (_cs.isdefined(model.spec[path[0]]))
                    break;
                comp = owner.parent();
            }
            if (comp === null)
                throw _cs.exception("value", "no model found containing value \"" + path[0] + "\"");

            /*  get new model value  */
            var value_new = params.value;

            /*  translate special-case array operations to splice operation  */
            var obj;
            switch (params.op[0]) {
                case "unshift":
                    params.op = [ "splice", 0, 0 ];
                    break;
                case "shift":
                    params.op = [ "splice", 0, 1 ];
                    value_new = undefined;
                    break;
                case "push":
                    obj = $cs.select(model.data, path);
                    params.op = [ "splice", obj.length, 0 ];
                    break;
                case "pop":
                    obj = $cs.select(model.data, path);
                    params.op = [ "splice", obj.length - 1, 1 ];
                    value_new = undefined;
                    break;
            }

            /*  get old model value  */
            var ev;
            var result;
            var value_old = $cs.select(model.data, path);
            if (params.op[0] === "splice") {
                /*  splice operation is on collection itself,
                    so pick the target collection element!  */
                if (params.op[2] > 0)
                    value_old = $cs.select(value_old, "" + params.op[1]);
                else
                    value_old = undefined;
            }
            else if (params.op[0] === "get") {
                if (owner.property({ name: "ComponentJS:model:subscribers:get", def: 0, bubbling: false }) > 0) {
                    /*  send event to observers for value get and allow observers
                        to reject value get operation and/or change old value to get  */
                    ev = owner.publish({
                        name:      "ComponentJS:model:" + pathName + ":" + params.op[0],
                        args:      [ value_old, value_old, params.op, pathName ],
                        capturing: false,
                        spreading: false,
                        bubbling:  false,
                        async:     false
                    });
                    if (ev.processing()) {
                        /*  allow value to be overridden by event result  */
                        result = ev.result();
                        if (typeof result !== "undefined")
                            value_old = result;
                    }
                }
            }

            /*  optionally set/delete/splice new model value  */
            if (   (   params.op[0] === "set"
                    && (params.force || value_old !== value_new))
                || params.op[0] === "delete"
                || params.op[0] === "splice"                     ) {

                /*  check validity of new value  */
                if (   params.op[0] === "set"
                    || (   params.op[0] === "splice"
                        && value_new !== undefined  )) {
                    var subPath = (
                          params.op[0] === "splice"
                        ? path.slice(1).concat([ "0" ])
                        : path.slice(1)
                    );
                    if (!_cs.validate_at(value_new, model.spec[path[0]].valid, subPath))
                        throw _cs.exception("value", "model field \"" + params.name + "\" receives " +
                            "new value " + _cs.json(value_new) + ", which does not validate " +
                            "against \"" + model.spec[path[0]].valid + "\"" +
                            (subPath.length > 0 ? " at sub-path \"" + subPath.join(".") + "\"" : ""));
                }

                /*  send event to observers for value set/delete/splice operation
                    and allow observers to reject operation and/or change new value to set  */
                var cont = true;
                if (owner.property({ name: "ComponentJS:model:subscribers:" + params.op[0], def: 0, bubbling: false }) > 0) {
                    ev = owner.publish({
                        name:      "ComponentJS:model:" + pathName + ":" + params.op[0],
                        args:      [ value_new, value_old, params.op, pathName ],
                        capturing: false,
                        spreading: false,
                        bubbling:  false,
                        async:     false
                    });
                    if (!ev.processing()) {
                        if (params.injected)
                            throw _cs.exception("value", "model field \"" + params.name + "\" receives (again) " +
                                "value " + _cs.json(value_new) + ", which is rejected by observers, " +
                                "but the value was indicated to be already injected by third-parties " +
                                "(so it technically no longer can be rejected)");
                        cont = false;
                    }
                    else {
                        /*  allow value to be overridden  */
                        result = ev.result();
                        if (typeof result !== "undefined")
                            value_new = result;
                    }
                }
                if (cont && !model.spec[path[0]].autoreset) {
                    /*  perform destructive operation on model  */
                    if (params.op[0] === "set") {
                        /*  set value in model  */
                        $cs.select(model.data, path, value_new);
                    }
                    else if (params.op[0] === "splice") {
                        /*  splice value into model  */
                        obj = $cs.select(model.data, path);
                        if (!(obj instanceof Array))
                            throw new _cs.exception("value", "cannot splice: target object is not of Array type");
                        if (typeof value_new !== "undefined")
                            obj.splice(params.op[1], params.op[2], value_new);
                        else
                            obj.splice(params.op[1], params.op[2]);
                    }
                    else if (params.op[0] === "delete") {
                        /*  delete value from model  */
                        if (path.length < 2)
                            throw new _cs.exception("value", "cannot delete model root or top-level model entry");
                        obj = $cs.select(model.data, path.slice(0, path.length - 1));
                        var pathSegment = path[path.length - 1];
                        if (obj instanceof Array)
                            obj.splice(parseInt(pathSegment, 10), 1);
                        else if (typeof obj === "object")
                            delete obj[pathSegment];
                        else
                            throw new _cs.exception("value", "cannot delete: target object is neither Array nor Object type");
                    }

                    /*  synchronize model with underlying store  */
                    if (model.spec[path[0]].store) {
                        var store = owner.store("model");
                        store[path[0]] = model.data[path[0]];
                        owner.store("model", store);
                    }

                    /*  send event to observers after value finally changed  */
                    if (owner.property({ name: "ComponentJS:model:subscribers:changed", def: 0, bubbling: false }) > 0) {
                        owner.publish({
                            name:      "ComponentJS:model:" + pathName + ":changed",
                            args:      [ value_new, value_old, params.op, pathName ],
                            noresult:  true,
                            capturing: false,
                            spreading: false,
                            bubbling:  false,
                            async:     true
                        });
                    }
                }
            }

            /*  return old model value  */
            return (params.returnowner ? owner : value_old);
        }
470435
String getOption(String[] options, int index) {
        if ((options != null) && (options.length > index)) {
            return options[index];
        }
        return null;
    }
1033164
function (obj, options) {

            debug('Parsing properties...');
            debug('Object: %o', obj);

            Object.keys(obj)
                .map(key => {

                    let value = obj[key];

                    debug('Value: %o', value);

                    // parse current value
                    value = helpers.parseValue(value);

                    debug('Parsed value: %o', value);

                    // replace value with the updated one
                    obj[key] = value;
                });


            debug('Parsed options: %o', obj);

            return obj;
        }
621623
public static ClientOptions of(ClientOptions baseOptions, Iterable<ClientOptionValue<?>> options) {
        // TODO(trustin): Reduce the cost of creating a derived ClientOptions.
        requireNonNull(baseOptions, "baseOptions");
        requireNonNull(options, "options");
        return new ClientOptions(baseOptions, options);
    }
477324
public static Option findListOption(Option[] options) {
        for (int i = 0; i < options.length; i++) {
            if (options[i].getType() == Type.LIST) {
                return options[i];
            }
        }
        return null;
    }
1202460
@Override
  public Object getOptProperty(final String name) throws OptionsException {
    if (useSystemwideValues) {
      return findValue(optionsRoot, makePathElements(name), -1);
    }

    return findValue(localOptionsRoot, makePathElements(name), -1);
  }
314426
Option toOption() {
        DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();

        oBuilder.withShortName(option).withDescription(description).withRequired(required);

        if (longOptionName != null) {
            oBuilder.withLongName(longOptionName);
        }

        if (hasArgs) {
            ArgumentBuilder aBuilder = new ArgumentBuilder();

            if (argName != null) {
                aBuilder.withName(argName);
            }

            if (argsAreOptional) {
                aBuilder.withMinimum(0);
            }

            if (argsCount != null) {
                aBuilder.withMaximum(argsCount);
            } else {
                aBuilder.withMaximum(1);
            }

            if (argsValueSeparator != null && argsValueSeparator.length() != 0) {
                aBuilder.withInitialSeparator(argsValueSeparator.charAt(0));
                aBuilder.withSubsequentSeparator(argsValueSeparator.charAt(0));
            }
            oBuilder.withArgument(aBuilder.create());
        }

        return oBuilder.create();
    }
107050
private String getOptionalProperty(JsonObject jsonObject, String key) {
    return jsonObject.has(key) ? jsonObject.get(key).getAsString() : DEFAULT_VALUE_FOR_OPTIONAL_PROPERTY;
  }
204728
public static <T> Choice<T> fromOptional(Optional<T> optional) {
    return optional.isPresent() ? of(optional.get()) : Choice.<T>none();
  }
625610
function validateOptsProperties(opts, validProperties) {
  var validProps = ensureVector(validProperties);
  var allOpts = jd.vector(Object.keys(opts), 'string');
  var invalidOpts = allOpts.s(allOpts.isIn(validProps).not());
  if (invalidOpts.size() > 0) {
    throw new Error('invalid properties found in "opts": ' +
      invalidOpts.strJoin(', '));
  }
}
121804
@CheckForNull
    public <T extends QEmuOption> T getOption(@Nonnull Class<T> type) {
        List<? extends T> options = getOptions(type);
        if (options.isEmpty())
            return null;
        return options.iterator().next();
    }