"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.core = core;
exports.create = create;
Object.defineProperty(exports, "factory", {
  enumerable: true,
  get: function get() {
    return _factory.factory;
  }
});

var _config = require("../core/config");

var _core = require("../core/core");

var _object = require("../utils/object");

var _ArgumentsError = require("../error/ArgumentsError");

var _DimensionError = require("../error/DimensionError");

var _IndexError = require("../error/IndexError");

var _log = require("../utils/log");

var _array = require("../utils/array");

var _factory = require("../utils/factory");

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function core(config) {
  var mergedConfig = _extends({}, _config.DEFAULT_CONFIG, config);

  return (0, _core.createCore)({
    config: mergedConfig
  });
}
/**
 * Create a mathjs instance from given factory functions and optionally config
 *
 * Usage:
 *
 *     const mathjs1 = create({ createAdd, createMultiply, ...})
 *     const config = { number: 'BigNumber' }
 *     const mathjs2 = create(all, config)
 *
 * @param {Object} factories   An object with factory functions
 *                             The object can contain nested objects,
 *                             all nested objects will be flattened.
 * @param {Object} [config]    Optional configuration
 */


function create(factories, config) {
  var math = core(config); // the create function exposed on the mathjs instance is bound to
  // the factory functions passed before

  math.create = create.bind(null, factories);
  math.core = core; // import the factory functions like createAdd as an array instead of object,
  // else they will get a different naming (`createAdd` instead of `add`).

  math['import']((0, _object.values)((0, _object.deepFlatten)(factories))); // TODO: deprecated since v6.0.0. Clean up some day

  var movedNames = ['type.isNumber', 'type.isComplex', 'type.isBigNumber', 'type.isFraction', 'type.isUnit', 'type.isString', 'type.isArray', 'type.isMatrix', 'type.isDenseMatrix', 'type.isSparseMatrix', 'type.isRange', 'type.isIndex', 'type.isBoolean', 'type.isResultSet', 'type.isHelp', 'type.isFunction', 'type.isDate', 'type.isRegExp', 'type.isObject', 'type.isNull', 'type.isUndefined', 'type.isAccessorNode', 'type.isArrayNode', 'type.isAssignmentNode', 'type.isBlockNode', 'type.isConditionalNode', 'type.isConstantNode', 'type.isFunctionAssignmentNode', 'type.isFunctionNode', 'type.isIndexNode', 'type.isNode', 'type.isObjectNode', 'type.isOperatorNode', 'type.isParenthesisNode', 'type.isRangeNode', 'type.isSymbolNode', 'type.isChain', 'type.BigNumber', 'type.Chain', 'type.Complex', 'type.Fraction', 'type.Matrix', 'type.DenseMatrix', 'type.SparseMatrix', 'type.Spa', 'type.FibonacciHeap', 'type.ImmutableDenseMatrix', 'type.Index', 'type.Range', 'type.ResultSet', 'type.Unit', 'type.Help', 'type.Parser', 'expression.parse', 'expression.Parser', 'expression.node.AccessorNode', 'expression.node.ArrayNode', 'expression.node.AssignmentNode', 'expression.node.BlockNode', 'expression.node.ConditionalNode', 'expression.node.ConstantNode', 'expression.node.IndexNode', 'expression.node.FunctionAssignmentNode', 'expression.node.FunctionNode', 'expression.node.Node', 'expression.node.ObjectNode', 'expression.node.OperatorNode', 'expression.node.ParenthesisNode', 'expression.node.RangeNode', 'expression.node.RelationalNode', 'expression.node.SymbolNode', 'json.reviver', 'error.ArgumentsError', 'error.DimensionError', 'error.IndexError'];
  movedNames.forEach(function (fullName) {
    var parts = fullName.split('.');
    var path = (0, _array.initial)(parts);
    var name = (0, _array.last)(parts);
    var obj = (0, _object.traverse)(math, path);
    (0, _object.lazy)(obj, name, function () {
      (0, _log.warnOnce)("math.".concat(fullName, " is moved to math.").concat(name, " in v6.0.0. ") + 'Please use the new location instead.');
      return math[name];
    });
  });
  (0, _object.lazy)(math.expression, 'docs', function () {
    throw new Error('math.expression.docs has been moved. ' + 'Please import via "import { docs } from \'mathjs\'"');
  });
  math.ArgumentsError = _ArgumentsError.ArgumentsError;
  math.DimensionError = _DimensionError.DimensionError;
  math.IndexError = _IndexError.IndexError;
  return math;
}