backprop.js
function transformValue(propSpec, inputVal, fallbackValue) {
        var value = inputVal;
        if (typeof propSpec.coerce === 'function') value = propSpec.coerce(value);

        // If an array of choices was passed in, validate that the input is one of
        // the valid choices:
        var choices = propSpec.choices;
        if (choices && choices.constructor && choices.constructor.name === 'Array') {
            if (choices.indexOf(value) === -1) {
                if (fallbackValue !== undefined) value = fallbackValue;
                else return undefined;
            }
        }

        if (propSpec.trim && (typeof value.trim === 'function')) value = value.trim();
        if (propSpec.max && (value > propSpec.max)) value = propSpec.max;
        if (propSpec.min && (value < propSpec.min)) value = propSpec.min;
        return value;
    }
function transformValue(propSpec, inputVal, fallbackValue) {
        var value = inputVal;
        if (typeof propSpec.coerce === 'function') value = propSpec.coerce(value);

        // If an array of choices was passed in, validate that the input is one of
        // the valid choices:
        var choices = propSpec.choices;
        if (choices && choices.constructor && choices.constructor.name === 'Array') {
            if (choices.indexOf(value) === -1) {
                if (fallbackValue !== undefined) value = fallbackValue;
                else return undefined;
            }
        }

        if (propSpec.trim && (typeof value.trim === 'function')) value = value.trim();
        if (propSpec.max && (value > propSpec.max)) value = propSpec.max;
        if (propSpec.min && (value < propSpec.min)) value = propSpec.min;
        return value;
    }
Transform a given input value, using a property spec object. propSpec: an object that defines a Backprop property. Supported keys (see the README for explanations) include: 'coerce', 'choices', 'trim', 'max', 'min' inputVal: the value that the caller has assigned to the property fallbackValue (optional): a default value to use if the input is invalid