mathjs 9.3.2 → 9.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +22 -0
- package/README.md +1 -0
- package/bin/cli.js +11 -11
- package/docs/expressions/parsing.md +21 -4
- package/docs/reference/functions/complex.md +5 -49
- package/docs/reference/functions/eigs.md +12 -12
- package/docs/reference/functions/flatten.md +1 -0
- package/docs/reference/functions/matrixFromColumns.md +1 -1
- package/docs/reference/functions/matrixFromFunction.md +12 -0
- package/docs/reference/functions/matrixFromRows.md +1 -1
- package/docs/reference/functions.md +4 -1
- package/examples/advanced/custom_scope_objects.js +115 -0
- package/lib/browser/math.js +10 -10
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/core/create.js +8 -7
- package/lib/cjs/core/function/import.js +9 -7
- package/lib/cjs/core/function/typed.js +6 -1
- package/lib/cjs/defaultInstance.js +3 -3
- package/lib/cjs/entry/allFactoriesAny.js +3 -3
- package/lib/cjs/entry/allFactoriesNumber.js +3 -3
- package/lib/cjs/entry/configReadonly.js +5 -4
- package/lib/cjs/entry/dependenciesAny/dependenciesEigs.generated.js +51 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesMatrixFromColumns.generated.js +29 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesMatrixFromFunction.generated.js +26 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesMatrixFromRows.generated.js +29 -0
- package/lib/cjs/entry/dependenciesAny.generated.js +24 -0
- package/lib/cjs/entry/impureFunctionsAny.generated.js +22 -17
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +11 -9
- package/lib/cjs/entry/pureFunctionsAny.generated.js +78 -41
- package/lib/cjs/expression/Parser.js +22 -15
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +9 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/column.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/matrixFromColumns.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/matrixFromFunction.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/matrixFromRows.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/row.js +1 -1
- package/lib/cjs/expression/function/evaluate.js +6 -4
- package/lib/cjs/expression/keywords.js +1 -3
- package/lib/cjs/expression/node/AccessorNode.js +1 -0
- package/lib/cjs/expression/node/AssignmentNode.js +6 -3
- package/lib/cjs/expression/node/FunctionAssignmentNode.js +2 -4
- package/lib/cjs/expression/node/FunctionNode.js +76 -46
- package/lib/cjs/expression/node/IndexNode.js +5 -13
- package/lib/cjs/expression/node/Node.js +15 -9
- package/lib/cjs/expression/node/ObjectNode.js +5 -3
- package/lib/cjs/expression/node/SymbolNode.js +2 -2
- package/lib/cjs/expression/node/utils/access.js +5 -3
- package/lib/cjs/expression/node/utils/assign.js +5 -3
- package/lib/cjs/expression/parse.js +10 -14
- package/lib/cjs/expression/transform/utils/compileInlineExpression.js +5 -3
- package/lib/cjs/factoriesAny.js +24 -0
- package/lib/cjs/function/algebra/decomposition/qr.js +5 -3
- package/lib/cjs/function/algebra/simplify/resolve.js +7 -1
- package/lib/cjs/function/algebra/simplify.js +20 -14
- package/lib/cjs/function/algebra/solver/lsolveAll.js +6 -16
- package/lib/cjs/function/algebra/solver/usolveAll.js +6 -16
- package/lib/cjs/function/arithmetic/ceil.js +6 -16
- package/lib/cjs/function/arithmetic/floor.js +6 -16
- package/lib/cjs/function/arithmetic/norm.js +2 -2
- package/lib/cjs/function/arithmetic/pow.js +9 -7
- package/lib/cjs/function/arithmetic/round.js +7 -5
- package/lib/cjs/function/complex/im.js +3 -0
- package/lib/cjs/function/complex/re.js +3 -0
- package/lib/cjs/function/matrix/eigs/complexEigs.js +631 -0
- package/lib/cjs/function/matrix/eigs/realSymetric.js +341 -0
- package/lib/cjs/function/matrix/eigs.js +188 -334
- package/lib/cjs/function/matrix/flatten.js +1 -0
- package/lib/cjs/function/matrix/matrixFromColumns.js +118 -0
- package/lib/cjs/function/matrix/matrixFromFunction.js +85 -0
- package/lib/cjs/function/matrix/matrixFromRows.js +108 -0
- package/lib/cjs/function/probability/pickRandom.js +1 -1
- package/lib/cjs/function/probability/util/seededRNG.js +2 -2
- package/lib/cjs/function/relational/compareNatural.js +2 -2
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/plain/bignumber/index.js +2 -2
- package/lib/cjs/type/bignumber/BigNumber.js +2 -2
- package/lib/cjs/type/complex/Complex.js +5 -5
- package/lib/cjs/type/fraction/Fraction.js +2 -2
- package/lib/cjs/type/matrix/DenseMatrix.js +138 -0
- package/lib/cjs/type/matrix/Matrix.js +10 -0
- package/lib/cjs/type/matrix/SparseMatrix.js +77 -3
- package/lib/cjs/type/matrix/function/matrix.js +2 -1
- package/lib/cjs/type/unit/Unit.js +15 -13
- package/lib/cjs/utils/array.js +1 -1
- package/lib/cjs/utils/customs.js +18 -4
- package/lib/cjs/utils/emitter.js +2 -2
- package/lib/cjs/utils/function.js +6 -2
- package/lib/cjs/utils/is.js +7 -5
- package/lib/cjs/utils/latex.js +2 -2
- package/lib/cjs/utils/map.js +197 -0
- package/lib/cjs/utils/object.js +6 -5
- package/lib/cjs/utils/scope.js +33 -0
- package/lib/cjs/utils/snapshot.js +17 -16
- package/lib/cjs/utils/string.js +6 -4
- package/lib/cjs/version.js +1 -1
- package/lib/esm/constants.js +15 -15
- package/lib/esm/core/create.js +1 -2
- package/lib/esm/core/function/typed.js +5 -1
- package/lib/esm/entry/configReadonly.js +1 -2
- package/lib/esm/entry/dependenciesAny/dependenciesEigs.generated.js +34 -0
- package/lib/esm/entry/dependenciesAny/dependenciesMatrixFromColumns.generated.js +16 -0
- package/lib/esm/entry/dependenciesAny/dependenciesMatrixFromFunction.generated.js +14 -0
- package/lib/esm/entry/dependenciesAny/dependenciesMatrixFromRows.generated.js +16 -0
- package/lib/esm/entry/dependenciesAny.generated.js +3 -0
- package/lib/esm/entry/impureFunctionsAny.generated.js +13 -10
- package/lib/esm/entry/impureFunctionsNumber.generated.js +1 -1
- package/lib/esm/entry/pureFunctionsAny.generated.js +66 -32
- package/lib/esm/expression/Help.js +1 -1
- package/lib/esm/expression/Parser.js +23 -15
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +6 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/column.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/matrixFromColumns.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/matrixFromFunction.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/matrixFromRows.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/row.js +1 -1
- package/lib/esm/expression/function/compile.js +1 -1
- package/lib/esm/expression/function/evaluate.js +6 -5
- package/lib/esm/expression/function/help.js +1 -1
- package/lib/esm/expression/function/parser.js +1 -1
- package/lib/esm/expression/keywords.js +1 -3
- package/lib/esm/expression/node/AccessorNode.js +2 -1
- package/lib/esm/expression/node/ArrayNode.js +1 -1
- package/lib/esm/expression/node/AssignmentNode.js +7 -4
- package/lib/esm/expression/node/BlockNode.js +1 -1
- package/lib/esm/expression/node/ConditionalNode.js +1 -1
- package/lib/esm/expression/node/ConstantNode.js +1 -1
- package/lib/esm/expression/node/FunctionAssignmentNode.js +3 -4
- package/lib/esm/expression/node/FunctionNode.js +57 -39
- package/lib/esm/expression/node/IndexNode.js +1 -1
- package/lib/esm/expression/node/Node.js +7 -8
- package/lib/esm/expression/node/ObjectNode.js +1 -1
- package/lib/esm/expression/node/OperatorNode.js +1 -1
- package/lib/esm/expression/node/ParenthesisNode.js +1 -1
- package/lib/esm/expression/node/RangeNode.js +1 -1
- package/lib/esm/expression/node/RelationalNode.js +1 -1
- package/lib/esm/expression/node/SymbolNode.js +3 -3
- package/lib/esm/expression/parse.js +2 -3
- package/lib/esm/expression/transform/apply.transform.js +1 -1
- package/lib/esm/expression/transform/column.transform.js +1 -1
- package/lib/esm/expression/transform/concat.transform.js +1 -1
- package/lib/esm/expression/transform/diff.transform.js +1 -1
- package/lib/esm/expression/transform/filter.transform.js +1 -1
- package/lib/esm/expression/transform/forEach.transform.js +1 -1
- package/lib/esm/expression/transform/index.transform.js +1 -1
- package/lib/esm/expression/transform/map.transform.js +1 -1
- package/lib/esm/expression/transform/max.transform.js +1 -1
- package/lib/esm/expression/transform/mean.transform.js +1 -1
- package/lib/esm/expression/transform/min.transform.js +1 -1
- package/lib/esm/expression/transform/range.transform.js +1 -1
- package/lib/esm/expression/transform/row.transform.js +1 -1
- package/lib/esm/expression/transform/std.transform.js +1 -1
- package/lib/esm/expression/transform/subset.transform.js +1 -1
- package/lib/esm/expression/transform/sum.transform.js +1 -1
- package/lib/esm/expression/transform/utils/compileInlineExpression.js +4 -3
- package/lib/esm/expression/transform/variance.transform.js +1 -1
- package/lib/esm/factoriesAny.js +3 -0
- package/lib/esm/factoriesNumber.js +1 -1
- package/lib/esm/function/algebra/decomposition/lup.js +1 -1
- package/lib/esm/function/algebra/decomposition/qr.js +2 -3
- package/lib/esm/function/algebra/decomposition/slu.js +1 -1
- package/lib/esm/function/algebra/derivative.js +1 -1
- package/lib/esm/function/algebra/rationalize.js +1 -1
- package/lib/esm/function/algebra/simplify/resolve.js +7 -2
- package/lib/esm/function/algebra/simplify/simplifyConstant.js +1 -1
- package/lib/esm/function/algebra/simplify/simplifyCore.js +1 -1
- package/lib/esm/function/algebra/simplify/util.js +1 -1
- package/lib/esm/function/algebra/simplify.js +16 -12
- package/lib/esm/function/algebra/solver/lsolve.js +1 -1
- package/lib/esm/function/algebra/solver/lsolveAll.js +1 -1
- package/lib/esm/function/algebra/solver/lusolve.js +1 -1
- package/lib/esm/function/algebra/solver/usolve.js +1 -1
- package/lib/esm/function/algebra/solver/usolveAll.js +1 -1
- package/lib/esm/function/algebra/sparse/csAmd.js +1 -1
- package/lib/esm/function/algebra/sparse/csChol.js +1 -1
- package/lib/esm/function/algebra/sparse/csCounts.js +1 -1
- package/lib/esm/function/algebra/sparse/csLu.js +1 -1
- package/lib/esm/function/algebra/sparse/csSpsolve.js +1 -1
- package/lib/esm/function/algebra/sparse/csSqr.js +1 -1
- package/lib/esm/function/algebra/sparse/csSymperm.js +1 -1
- package/lib/esm/function/arithmetic/abs.js +1 -1
- package/lib/esm/function/arithmetic/add.js +1 -1
- package/lib/esm/function/arithmetic/addScalar.js +1 -1
- package/lib/esm/function/arithmetic/cbrt.js +1 -1
- package/lib/esm/function/arithmetic/ceil.js +1 -1
- package/lib/esm/function/arithmetic/cube.js +1 -1
- package/lib/esm/function/arithmetic/divide.js +1 -1
- package/lib/esm/function/arithmetic/divideScalar.js +1 -1
- package/lib/esm/function/arithmetic/dotDivide.js +1 -1
- package/lib/esm/function/arithmetic/dotMultiply.js +1 -1
- package/lib/esm/function/arithmetic/dotPow.js +1 -1
- package/lib/esm/function/arithmetic/exp.js +1 -1
- package/lib/esm/function/arithmetic/expm1.js +1 -1
- package/lib/esm/function/arithmetic/fix.js +1 -1
- package/lib/esm/function/arithmetic/floor.js +1 -1
- package/lib/esm/function/arithmetic/gcd.js +1 -1
- package/lib/esm/function/arithmetic/hypot.js +1 -1
- package/lib/esm/function/arithmetic/lcm.js +1 -1
- package/lib/esm/function/arithmetic/log.js +1 -1
- package/lib/esm/function/arithmetic/log10.js +1 -1
- package/lib/esm/function/arithmetic/log1p.js +1 -1
- package/lib/esm/function/arithmetic/log2.js +1 -1
- package/lib/esm/function/arithmetic/mod.js +1 -1
- package/lib/esm/function/arithmetic/multiply.js +1 -1
- package/lib/esm/function/arithmetic/multiplyScalar.js +1 -1
- package/lib/esm/function/arithmetic/norm.js +3 -3
- package/lib/esm/function/arithmetic/nthRoot.js +2 -2
- package/lib/esm/function/arithmetic/nthRoots.js +1 -1
- package/lib/esm/function/arithmetic/pow.js +10 -8
- package/lib/esm/function/arithmetic/round.js +6 -6
- package/lib/esm/function/arithmetic/sign.js +1 -1
- package/lib/esm/function/arithmetic/sqrt.js +1 -1
- package/lib/esm/function/arithmetic/square.js +1 -1
- package/lib/esm/function/arithmetic/subtract.js +1 -1
- package/lib/esm/function/arithmetic/unaryMinus.js +1 -1
- package/lib/esm/function/arithmetic/unaryPlus.js +1 -1
- package/lib/esm/function/arithmetic/xgcd.js +1 -1
- package/lib/esm/function/bitwise/bitAnd.js +1 -1
- package/lib/esm/function/bitwise/bitNot.js +1 -1
- package/lib/esm/function/bitwise/bitOr.js +1 -1
- package/lib/esm/function/bitwise/bitXor.js +1 -1
- package/lib/esm/function/bitwise/leftShift.js +1 -1
- package/lib/esm/function/bitwise/rightArithShift.js +1 -1
- package/lib/esm/function/bitwise/rightLogShift.js +1 -1
- package/lib/esm/function/combinatorics/bellNumbers.js +1 -1
- package/lib/esm/function/combinatorics/catalan.js +1 -1
- package/lib/esm/function/combinatorics/composition.js +1 -1
- package/lib/esm/function/combinatorics/stirlingS2.js +1 -1
- package/lib/esm/function/complex/arg.js +1 -1
- package/lib/esm/function/complex/conj.js +1 -1
- package/lib/esm/function/complex/im.js +4 -1
- package/lib/esm/function/complex/re.js +4 -1
- package/lib/esm/function/geometry/distance.js +1 -1
- package/lib/esm/function/geometry/intersect.js +1 -1
- package/lib/esm/function/logical/and.js +1 -1
- package/lib/esm/function/logical/not.js +1 -1
- package/lib/esm/function/logical/or.js +1 -1
- package/lib/esm/function/logical/xor.js +1 -1
- package/lib/esm/function/matrix/apply.js +1 -1
- package/lib/esm/function/matrix/column.js +1 -1
- package/lib/esm/function/matrix/concat.js +1 -1
- package/lib/esm/function/matrix/count.js +1 -1
- package/lib/esm/function/matrix/cross.js +1 -1
- package/lib/esm/function/matrix/ctranspose.js +1 -1
- package/lib/esm/function/matrix/det.js +1 -1
- package/lib/esm/function/matrix/diag.js +1 -1
- package/lib/esm/function/matrix/diff.js +1 -1
- package/lib/esm/function/matrix/dot.js +1 -1
- package/lib/esm/function/matrix/eigs/complexEigs.js +586 -0
- package/lib/esm/function/matrix/eigs/realSymetric.js +335 -0
- package/lib/esm/function/matrix/eigs.js +187 -335
- package/lib/esm/function/matrix/expm.js +1 -1
- package/lib/esm/function/matrix/filter.js +1 -1
- package/lib/esm/function/matrix/flatten.js +2 -1
- package/lib/esm/function/matrix/forEach.js +1 -1
- package/lib/esm/function/matrix/getMatrixDataType.js +1 -1
- package/lib/esm/function/matrix/identity.js +1 -1
- package/lib/esm/function/matrix/inv.js +1 -1
- package/lib/esm/function/matrix/kron.js +1 -1
- package/lib/esm/function/matrix/map.js +1 -1
- package/lib/esm/function/matrix/matrixFromColumns.js +93 -0
- package/lib/esm/function/matrix/matrixFromFunction.js +78 -0
- package/lib/esm/function/matrix/matrixFromRows.js +83 -0
- package/lib/esm/function/matrix/ones.js +1 -1
- package/lib/esm/function/matrix/partitionSelect.js +1 -1
- package/lib/esm/function/matrix/range.js +1 -1
- package/lib/esm/function/matrix/reshape.js +1 -1
- package/lib/esm/function/matrix/resize.js +1 -1
- package/lib/esm/function/matrix/rotate.js +1 -1
- package/lib/esm/function/matrix/rotationMatrix.js +1 -1
- package/lib/esm/function/matrix/row.js +1 -1
- package/lib/esm/function/matrix/size.js +1 -1
- package/lib/esm/function/matrix/sort.js +1 -1
- package/lib/esm/function/matrix/sqrtm.js +1 -1
- package/lib/esm/function/matrix/squeeze.js +1 -1
- package/lib/esm/function/matrix/subset.js +1 -1
- package/lib/esm/function/matrix/trace.js +1 -1
- package/lib/esm/function/matrix/transpose.js +1 -1
- package/lib/esm/function/matrix/zeros.js +1 -1
- package/lib/esm/function/probability/combinations.js +1 -1
- package/lib/esm/function/probability/combinationsWithRep.js +1 -1
- package/lib/esm/function/probability/factorial.js +1 -1
- package/lib/esm/function/probability/gamma.js +1 -1
- package/lib/esm/function/probability/kldivergence.js +1 -1
- package/lib/esm/function/probability/multinomial.js +1 -1
- package/lib/esm/function/probability/permutations.js +1 -1
- package/lib/esm/function/probability/pickRandom.js +2 -2
- package/lib/esm/function/probability/random.js +2 -2
- package/lib/esm/function/probability/randomInt.js +1 -1
- package/lib/esm/function/relational/compare.js +2 -2
- package/lib/esm/function/relational/compareNatural.js +1 -1
- package/lib/esm/function/relational/compareText.js +2 -2
- package/lib/esm/function/relational/deepEqual.js +1 -1
- package/lib/esm/function/relational/equal.js +2 -2
- package/lib/esm/function/relational/equalScalar.js +2 -2
- package/lib/esm/function/relational/equalText.js +1 -1
- package/lib/esm/function/relational/larger.js +2 -2
- package/lib/esm/function/relational/largerEq.js +2 -2
- package/lib/esm/function/relational/smaller.js +2 -2
- package/lib/esm/function/relational/smallerEq.js +2 -2
- package/lib/esm/function/relational/unequal.js +2 -2
- package/lib/esm/function/set/setCartesian.js +1 -1
- package/lib/esm/function/set/setDifference.js +1 -1
- package/lib/esm/function/set/setDistinct.js +1 -1
- package/lib/esm/function/set/setIntersect.js +1 -1
- package/lib/esm/function/set/setIsSubset.js +1 -1
- package/lib/esm/function/set/setMultiplicity.js +1 -1
- package/lib/esm/function/set/setPowerset.js +1 -1
- package/lib/esm/function/set/setSize.js +1 -1
- package/lib/esm/function/set/setSymDifference.js +1 -1
- package/lib/esm/function/set/setUnion.js +1 -1
- package/lib/esm/function/special/erf.js +1 -1
- package/lib/esm/function/statistics/mad.js +1 -1
- package/lib/esm/function/statistics/max.js +1 -1
- package/lib/esm/function/statistics/mean.js +1 -1
- package/lib/esm/function/statistics/median.js +1 -1
- package/lib/esm/function/statistics/min.js +1 -1
- package/lib/esm/function/statistics/mode.js +1 -1
- package/lib/esm/function/statistics/prod.js +1 -1
- package/lib/esm/function/statistics/quantileSeq.js +1 -1
- package/lib/esm/function/statistics/std.js +1 -1
- package/lib/esm/function/statistics/sum.js +1 -1
- package/lib/esm/function/statistics/variance.js +1 -1
- package/lib/esm/function/string/bin.js +1 -1
- package/lib/esm/function/string/format.js +1 -1
- package/lib/esm/function/string/hex.js +1 -1
- package/lib/esm/function/string/oct.js +1 -1
- package/lib/esm/function/string/print.js +1 -1
- package/lib/esm/function/trigonometry/acos.js +1 -1
- package/lib/esm/function/trigonometry/acosh.js +1 -1
- package/lib/esm/function/trigonometry/acot.js +1 -1
- package/lib/esm/function/trigonometry/acoth.js +1 -1
- package/lib/esm/function/trigonometry/acsc.js +1 -1
- package/lib/esm/function/trigonometry/acsch.js +1 -1
- package/lib/esm/function/trigonometry/asec.js +1 -1
- package/lib/esm/function/trigonometry/asech.js +1 -1
- package/lib/esm/function/trigonometry/asin.js +1 -1
- package/lib/esm/function/trigonometry/asinh.js +1 -1
- package/lib/esm/function/trigonometry/atan.js +1 -1
- package/lib/esm/function/trigonometry/atan2.js +1 -1
- package/lib/esm/function/trigonometry/atanh.js +1 -1
- package/lib/esm/function/trigonometry/cos.js +1 -1
- package/lib/esm/function/trigonometry/cosh.js +1 -1
- package/lib/esm/function/trigonometry/cot.js +1 -1
- package/lib/esm/function/trigonometry/coth.js +1 -1
- package/lib/esm/function/trigonometry/csc.js +1 -1
- package/lib/esm/function/trigonometry/csch.js +1 -1
- package/lib/esm/function/trigonometry/sec.js +1 -1
- package/lib/esm/function/trigonometry/sech.js +1 -1
- package/lib/esm/function/trigonometry/sin.js +1 -1
- package/lib/esm/function/trigonometry/sinh.js +1 -1
- package/lib/esm/function/trigonometry/tan.js +1 -1
- package/lib/esm/function/trigonometry/tanh.js +1 -1
- package/lib/esm/function/unit/to.js +1 -1
- package/lib/esm/function/utils/clone.js +1 -1
- package/lib/esm/function/utils/hasNumericValue.js +1 -1
- package/lib/esm/function/utils/isInteger.js +1 -1
- package/lib/esm/function/utils/isNaN.js +1 -1
- package/lib/esm/function/utils/isNegative.js +1 -1
- package/lib/esm/function/utils/isNumeric.js +1 -1
- package/lib/esm/function/utils/isPositive.js +1 -1
- package/lib/esm/function/utils/isPrime.js +1 -1
- package/lib/esm/function/utils/isZero.js +1 -1
- package/lib/esm/function/utils/numeric.js +1 -1
- package/lib/esm/function/utils/typeOf.js +1 -1
- package/lib/esm/json/reviver.js +1 -1
- package/lib/esm/type/bignumber/BigNumber.js +1 -1
- package/lib/esm/type/bignumber/function/bignumber.js +1 -1
- package/lib/esm/type/boolean.js +1 -1
- package/lib/esm/type/chain/Chain.js +1 -1
- package/lib/esm/type/chain/function/chain.js +1 -1
- package/lib/esm/type/complex/function/complex.js +1 -1
- package/lib/esm/type/fraction/function/fraction.js +1 -1
- package/lib/esm/type/matrix/DenseMatrix.js +75 -1
- package/lib/esm/type/matrix/FibonacciHeap.js +1 -1
- package/lib/esm/type/matrix/ImmutableDenseMatrix.js +1 -1
- package/lib/esm/type/matrix/Matrix.js +10 -0
- package/lib/esm/type/matrix/MatrixIndex.js +1 -1
- package/lib/esm/type/matrix/Spa.js +1 -1
- package/lib/esm/type/matrix/SparseMatrix.js +37 -3
- package/lib/esm/type/matrix/function/index.js +1 -1
- package/lib/esm/type/matrix/function/matrix.js +3 -2
- package/lib/esm/type/matrix/function/sparse.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm01.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm02.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm03.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm04.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm05.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm06.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm07.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm08.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm09.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm10.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm11.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm12.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm13.js +1 -1
- package/lib/esm/type/matrix/utils/algorithm14.js +1 -1
- package/lib/esm/type/number.js +1 -1
- package/lib/esm/type/string.js +1 -1
- package/lib/esm/type/unit/Unit.js +4 -5
- package/lib/esm/type/unit/function/createUnit.js +1 -1
- package/lib/esm/type/unit/function/splitUnit.js +1 -1
- package/lib/esm/type/unit/function/unit.js +1 -1
- package/lib/esm/type/unit/physicalConstants.js +2 -2
- package/lib/esm/utils/array.js +1 -1
- package/lib/esm/utils/customs.js +10 -0
- package/lib/esm/utils/map.js +135 -0
- package/lib/esm/utils/scope.js +26 -0
- package/lib/esm/utils/snapshot.js +3 -4
- package/lib/esm/version.js +1 -1
- package/package.json +18 -9
package/HISTORY.md
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
# History
|
2
2
|
|
3
|
+
# 2021-05-16, version 9.4.0
|
4
|
+
|
5
|
+
- Implemented support to use objects with a `Map` interface as scope,
|
6
|
+
see #2143, #2166. Thanks @jhugman.
|
7
|
+
- Extend `eigs` to support general complex matrices, see #1741. Thanks @m93a.
|
8
|
+
- DenseMatrix and SparseMatrix are now iterable, see #1184. Thanks @m93a.
|
9
|
+
- Implemented utility functions `matrixFromRows`, `matrixFromColumns`, and
|
10
|
+
`matrixFromFunction`, see #2155, #2153. Thanks @m93a.
|
11
|
+
- Added TypeScript definitions to the project, making it redundant to install
|
12
|
+
`@types/mathjs`, and making it easier to improve the definitions. See #2187,
|
13
|
+
#2192. Thanks @CatsMiaow.
|
14
|
+
- Upgraded dependencies
|
15
|
+
- `complex.js@2.0.13` (fixing #2211). Thanks @infusion
|
16
|
+
- `fraction.js@4.1.0` (`pow` now supporting rational exponents).
|
17
|
+
- Fix #2174: function `pickRandom` having no name. Thanks @HK-SHAO.
|
18
|
+
- Fix #2019: VSCode auto import keeps adding import { null } from 'mathjs'.
|
19
|
+
- Fix #2185: Fix TypeScript definition of unit division, which can also return
|
20
|
+
a number.
|
21
|
+
- Fix #2123: add type definitions for functions `row` and `column`.
|
22
|
+
- Fix some files not exposed in the package, see #2213. Thanks @javiermarinros.
|
23
|
+
|
24
|
+
|
3
25
|
# 2021-04-12, version 9.3.2
|
4
26
|
|
5
27
|
- Fix #2169: mathjs requesting `@babel/runtime` dependency.
|
package/README.md
CHANGED
@@ -11,6 +11,7 @@ Math.js is an extensive math library for JavaScript and Node.js. It features a f
|
|
11
11
|
[![License](https://img.shields.io/github/license/josdejong/mathjs.svg)](https://github.com/josdejong/mathjs/blob/master/LICENSE)
|
12
12
|
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fjosdejong%2Fmathjs.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjosdejong%2Fmathjs?ref=badge_shield)
|
13
13
|
[![Codecov](https://codecov.io/gh/josdejong/mathjs/branch/develop/graph/badge.svg)](https://codecov.io/gh/josdejong/mathjs)
|
14
|
+
[![Github Sponsor](https://camo.githubusercontent.com/7d9333b097b2f54a8957d126ab82937811489c9b75c3850f609985cf94cd29fe/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2532302d53706f6e736f722532306d652532306f6e2532304769744875622d6f72616e6765)](https://github.com/sponsors/josdejong)
|
14
15
|
|
15
16
|
## Features
|
16
17
|
|
package/bin/cli.js
CHANGED
@@ -45,9 +45,10 @@
|
|
45
45
|
* the License.
|
46
46
|
*/
|
47
47
|
|
48
|
-
let scope = {}
|
49
48
|
const fs = require('fs')
|
50
49
|
const path = require('path')
|
50
|
+
const { createEmptyMap } = require('../lib/cjs/utils/map.js')
|
51
|
+
let scope = createEmptyMap()
|
51
52
|
|
52
53
|
const PRECISION = 14 // decimals
|
53
54
|
|
@@ -95,11 +96,9 @@ function completer (text) {
|
|
95
96
|
keyword = m[0]
|
96
97
|
|
97
98
|
// scope variables
|
98
|
-
for (const def in scope) {
|
99
|
-
if (
|
100
|
-
|
101
|
-
matches.push(def)
|
102
|
-
}
|
99
|
+
for (const def in scope.keys()) {
|
100
|
+
if (def.indexOf(keyword) === 0) {
|
101
|
+
matches.push(def)
|
103
102
|
}
|
104
103
|
}
|
105
104
|
|
@@ -199,7 +198,7 @@ function runStream (input, output, mode, parenthesis) {
|
|
199
198
|
break
|
200
199
|
case 'clear':
|
201
200
|
// clear memory
|
202
|
-
scope =
|
201
|
+
scope = createEmptyMap()
|
203
202
|
console.log('memory cleared')
|
204
203
|
|
205
204
|
// get next input
|
@@ -231,16 +230,17 @@ function runStream (input, output, mode, parenthesis) {
|
|
231
230
|
if (math.isAssignmentNode(node)) {
|
232
231
|
const name = findSymbolName(node)
|
233
232
|
if (name !== null) {
|
234
|
-
|
235
|
-
|
233
|
+
const value = scope.get(name)
|
234
|
+
scope.set('ans', value)
|
235
|
+
console.log(name + ' = ' + format(value))
|
236
236
|
} else {
|
237
|
-
scope.ans
|
237
|
+
scope.set('ans', res)
|
238
238
|
console.log(format(res))
|
239
239
|
}
|
240
240
|
} else if (math.isHelp(res)) {
|
241
241
|
console.log(res.toString())
|
242
242
|
} else {
|
243
|
-
scope.ans
|
243
|
+
scope.set('ans', res)
|
244
244
|
console.log(format(res))
|
245
245
|
}
|
246
246
|
}
|
@@ -22,8 +22,8 @@ math.evaluate([expr1, expr2, expr3, ...], scope)
|
|
22
22
|
|
23
23
|
Function `evaluate` accepts a single expression or an array with
|
24
24
|
expressions as the first argument and has an optional second argument
|
25
|
-
containing a scope with variables and functions. The scope
|
26
|
-
JavaScript Object. The scope will be used to resolve symbols, and to write
|
25
|
+
containing a scope with variables and functions. The scope can be a regular
|
26
|
+
JavaScript Object, or Map. The scope will be used to resolve symbols, and to write
|
27
27
|
assigned variables or function.
|
28
28
|
|
29
29
|
The following code demonstrates how to evaluate expressions.
|
@@ -70,7 +70,7 @@ const result = code.evaluate([scope]) // evaluate the code with an optional scop
|
|
70
70
|
An expression needs to be compiled only once, after which the
|
71
71
|
expression can be evaluated repeatedly and against different scopes.
|
72
72
|
The optional scope is used to resolve symbols and to write assigned
|
73
|
-
variables or functions. Parameter `scope`
|
73
|
+
variables or functions. Parameter [`scope`](#scope) can be a regular Object, or Map.
|
74
74
|
|
75
75
|
Example usage:
|
76
76
|
|
@@ -107,7 +107,7 @@ The API of nodes is described in detail on the page
|
|
107
107
|
An expression needs to be parsed and compiled only once, after which the
|
108
108
|
expression can be evaluated repeatedly. On evaluation, an optional scope
|
109
109
|
can be provided, which is used to resolve symbols and to write assigned
|
110
|
-
variables or functions. Parameter `scope` is a regular Object.
|
110
|
+
variables or functions. Parameter [`scope`](#scope) is a regular Object or Map.
|
111
111
|
|
112
112
|
Example usage:
|
113
113
|
|
@@ -205,3 +205,20 @@ parser.evaluate('hello("user")') // "hello, user!"
|
|
205
205
|
// clear defined functions and variables
|
206
206
|
parser.clear()
|
207
207
|
```
|
208
|
+
|
209
|
+
## Scope
|
210
|
+
|
211
|
+
The scope is a data-structure used to store and lookup variables and functions defined and used by expressions.
|
212
|
+
|
213
|
+
It is passed to mathjs via calls to [`math.evaluate`](#evaluate) or `simplify`.
|
214
|
+
|
215
|
+
For ease of use, it can be a Plain Javascript Object; for safety it can be a plain `Map` and for flexibility, any object that has
|
216
|
+
the methods `get`/`set`/`has`/`keys`, seen on `Map`.
|
217
|
+
|
218
|
+
Some care is taken to mutate the same object that is passed into mathjs, so they can collect the definitions from mathjs scripts and expressions.
|
219
|
+
|
220
|
+
`evaluate` will fail if the expression uses a blacklisted symbol, preventing mathjs expressions to escape into Javascript. This is enforced by access to the scope.
|
221
|
+
|
222
|
+
For less reliance on this blacklist, scope can also be a `Map`, which allows mathjs expressions to define variables and functions of any name.
|
223
|
+
|
224
|
+
For more, see [examples of custom scopes][../../examples/advanced/custom_scope_objects.js.html].
|
@@ -2,60 +2,16 @@
|
|
2
2
|
|
3
3
|
# Function complex
|
4
4
|
|
5
|
-
Create a complex value or convert a value to a complex value.
|
6
5
|
|
7
6
|
|
8
|
-
## Syntax
|
9
|
-
|
10
|
-
```js
|
11
|
-
math.complex() // creates a complex value with zero
|
12
|
-
// as real and imaginary part.
|
13
|
-
math.complex(re : number, im : string) // creates a complex value with provided
|
14
|
-
// values for real and imaginary part.
|
15
|
-
math.complex(re : number) // creates a complex value with provided
|
16
|
-
// real value and zero imaginary part.
|
17
|
-
math.complex(complex : Complex) // clones the provided complex value.
|
18
|
-
math.complex(arg : string) // parses a string into a complex value.
|
19
|
-
math.complex(array : Array) // converts the elements of the array
|
20
|
-
// or matrix element wise into a
|
21
|
-
// complex value.
|
22
|
-
math.complex({re: number, im: number}) // creates a complex value with provided
|
23
|
-
// values for real an imaginary part.
|
24
|
-
math.complex({r: number, phi: number}) // creates a complex value with provided
|
25
|
-
// polar coordinates
|
26
|
-
```
|
27
7
|
|
28
8
|
### Parameters
|
29
9
|
|
30
10
|
Parameter | Type | Description
|
31
11
|
--------- | ---- | -----------
|
32
|
-
`
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
---- | -----------
|
38
|
-
Complex | Array | Matrix | Returns a complex value
|
39
|
-
|
40
|
-
|
41
|
-
## Examples
|
42
|
-
|
43
|
-
```js
|
44
|
-
const a = math.complex(3, -4) // a = Complex 3 - 4i
|
45
|
-
a.re = 5 // a = Complex 5 - 4i
|
46
|
-
const i = a.im // Number -4
|
47
|
-
const b = math.complex('2 + 6i') // Complex 2 + 6i
|
48
|
-
const c = math.complex() // Complex 0 + 0i
|
49
|
-
const d = math.add(a, b) // Complex 5 + 2i
|
50
|
-
```
|
51
|
-
|
52
|
-
|
53
|
-
## See also
|
12
|
+
`arr` | number[][] | the matrix to find eigenvalues of
|
13
|
+
`N` | number | size of the matrix
|
14
|
+
`prec` | number | BigNumber | precision, anything lower will be considered zero
|
15
|
+
`type` | 'number' | 'BigNumber' | 'Complex' |
|
16
|
+
`findVectors` | boolean | should we find eigenvectors?
|
54
17
|
|
55
|
-
[bignumber](bignumber.md),
|
56
|
-
[boolean](boolean.md),
|
57
|
-
[index](index.md),
|
58
|
-
[matrix](matrix.md),
|
59
|
-
[number](number.md),
|
60
|
-
[string](string.md),
|
61
|
-
[unit](unit.md)
|
@@ -2,19 +2,17 @@
|
|
2
2
|
|
3
3
|
# Function eigs
|
4
4
|
|
5
|
-
Compute
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
eigenvalues are of 'number' type. For 'bignumber' the eigenvalues are of ''bignumber' type.
|
11
|
-
Eigenvectors are always of 'number' type.
|
5
|
+
Compute eigenvalues and eigenvectors of a matrix. The eigenvalues are sorted by their absolute value, ascending.
|
6
|
+
An eigenvalue with multiplicity k will be listed k times. The eigenvectors are returned as columns of a matrix –
|
7
|
+
the eigenvector that belongs to the j-th eigenvalue in the list (eg. `values[j]`) is the j-th column (eg. `column(vectors, j)`).
|
8
|
+
If the algorithm fails to converge, it will throw an error – in that case, however, you may still find useful information
|
9
|
+
in `err.values` and `err.vectors`.
|
12
10
|
|
13
11
|
|
14
12
|
## Syntax
|
15
13
|
|
16
14
|
```js
|
17
|
-
math.eigs(x)
|
15
|
+
math.eigs(x, [prec])
|
18
16
|
```
|
19
17
|
|
20
18
|
### Parameters
|
@@ -22,23 +20,25 @@ math.eigs(x)
|
|
22
20
|
Parameter | Type | Description
|
23
21
|
--------- | ---- | -----------
|
24
22
|
`x` | Array | Matrix | Matrix to be diagonalized
|
23
|
+
`prec` | number | BigNumber | Precision, default value: 1e-15
|
25
24
|
|
26
25
|
### Returns
|
27
26
|
|
28
27
|
Type | Description
|
29
28
|
---- | -----------
|
30
|
-
{values: Array, vectors: Array
|
29
|
+
{values: Array | Matrix, vectors: Array | Matrix} | Object containing an array of eigenvalues and a matrix with eigenvectors as columns.
|
31
30
|
|
32
31
|
|
33
32
|
## Examples
|
34
33
|
|
35
34
|
```js
|
35
|
+
const { eigs, multiply, column, transpose } = math
|
36
36
|
const H = [[5, 2.3], [2.3, 1]]
|
37
|
-
const ans =
|
37
|
+
const ans = eigs(H) // returns {values: [E1,E2...sorted], vectors: [v1,v2.... corresponding vectors as columns]}
|
38
38
|
const E = ans.values
|
39
39
|
const U = ans.vectors
|
40
|
-
|
41
|
-
const UTxHxU =
|
40
|
+
multiply(H, column(U, 0)) // returns multiply(E[0], column(U, 0))
|
41
|
+
const UTxHxU = multiply(transpose(U), H, U) // diagonalizes H
|
42
42
|
E[0] == UTxHxU[0][0] // returns true
|
43
43
|
```
|
44
44
|
|
@@ -3,6 +3,8 @@
|
|
3
3
|
# Function matrixFromFunction
|
4
4
|
|
5
5
|
Create a matrix by evaluating a generating function at each index.
|
6
|
+
The simplest overload returns a multi-dimensional array as long as `size` is an array.
|
7
|
+
Passing `size` as a Matrix or specifying a `format` will result in returning a Matrix.
|
6
8
|
|
7
9
|
|
8
10
|
## Syntax
|
@@ -19,6 +21,16 @@ math.matrixFromFunction(size, format, datatype, fn)
|
|
19
21
|
|
20
22
|
Parameter | Type | Description
|
21
23
|
--------- | ---- | -----------
|
24
|
+
`size` | Array | Matrix | The size of the matrix to be created
|
25
|
+
`fn` | function | Callback function invoked for every entry in the matrix
|
26
|
+
`format` | string | The Matrix storage format, either `'dense'` or `'sparse'`
|
27
|
+
`datatype` | string | Type of the values
|
28
|
+
|
29
|
+
### Returns
|
30
|
+
|
31
|
+
Type | Description
|
32
|
+
---- | -----------
|
33
|
+
Array | Matrix | Returns the created matrix
|
22
34
|
|
23
35
|
|
24
36
|
## Examples
|
@@ -124,7 +124,7 @@ Function | Description
|
|
124
124
|
[math.diag(X)](functions/diag.md) | Create a diagonal matrix or retrieve the diagonal of a matrix When `x` is a vector, a matrix with vector `x` on the diagonal will be returned.
|
125
125
|
[math.diff(arr)](functions/diff.md) | Create a new matrix or array of the difference between elements of the given array The optional dim parameter lets you specify the dimension to evaluate the difference of If no dimension parameter is passed it is assumed as dimension 0 Dimension is zero-based in javascript and one-based in the parser and can be a number or bignumber Arrays must be 'rectangular' meaning arrays like [1, 2] If something is passed as a matrix it will be returned as a matrix but other than that all matrices are converted to arrays.
|
126
126
|
[math.dot(x, y)](functions/dot.md) | Calculate the dot product of two vectors.
|
127
|
-
[math.eigs(x)](functions/eigs.md) | Compute
|
127
|
+
[math.eigs(x, [prec])](functions/eigs.md) | Compute eigenvalues and eigenvectors of a matrix.
|
128
128
|
[math.expm(x)](functions/expm.md) | Compute the matrix exponential, expm(A) = e^A.
|
129
129
|
[math.filter(x, test)](functions/filter.md) | Filter the items in an array or one dimensional matrix.
|
130
130
|
[math.flatten(x)](functions/flatten.md) | Flatten a multi dimensional matrix into a single dimensional matrix.
|
@@ -134,6 +134,9 @@ Function | Description
|
|
134
134
|
[math.inv(x)](functions/inv.md) | Calculate the inverse of a square matrix.
|
135
135
|
[math.kron(x, y)](functions/kron.md) | Calculates the kronecker product of 2 matrices or vectors.
|
136
136
|
[math.map(x, callback)](functions/map.md) | Create a new matrix or array with the results of the callback function executed on each entry of the matrix/array.
|
137
|
+
[math.matrixFromColumns(...arr)](functions/matrixFromColumns.md) | Create a dense matrix from vectors as individual columns.
|
138
|
+
[math.matrixFromFunction(size, fn)](functions/matrixFromFunction.md) | Create a matrix by evaluating a generating function at each index.
|
139
|
+
[math.matrixFromRows(...arr)](functions/matrixFromRows.md) | Create a dense matrix from vectors as individual rows.
|
137
140
|
[math.ones(m, n, p, ...)](functions/ones.md) | Create a matrix filled with ones.
|
138
141
|
[math.partitionSelect(x, k)](functions/partitionSelect.md) | Partition-based selection of an array or 1D matrix.
|
139
142
|
[math.range(start, end [, step])](functions/range.md) | Create an array from a range.
|
@@ -0,0 +1,115 @@
|
|
1
|
+
const { create, all } = require('../..')
|
2
|
+
|
3
|
+
const math = create(all)
|
4
|
+
|
5
|
+
// The expression evaluator accepts an optional scope object.
|
6
|
+
// This is the symbol table for variable defintions and function declations.
|
7
|
+
|
8
|
+
// Scope can be a bare object.
|
9
|
+
function withObjectScope () {
|
10
|
+
const scope = { x: 3 }
|
11
|
+
|
12
|
+
math.evaluate('x', scope) // 1
|
13
|
+
math.evaluate('y = 2 x', scope)
|
14
|
+
math.evaluate('scalar = 1', scope)
|
15
|
+
math.evaluate('area(length, width) = length * width * scalar', scope)
|
16
|
+
math.evaluate('A = area(x, y)', scope)
|
17
|
+
|
18
|
+
console.log('Object scope:', scope)
|
19
|
+
}
|
20
|
+
|
21
|
+
// Where flexibility is important, scope can duck type appear to be a Map.
|
22
|
+
function withMapScope (scope, name) {
|
23
|
+
scope.set('x', 3)
|
24
|
+
|
25
|
+
math.evaluate('x', scope) // 1
|
26
|
+
math.evaluate('y = 2 x', scope)
|
27
|
+
math.evaluate('scalar = 1', scope)
|
28
|
+
math.evaluate('area(length, width) = length * width * scalar', scope)
|
29
|
+
math.evaluate('A = area(x, y)', scope)
|
30
|
+
|
31
|
+
console.log(`Map-like scope (${name}):`, scope.localScope)
|
32
|
+
}
|
33
|
+
|
34
|
+
// This is a minimal set of functions to look like a Map.
|
35
|
+
class MapScope {
|
36
|
+
constructor () {
|
37
|
+
this.localScope = new Map()
|
38
|
+
}
|
39
|
+
|
40
|
+
get (key) {
|
41
|
+
// Remember to sanitize your inputs, or use
|
42
|
+
// a datastructure that isn't a footgun.
|
43
|
+
return this.localScope.get(key)
|
44
|
+
}
|
45
|
+
|
46
|
+
set (key, value) {
|
47
|
+
return this.localScope.set(key, value)
|
48
|
+
}
|
49
|
+
|
50
|
+
has (key) {
|
51
|
+
return this.localScope.has(key)
|
52
|
+
}
|
53
|
+
|
54
|
+
keys () {
|
55
|
+
return this.localScope.keys()
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
/*
|
60
|
+
* This is a more fully featured example, with all methods
|
61
|
+
* used in mathjs.
|
62
|
+
*
|
63
|
+
*/
|
64
|
+
class AdvancedMapScope extends MapScope {
|
65
|
+
constructor (parent) {
|
66
|
+
super()
|
67
|
+
this.parentScope = parent
|
68
|
+
}
|
69
|
+
|
70
|
+
get (key) {
|
71
|
+
return this.localScope.get(key) ?? this.parentScope?.get(key)
|
72
|
+
}
|
73
|
+
|
74
|
+
has (key) {
|
75
|
+
return this.localScope.has(key) ?? this.parentScope?.get(key)
|
76
|
+
}
|
77
|
+
|
78
|
+
keys () {
|
79
|
+
if (this.parentScope) {
|
80
|
+
return new Set([...this.localScope.keys(), ...this.parentScope.keys()])
|
81
|
+
} else {
|
82
|
+
return this.localScope.keys()
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
delete () {
|
87
|
+
return this.localScope.delete()
|
88
|
+
}
|
89
|
+
|
90
|
+
clear () {
|
91
|
+
return this.localScope.clear()
|
92
|
+
}
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Creates a child scope from this one. This is used in function calls.
|
96
|
+
*
|
97
|
+
* @returns a new Map scope that has access to the symbols in the parent, but
|
98
|
+
* cannot overwrite them.
|
99
|
+
*/
|
100
|
+
createSubScope () {
|
101
|
+
return new AdvancedMapScope(this)
|
102
|
+
}
|
103
|
+
|
104
|
+
toString () {
|
105
|
+
return this.localScope.toString()
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
withObjectScope()
|
110
|
+
// Where safety is important, scope can also be a Map
|
111
|
+
withMapScope(new Map(), 'simple Map')
|
112
|
+
// Where flexibility is important, scope can duck type appear to be a Map.
|
113
|
+
withMapScope(new MapScope(), 'MapScope example')
|
114
|
+
// Extra methods allow even finer grain control.
|
115
|
+
withMapScope(new AdvancedMapScope(), 'AdvancedScope example')
|