When our app state is fully typed, we should be able to get rid of
this function. This is only temporarily necessary to support
converting typed objects to immutable.js, which usually happens in
reducers.

@memberof utils/fromJS
@static
500747
function fromJS(value: any): any {
  if (Array.isArray(value)) {
    return createList(value);
  }
  if (value && value.constructor && value.constructor.meta) {
    // This adds support for tcomb objects which are native JS objects
    // but are not "plain", so the above checks fail. Since they
    // behave the same we can use the same constructors, but we need
    // special checks for them.
    const kind = value.constructor.meta.kind;
    if (kind === "struct") {
      return createMap(value);
    } else if (kind === "list") {
      return createList(value);
    }
  }

  // If it's a primitive type, just return the value. Note `==` check
  // for null, which is intentionally used to match either `null` or
  // `undefined`.
  if (value == null || typeof value !== "object") {
    return value;
  }

  // Otherwise, treat it like an object. We can't reliably detect if
  // it's a plain object because we might be objects from other JS
  // contexts so `Object !== Object`.

  return createMap(value);
}
280191
function destroy(object) {
    if (isObject(object)) {
        if (isFunction(object.finalize)) {
            object.finalize();
        }
        for (var property in object) {
            if (true) {//For lint
                delete object[property];
            }
        }
    }
}
998419
private static boolean isImmutable(Type type, VisitorState state) {
    switch (type.getKind()) {
      case BOOLEAN:
      case BYTE:
      case SHORT:
      case INT:
      case CHAR:
      case FLOAT:
        return true;
      case LONG:
      case DOUBLE:
        // double-width primitives aren't written atomically
        return true;
      default:
        break;
    }
    return IMMUTABLE_WHITELIST.contains(
        state.getTypes().erasure(type).tsym.getQualifiedName().toString());
  }
1172744
function deleteInstance() {
  var _this = this;

  expect(arguments).to.have.length(
    0,
    'Invalid arguments length when deleting a "' +
    this.Entity.specification.name +
    '" instance (it has to be passed 0 arguments)');

  return new Promise(function (resolve, reject) {

    var promise = _this.adapter.deleteObject(_this);

    expect(promise).to.respondTo(
      'then',
      'Function "delete" of an Adapter specialization should return a Promise'
    );

    expect(promise).to.respondTo(
      'catch',
      'Function "delete" of an Adapter specialization should return a Promise'
    );

    promise
      .then(resolve)
      .catch(reject);
  });
}
683282
function () {
        json.unobserve(this.target, this.callback);
        this.props=null;
        this.callback=null;
        this.target=null;
    }
