mathjs 13.1.0 → 13.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -176,7 +176,15 @@ const createFunctionNode = exports.createFunctionNode = /* #__PURE__ */(0, _fact
176
176
  const rawArgs = this.args;
177
177
  return function evalFunctionNode(scope, args, context) {
178
178
  const fn = resolveFn(scope);
179
- return fn(rawArgs, math, (0, _scope.createSubScope)(scope, args));
179
+
180
+ // the original function can be overwritten in the scope with a non-rawArgs function
181
+ if (fn.rawArgs === true) {
182
+ return fn(rawArgs, math, (0, _scope.createSubScope)(scope, args));
183
+ } else {
184
+ // "regular" evaluation
185
+ const values = evalArgs.map(evalArg => evalArg(scope, args, context));
186
+ return fn(...values);
187
+ }
180
188
  };
181
189
  } else {
182
190
  // "regular" evaluation
package/lib/cjs/header.js CHANGED
@@ -6,8 +6,8 @@
6
6
  * It features real and complex numbers, units, matrices, a large set of
7
7
  * mathematical functions, and a flexible expression parser.
8
8
  *
9
- * @version 13.1.0
10
- * @date 2024-08-26
9
+ * @version 13.1.1
10
+ * @date 2024-08-27
11
11
  *
12
12
  * @license
13
13
  * Copyright (C) 2013-2024 Jos de Jong <wjosdejong@gmail.com>
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getSafeMethod = getSafeMethod;
7
- exports.getSafeProperties = getSafeProperties;
8
7
  exports.getSafeProperty = getSafeProperty;
9
- exports.hasSafeProperty = hasSafeProperty;
10
8
  exports.isPlainObject = isPlainObject;
11
9
  exports.isSafeMethod = isSafeMethod;
12
10
  exports.isSafeProperty = isSafeProperty;
@@ -22,7 +20,7 @@ var _object = require("./object.js");
22
20
  */
23
21
  function getSafeProperty(object, prop) {
24
22
  // only allow getting safe properties of a plain object
25
- if (isPlainObject(object) && isSafeProperty(object, prop)) {
23
+ if (isSafeProperty(object, prop)) {
26
24
  return object[prop];
27
25
  }
28
26
  if (typeof object[prop] === 'function' && isSafeMethod(object, prop)) {
@@ -43,27 +41,22 @@ function getSafeProperty(object, prop) {
43
41
  // TODO: merge this function into access.js?
44
42
  function setSafeProperty(object, prop, value) {
45
43
  // only allow setting safe properties of a plain object
46
- if (isPlainObject(object) && isSafeProperty(object, prop)) {
44
+ if (isSafeProperty(object, prop)) {
47
45
  object[prop] = value;
48
46
  return value;
49
47
  }
50
48
  throw new Error('No access to property "' + prop + '"');
51
49
  }
52
- function getSafeProperties(object) {
53
- return Object.keys(object).filter(prop => (0, _object.hasOwnProperty)(object, prop));
54
- }
55
- function hasSafeProperty(object, prop) {
56
- return prop in object;
57
- }
58
50
 
59
51
  /**
60
- * Test whether a property is safe to use for an object.
52
+ * Test whether a property is safe to use on an object or Array.
61
53
  * For example .toString and .constructor are not safe
54
+ * @param {Object | Array} object
62
55
  * @param {string} prop
63
56
  * @return {boolean} Returns true when safe
64
57
  */
65
58
  function isSafeProperty(object, prop) {
66
- if (!object || typeof object !== 'object') {
59
+ if (!isPlainObject(object) && !Array.isArray(object)) {
67
60
  return false;
68
61
  }
69
62
  // SAFE: whitelisted
@@ -24,7 +24,7 @@ class ObjectWrappingMap {
24
24
  this[Symbol.iterator] = this.entries;
25
25
  }
26
26
  keys() {
27
- return Object.keys(this.wrappedObject).values();
27
+ return Object.keys(this.wrappedObject).filter(key => this.has(key)).values();
28
28
  }
29
29
  get(key) {
30
30
  return (0, _customs.getSafeProperty)(this.wrappedObject, key);
@@ -34,7 +34,7 @@ class ObjectWrappingMap {
34
34
  return this;
35
35
  }
36
36
  has(key) {
37
- return (0, _customs.hasSafeProperty)(this.wrappedObject, key);
37
+ return (0, _customs.isSafeProperty)(this.wrappedObject, key) && key in this.wrappedObject;
38
38
  }
39
39
  entries() {
40
40
  return mapIterator(this.keys(), key => [key, this.get(key)]);
@@ -45,7 +45,9 @@ class ObjectWrappingMap {
45
45
  }
46
46
  }
47
47
  delete(key) {
48
- delete this.wrappedObject[key];
48
+ if ((0, _customs.isSafeProperty)(this.wrappedObject, key)) {
49
+ delete this.wrappedObject[key];
50
+ }
49
51
  }
50
52
  clear() {
51
53
  for (const key of this.keys()) {
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.version = void 0;
7
- const version = exports.version = '13.1.0';
7
+ const version = exports.version = '13.1.1';
8
8
  // Note: This file is automatically generated when building math.js.
9
9
  // Changes made in this file will be overwritten.
@@ -169,7 +169,15 @@ export var createFunctionNode = /* #__PURE__ */factory(name, dependencies, _ref
169
169
  var rawArgs = this.args;
170
170
  return function evalFunctionNode(scope, args, context) {
171
171
  var fn = resolveFn(scope);
172
- return fn(rawArgs, math, createSubScope(scope, args));
172
+
173
+ // the original function can be overwritten in the scope with a non-rawArgs function
174
+ if (fn.rawArgs === true) {
175
+ return fn(rawArgs, math, createSubScope(scope, args));
176
+ } else {
177
+ // "regular" evaluation
178
+ var values = evalArgs.map(evalArg => evalArg(scope, args, context));
179
+ return fn(...values);
180
+ }
173
181
  };
174
182
  } else {
175
183
  // "regular" evaluation
@@ -10,7 +10,7 @@ import { hasOwnProperty } from './object.js';
10
10
  */
11
11
  function getSafeProperty(object, prop) {
12
12
  // only allow getting safe properties of a plain object
13
- if (isPlainObject(object) && isSafeProperty(object, prop)) {
13
+ if (isSafeProperty(object, prop)) {
14
14
  return object[prop];
15
15
  }
16
16
  if (typeof object[prop] === 'function' && isSafeMethod(object, prop)) {
@@ -31,27 +31,22 @@ function getSafeProperty(object, prop) {
31
31
  // TODO: merge this function into access.js?
32
32
  function setSafeProperty(object, prop, value) {
33
33
  // only allow setting safe properties of a plain object
34
- if (isPlainObject(object) && isSafeProperty(object, prop)) {
34
+ if (isSafeProperty(object, prop)) {
35
35
  object[prop] = value;
36
36
  return value;
37
37
  }
38
38
  throw new Error('No access to property "' + prop + '"');
39
39
  }
40
- function getSafeProperties(object) {
41
- return Object.keys(object).filter(prop => hasOwnProperty(object, prop));
42
- }
43
- function hasSafeProperty(object, prop) {
44
- return prop in object;
45
- }
46
40
 
47
41
  /**
48
- * Test whether a property is safe to use for an object.
42
+ * Test whether a property is safe to use on an object or Array.
49
43
  * For example .toString and .constructor are not safe
44
+ * @param {Object | Array} object
50
45
  * @param {string} prop
51
46
  * @return {boolean} Returns true when safe
52
47
  */
53
48
  function isSafeProperty(object, prop) {
54
- if (!object || typeof object !== 'object') {
49
+ if (!isPlainObject(object) && !Array.isArray(object)) {
55
50
  return false;
56
51
  }
57
52
  // SAFE: whitelisted
@@ -147,8 +142,6 @@ var safeNativeMethods = {
147
142
  export { getSafeProperty };
148
143
  export { setSafeProperty };
149
144
  export { isSafeProperty };
150
- export { hasSafeProperty };
151
- export { getSafeProperties };
152
145
  export { getSafeMethod };
153
146
  export { isSafeMethod };
154
147
  export { isPlainObject };
@@ -1,4 +1,4 @@
1
- import { getSafeProperty, hasSafeProperty, setSafeProperty } from './customs.js';
1
+ import { getSafeProperty, isSafeProperty, setSafeProperty } from './customs.js';
2
2
  import { isMap, isObject } from './is.js';
3
3
 
4
4
  /**
@@ -15,7 +15,7 @@ export class ObjectWrappingMap {
15
15
  this[Symbol.iterator] = this.entries;
16
16
  }
17
17
  keys() {
18
- return Object.keys(this.wrappedObject).values();
18
+ return Object.keys(this.wrappedObject).filter(key => this.has(key)).values();
19
19
  }
20
20
  get(key) {
21
21
  return getSafeProperty(this.wrappedObject, key);
@@ -25,7 +25,7 @@ export class ObjectWrappingMap {
25
25
  return this;
26
26
  }
27
27
  has(key) {
28
- return hasSafeProperty(this.wrappedObject, key);
28
+ return isSafeProperty(this.wrappedObject, key) && key in this.wrappedObject;
29
29
  }
30
30
  entries() {
31
31
  return mapIterator(this.keys(), key => [key, this.get(key)]);
@@ -36,7 +36,9 @@ export class ObjectWrappingMap {
36
36
  }
37
37
  }
38
38
  delete(key) {
39
- delete this.wrappedObject[key];
39
+ if (isSafeProperty(this.wrappedObject, key)) {
40
+ delete this.wrappedObject[key];
41
+ }
40
42
  }
41
43
  clear() {
42
44
  for (var key of this.keys()) {
@@ -1,3 +1,3 @@
1
- export var version = '13.1.0';
1
+ export var version = '13.1.1';
2
2
  // Note: This file is automatically generated when building math.js.
3
3
  // Changes made in this file will be overwritten.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mathjs",
3
- "version": "13.1.0",
3
+ "version": "13.1.1",
4
4
  "description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
5
5
  "author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
6
6
  "homepage": "https://mathjs.org",