1095426
function TypedObject (config) {
    const object = this;
    const allowNull = config.hasOwnProperty('allowNull') ? !!config.allowNull : true;
    const hasProperties = config.hasOwnProperty('properties');

    if (hasProperties && !util.isValidSchemaConfiguration(config.properties)) {
        const message = util.propertyErrorMessage('properties', config.properties, 'Must be a plain object.');
        throw Error(message);
    }

    if (config.hasOwnProperty('schema')) {
        if (!util.isValidSchemaConfiguration(config.schema)) {
            const message = util.propertyErrorMessage('schema', config.schema, 'Must be a plain object.');
            throw Error(message);
        }
        validateSchemaConfiguration('schema', config.schema);
    }

    const schemaIsNotOneOf = config.hasOwnProperty('schema') ? !FullyTyped.controllers.is('one-of', config.schema.type) : true;

    Object.defineProperties(object, {

        allowNull: {
            /**
             * @property
             * @name TypedObject#allowNull
             * @type {boolean}
             */
            value: allowNull,
            writable: false
        },

        clean: {
            /**
             * @property
             * @name TypedObject#clean
             * @type {boolean}
             */
            value: !!config.clean,
            writable: false
        },

        properties: {
            /**
             * @property
             * @name TypedObject#properties
             * @type {object}
             */
            value: hasProperties ? config.properties : {},
            writable: false
        },

        schema: {
            /**
             * @property
             * @name TypedObject#schema
             * @type {object, undefined}
             */
            value: config.schema ? FullyTyped(mergeSchemas(config.schema)) : undefined,
            writable: false
        }

    });

    // add typing to each property specified in the configuration
    Object.keys(object.properties)
        .forEach(function(key) {
            let options = object.properties[key] || {};
            const optionsIsNotOneOf = !FullyTyped.controllers.is('one-of', options.type);

            if (!util.isValidSchemaConfiguration(options)) {
                throw Error('Invalid configuration for property: ' + key + '. Must be a plain object.');
            }

            // merge generic schema with property specific schemas
            if (config.schema) {
                if (schemaIsNotOneOf && optionsIsNotOneOf) {
                    options = mergeSchemas(config.schema, options);
                } else if (schemaIsNotOneOf) {
                    options.oneOf = options.oneOf.map(item => mergeSchemas(config.schema, item));
                } else if (optionsIsNotOneOf) {
                    options.oneOf = config.schema.oneOf.map(item => mergeSchemas(item, options));
                    options.type = 'one-of';
                } else {
                    const array = [];
                    const optionsLength = options.oneOf.length;
                    const schemaLength = config.schema.oneOf.length;
                    for (let i = 0; i < optionsLength; i++) {
                        for (let j = 0; j < schemaLength; j++) {
                            array.push(mergeSchemas(config.schema.oneOf[j], options.oneOf[i]));
                        }
                    }
                    options.oneOf = array;
                    options.type = 'one-of';
                }
            } else if (optionsIsNotOneOf) {
                extend(options);
            } else {
                options.oneOf.forEach(item => extend(item));
            }

            // create a schema instance for each property
            const schema = FullyTyped(options);
            object.properties[key] = schema;

            // validate that not required and has default
            validateSchemaConfiguration(key, schema);
        });

    return object;
}
54665
function (instance, instanceKey, type, json, jsonKey) {
    var conversionFunctionsList = [];
    var objectInstance;
    /**
     * If instanceKey is not passed on then it's the first iteration of the functions.
     */
    // tslint:disable-next-line:triple-equals
    if (instanceKey != undefined) {
        objectInstance = new type();
        instance[instanceKey] = objectInstance;
    }
    else {
        objectInstance = instance;
    }
    var objectKeys = Object.keys(objectInstance);
    objectKeys = objectKeys.concat((Reflect.getMetadata(METADATA_JSON_PROPERTIES_NAME, objectInstance) || []).filter(function (item) {
        if (objectInstance.constructor.prototype.hasOwnProperty(item) && Object.getOwnPropertyDescriptor(objectInstance.constructor.prototype, item).set === undefined) {
            // Property does not have setter
            return false;
        }
        return objectKeys.indexOf(item) < 0;
    }));
    objectKeys = objectKeys.filter(function (item) {
        return !Reflect.hasMetadata(METADATA_JSON_IGNORE_NAME, objectInstance, item);
    });
    objectKeys.forEach(function (key) {
        /**
         * Check if there is any DecoratorMetadata attached to this property, otherwise create a new one.
         */
        var metadata = getJsonPropertyDecoratorMetadata(objectInstance, key);
        if (metadata === undefined) {
            metadata = { name: key, required: false, access: exports.AccessType.BOTH };
        }
        // tslint:disable-next-line:triple-equals
        if (exports.AccessType.WRITE_ONLY != metadata.access) {
            /**
             * Check requried property
             */
            if (metadata.required && json[metadata.name] === undefined) {
                throw new JsonConverstionError("JSON structure does have have required property '" + metadata.name + "' as required by '" + getTypeNameFromInstance(objectInstance) + "[" + key + "]", json);
            }
            // tslint:disable-next-line:triple-equals
            var jsonKeyName = metadata.name != undefined ? metadata.name : key;
            // tslint:disable-next-line:triple-equals
            if (json[jsonKeyName] != undefined) {
                /**
                 * If metadata has deserializer, use that one instead.
                 */
                // tslint:disable-next-line:triple-equals
                if (metadata.deserializer != undefined) {
                    objectInstance[key] = getOrCreateDeserializer(metadata.deserializer).deserialize(json[jsonKeyName]);
                }
                else if (metadata.type === undefined) {
                    /**
                    * If we do not have any type defined, then we can't do much here but to hope for the best.
                    */
                    objectInstance[key] = json[jsonKeyName];
                }
                else {
                    if (!isArrayType(objectInstance, key)) {
                        // tslint:disable-next-line:triple-equals
                        var typeName = metadata.type != undefined ? getTypeNameFromInstance(metadata.type) : getTypeName(objectInstance, key);
                        if (!isSimpleType(typeName)) {
                            objectInstance[key] = new metadata.type();
                            conversionFunctionsList.push({ functionName: Constants.OBJECT_TYPE, type: metadata.type, instance: objectInstance[key], json: json[jsonKeyName] });
                        }
                        else {
                            conversionFunctions[typeName](objectInstance, key, typeName, json, jsonKeyName);
                        }
                    }
                    else {
                        var moreFunctions = conversionFunctions[Constants.ARRAY_TYPE](objectInstance, key, metadata.type, json, jsonKeyName);
                        moreFunctions.forEach(function (struct) {
                            conversionFunctionsList.push(struct);
                        });
                    }
                }
            }
        }
    });
    return conversionFunctionsList;
}
1295800
function(val) {
      switch (typeof val) {
        case 'undefined':
        case 'boolean':
        case 'number':
        case 'string':
        case 'symbol':
        case 'function':
          return val;
        case 'object':
        default: {
          // typeof null === 'object'
          if (!val) return val;

          // This covers Uint8Array and friends, even without a TypedArray
          // base-class constructor.
          const isTypedArray =
              val.buffer && val.buffer.constructor == ArrayBuffer;
          if (isTypedArray) {
            return val;
          }

          if (seenObjects.has(val)) {
            return null;
          }

          const isArray = val.constructor == Array;
          if (val.constructor != Object && !isArray) {
            return null;
          }

          seenObjects.add(val);
          const ret = isArray ? [] : {};
          // Note |name| will equal a number for arrays.
          for (const name in val) {
            ret[name] = clone(val[name]);
          }

          // Length is a non-enumerable property, but we should copy it over in
          // case it is not the default.
          if (isArray) {
            ret.length = val.length;
          }
          return ret;
        }
      }
    }
164364
function unthenable(input) {
  var output = Object.assign({}, input)
  delete output.then
  if (input !== undefined)
    output.constructor = input.constructor

  if (input && input.then instanceof Function) return disguise(output, input,
    true)

  // `input` is not thenable
  return input
}
523440
function destroy() {
         // allow recycling object properties
         me.pool.push(this.currentTransform);
         this.currentTransform = undefined;
         me.pool.push(this.anchorPoint);
         this.anchorPoint = undefined;
         me.pool.push(this.pos);
         this.pos = undefined;
         me.pool.push(this._absPos);
         this._absPos = undefined;
         me.pool.push(this._bounds);
         this._bounds = undefined;
         this.onVisibilityChange = undefined;

         if (typeof this.mask !== "undefined") {
           me.pool.push(this.mask);
           this.mask = undefined;
         }

         if (typeof this.tint !== "undefined") {
           me.pool.push(this.tint);
           this.tint = undefined;
         }

         this.ancestor = undefined; // destroy the physic body if defined

         if (typeof this.body !== "undefined") {
           this.body.destroy.apply(this.body, arguments);
           this.body = undefined;
         }

         this.onDestroyEvent.apply(this, arguments);
       }
721994
function () {
        var obj = PropertyBase.toJSON(this);

        // remove header array if blank
        if (_.isArray(obj.header) && !obj.header.length) {
            delete obj.header;
        }

        return obj;
    }
806782
function unbindEvent(element, type, handler) {
    const events = safeEvent(element, type);
    const items = events.get(handler);

    if (!items) {
        return;
    }

    forgetHandler(element, type, handler);

    util.forEach(items, func => {
        if ('removeEventListener' in element) {
            element.removeEventListener(type, func);
        } else if ('detachEvent' in element) {
            element.detachEvent(`on${type}`, func);
        }
    });
}
952842
private <K, V> DiffHistoricalTypeState<K, V> createTypeState(Map<K, V> from, Map<K, V> to, boolean isGroupOfObjects) {
        int newCounter = 0;
        int diffCounter = 0;
        int deleteCounter = 0;

        for(K key : from.keySet()) {
            V toValue = to.get(key);

            if(toValue == null) {
                deleteCounter++;
            } else {
                V fromValue = from.get(key);

                if(!checkEquality(toValue, fromValue, isGroupOfObjects)) {
                    diffCounter++;
                }
            }
        }

        for(K key : to.keySet()) {
            if(!from.containsKey(key)) {
                newCounter++;
            }
        }

        OpenAddressingArraySet<K> newSet = new OpenAddressingArraySet<K>();
        OpenAddressingHashMap<K, V> diffMap = new OpenAddressingHashMap<K, V>();
        OpenAddressingHashMap<K, V> deleteMap = new OpenAddressingHashMap<K, V>();

        newSet.builderInit(newCounter);
        diffMap.builderInit(diffCounter);
        deleteMap.builderInit(deleteCounter);

        newCounter = diffCounter = deleteCounter = 0;

        for(K key : from.keySet()) {
            V fromValue = from.get(key);
            V toValue = to.get(key);

            if(toValue == null) {
                deleteMap.builderPut(deleteCounter++, key, fromValue);
            } else {
                if(!checkEquality(toValue, fromValue, isGroupOfObjects)) {
                    diffMap.builderPut(diffCounter++, key, fromValue);
                }
            }
        }

        for(K key : to.keySet()) {
            if(!from.containsKey(key)) {
                newSet.builderSet(newCounter++, key);
            }
        }

        newSet.builderFinish();
        diffMap.builderFinish();
        deleteMap.builderFinish();

        return new DiffHistoricalTypeState<K, V>(newSet, diffMap, deleteMap);
    }
275956
function( type ) {

      if( arguments.length === 0 ) {
        for( type in this._events ) {
          this.removeAllListeners( type )
        }
      } else {
        this._events[ type ] = undefined
        delete this._events[ type ]
      }

      return this

    }
771416
function removeBrackets(type, nullOrUndefinedOnly) {
  if(typeof nullOrUndefinedOnly === "undefined") {
    nullOrUndefinedOnly = false;
  }
  if (typeof type === 'object') {
    return 'object';
  }
  else if(type.replace(/ /g, '') !== type) {
    return removeBrackets(type.replace(/ /g, ''));
  }
  else if(type.indexOf('null|') === 0) {
    return removeBrackets(type.substr('null|'.length));
  }
  else if(type.indexOf('undefined|') === 0) {
    // Not used currently, but robust code is better code :)
    return removeBrackets(type.substr('undefined|'.length));
  }
  if (type == null || type.length === 0 || nullOrUndefinedOnly) {
    return type;
  }
  var pos = type.indexOf('Array<');
  if (pos >= 0) {
    var start = 'Array<'.length;
    return type.substr(start, type.length - start - 1);
  }
  pos = type.indexOf('[');
  return pos >= 0 ? type.substr(0, pos) : type;
}
1124617
function typecast(value, originalValue, properties) {
        const options = this[_privateKey]._options;

        // Allow transform to manipulate raw properties.
        if (properties.transform) {
            value = properties.transform.call(this[_privateKey]._root, value, originalValue, properties);
        }

        // Allow null to be preserved.
        if (value === null && options.preserveNull) {
            return null;
        }

        // Helper function designed to detect and handle usage of array-form custom error messages for validators
        function detectCustomErrorMessage(key) {
            if (typeof properties[key] === 'object' && properties[key].errorMessage && properties[key].value) {
                return properties[key];
            }
            else  if (_.isArray(properties[key])) {
                return {
                    value: properties[key][0],
                    errorMessage: properties[key][1]
                };
            }
            else {
                return {
                    value: properties[key],
                    errorMessage: undefined
                };
            }
        }

        // Property types are always normalized as lowercase strings despite shorthand definitions being available.
        switch (properties.type) {
            case 'string':
                // Reject if object or array.
                if (_.isObject(value) || _.isArray(value)) {
                    throw new StringCastError(value, originalValue, properties);
                }

                // If index is being set with null or undefined, set value and end.
                if (value === undefined || value === null) {
                    return undefined;
                }

                // Typecast to String.
                value = value + '';

                // If stringTransform function is defined, use.
                // This is used before we do validation checks (except to be sure we have a string at all).
                if (properties.stringTransform) {
                    value = properties.stringTransform.call(this[_privateKey]._root, value, originalValue, properties);
                }

                // If clip property & maxLength properties are set, the string should be clipped.
                // This is basically a shortcut property that could be done with stringTransform.
                if (properties.clip !== undefined && properties.maxLength !== undefined) {
                    value = value.substr(0, properties.maxLength);
                }

                let enumValidation;

                // Detect custom error message usage for enum (can't use function here as enum is expected to be an array)
                if (typeof properties.enum === 'object' && properties.enum.errorMessage && properties.enum.value) {
                    enumValidation = properties.enum;
                }
                else if (_.isArray(properties.enum) && _.isArray(properties.enum[0])) {
                    enumValidation = {
                        value: properties.enum[0],
                        errorMessage: properties.enum[1]
                    };
                }
                else {
                    enumValidation = {
                        value: properties.enum,
                        errorMessage: undefined
                    };
                }

                // If enum is being used, be sure the value is within definition.
                if (
                    enumValidation.value !== undefined &&
                    _.isArray(enumValidation.value) &&
                    enumValidation.value.indexOf(value) === -1
                ) {
                    throw new StringEnumValidationError(enumValidation.errorMessage, value, originalValue, properties);
                }

                // Detect custom error message usage for minLength
                let minLength = detectCustomErrorMessage('minLength');

                // If minLength is defined, check to be sure the string is > minLength.
                if (minLength.value !== undefined && value.length < minLength.value) {
                    throw new StringMinLengthValidationError(minLength.errorMessage, value, originalValue, properties);
                }

                // Detect custom error message usage for maxLength
                let maxLength = detectCustomErrorMessage('maxLength');

                // If maxLength is defined, check to be sure the string is < maxLength.
                if (maxLength.value !== undefined && value.length > maxLength.value) {
                    throw new StringMaxLengthValidationError(maxLength.errorMessage, value, originalValue, properties);
                }

                // Detect custom error message usage for maxLength
                let regex = detectCustomErrorMessage('regex');

                // If regex is defined, check to be sure the string matches the regex pattern.
                if (regex.value && !regex.value.test(value)) {
                    throw new StringRegexValidationError(regex.errorMessage, value, originalValue, properties);
                }

                return value;

            case 'number':
                // If index is being set with null, undefined, or empty string: clear value.
                if (value === undefined || value === null || value === '') {
                    return undefined;
                }

                // Set values for boolean.
                if (_.isBoolean(value)) {
                    value = value ? 1 : 0;
                }

                // Remove/convert number group separators
                if (typeof value === 'string') {
                    if (options.useDecimalNumberGroupSeparator) {
                        // Remove decimals
                        value = value.replace(/\./g, '');
                        // Replace commas with decimals for js parsing
                        value = value.replace(/,/g, '.');
                    }
                    else {
                        //Remove commas
                        value = value.replace(/,/g, '');
                    }

                    // Reject if string was not a valid number
                    if (isNaN(Number(value))) {
                      throw new NumberCastError('String', value, originalValue, properties);
                    }
                }

                // Reject if array, object, or not numeric.
                if (_.isArray(value)) {
                    throw new NumberCastError('Array', value, originalValue, properties);
                }
                else if (_.isObject(value)) {
                    throw new NumberCastError('Object', value, originalValue, properties);
                }
                else if (!isNumeric(value)) {
                    throw new NumberCastError('Non-numeric', value, originalValue, properties);
                }

                // Typecast to number.
                value = Number(value);

                // Transformation after typecasting but before validation and filters.
                if (properties.numberTransform) {
                    value = properties.numberTransform.call(this[_privateKey]._root, value, originalValue, properties);
                }

                // Detect custom error message usage for min
                let min = detectCustomErrorMessage('min');

                if (min.value !== undefined && value < min.value) {
                    throw new NumberMinValidationError(min.errorMessage, value, originalValue, properties);
                }

                // Detect custom error message usage for min
                let max = detectCustomErrorMessage('max');

                if (max.value !== undefined && value > max.value) {
                    throw new NumberMaxValidationError(max.errorMessage, value, originalValue, properties);
                }

                return value;

            case 'boolean':
                // If index is being set with null, undefined, or empty string: clear value.
                if (value === undefined || value === null || value === '') {
                    return undefined;
                }

                // If is String and is 'false', convert to Boolean.
                if (value === 'false') {
                    return false;
                }

                // If is Number, <0 is true and >0 is false.
                if (isNumeric(value)) {
                    return (value * 1) > 0;
                }

                // Use Javascript to eval and return boolean.
                value = !!value;

                // Transformation after typecasting but before validation and filters.
                if (properties.booleanTransform) {
                    value = properties.booleanTransform.call(this[_privateKey]._root, value, originalValue, properties);
                }

                return value;

            case 'array':
                // If it's an object, typecast to an array and return array.
                if (_.isObject(value)) {
                    value = _.toArray(value);
                }

                // Reject if not array.
                if (!_.isArray(value)) {
                    throw new ArrayCastError(value, originalValue, properties);
                }

                // Arrays are never set directly.
                // Instead, the values are copied over to the existing SchemaArray instance.
                // The SchemaArray is initialized immediately and will always exist.
                originalValue.length = 0;
                _.each(value, (arrayValue) => {
                    originalValue.push(arrayValue);
                });

                return originalValue;

            case 'object':
                // If it's not an Object, reject.
                if (!_.isObject(value)) {
                    throw new ObjectCastError(value, originalValue, properties);
                }

                // If object is schema object and an entirely new object was passed, clear values and set.
                // This preserves the object instance.
                if (properties.objectType) {
                    // The object will usually exist because it's initialized immediately for deep access within SchemaObjects.
                    // However, in the case of Array elements, it will not exist.
                    let schemaObject;
                    if (originalValue !== undefined) {
                        // Clear existing values.
                        schemaObject = originalValue;
                        schemaObject.clear();
                    } else {
                        // The SchemaObject doesn't exist yet. Let's initialize a new one.
                        // This is used for Array types.
                        schemaObject = new properties.objectType({}, this[_privateKey]._root);
                    }

                    // Copy value to SchemaObject and set value to SchemaObject.
                    for (const key in value) {
                        schemaObject[key] = value[key];
                    }
                    value = schemaObject;
                }

                // Otherwise, it's OK.
                return value;

            case 'date':
                // If index is being set with null, undefined, or empty string: clear value.
                if (value === undefined || value === null || value === '') {
                    return undefined;
                }

                // Reject if object, array or boolean.
                if (!_.isDate(value) && !_.isString(value) && !_.isNumber(value)) {
                    throw new DateCastError(value, originalValue, properties);
                }

                // Attempt to parse string value with Date.parse (which returns number of milliseconds).
                if (_.isString(value)) {
                    value = Date.parse(value);
                }

                // If is timestamp, convert to Date.
                if (isNumeric(value)) {
                    value = new Date((value + '').length > 10 ? value : value * 1000);
                }

                // If the date couldn't be parsed, do not modify index.
                if (value == 'Invalid Date' || !_.isDate(value)) {
                    throw new DateParseValidationError(null, value, originalValue, properties);
                }

                // Transformation after typecasting but before validation and filters.
                if (properties.dateTransform) {
                    value = properties.dateTransform.call(this[_privateKey]._root, value, originalValue, properties);
                }

                return value;

            default: // 'any'
                return value;
        }
    }
1210286
function setUnusableRecord(state, unusableRecord) {
  Object.defineProperty(state, 'unusableRecord',
    {value: unusableRecord, writable: true, configurable: true, enumerable: false});
}