33 Commits

Author SHA1 Message Date
David Contreras
40c09c5e76
refactor: simplify flatten function using Array.prototype.flat (#3354)
* refactor: simplify flatten function using Array.prototype.flat

* Added fallback

* added option to flatten arrays with homogeneous size

* Typos in array.js and array.test.js

* fix types in jsdocs

* Renamed variable

* Reverted to original form

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2025-02-17 17:19:13 +01:00
Jos de Jong
e00d3678c6 fix: #3323 support functions in function clone 2024-11-20 10:34:59 +01:00
Jos de Jong
ed2cce4d17
fix: various security vulnerabilities (#3255)
* fix: disable parser functions in the CLI (security issue)

* fix: ensure `ObjectWrappingMap` doesn't allow deleting unsafe properties (security issue)

* fix: enable using methods and (safe) properties on plain arrays

* docs: update the "Less vulnerable expression parser" section in the docs

* chore: fix typos and linting issues

* chore: keep functions like `simplify` enabled in the CLI

* docs: update the security page

* fix: ensure `ObjectWrappingMap.keys` cannot list unsafe properties

* fix: when overwriting a rawArgs function with a non-rawArgs function it was still called with raw arguments

* docs: fix a typo
2024-08-27 16:42:46 +02:00
David Contreras
bcf0da46f0
feat: support multiple inputs in function map (#3228) 2024-08-22 13:35:21 +02:00
David Contreras
c8e4bbd573
fix: function map not always working with matrices (#3242)
* Removed maxArgumentCount in favor of applyCallback

* Making a pure _recurse function

* Added cbrt tests, removed unnecesary changes in functions.

* Fixed main bottleneck

* Restored back function before unintended change

* Fix format

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-08-01 15:54:20 +02:00
Jos de Jong
a1eec936fc
feat: export util functions for maps and improve documentation of scope (#3243)
* feat: export util functions `isMap`, `isPartitionedMap`, and `isObjectWrappingMap` and improve the documentation of `scope` (see #3150)

* chore: fix broken unit tests

* docs: refine the explanation about scopes
2024-08-01 10:57:23 +02:00
Jos de Jong
ab3461d484
feat: implement support for bigint (#3207, #2737) 2024-05-31 12:43:09 +02:00
David Contreras
eded7e1dc3
feat: nearly equal with relative and absolute tolerance (#3152)
* nearlyEqual with absolute and relative tolerances

* Format

* nearlyEqual for bigNumber

* Added skip for NaN

* Reduce diff a bit

* Issue with examples in jsdcos

* Updated all calls for nearlyEqual

* Fixed failing tests

* Changed epsilon to relTol, absTol

* Changed references to epsilon in docs and tests

* Added warning for config.epsilon

* Fix warning in zeta.test

* Added config test

* Added sinon to test console.warn

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-05-15 10:56:11 +02:00
Jos de Jong
f504ffe1d3 chore: update devDependencies (most notably eslint) 2024-02-22 16:27:24 +01:00
Jos de Jong
663bbea40d fix: linting issue 2024-02-21 12:23:05 +01:00
Jos de Jong
a7f84abe51 fix: PartitionedMap and ObjectWrappingMap missing a property
`Symbol.iterator`
2024-02-21 12:17:30 +01:00
Jos de Jong
5a4f60fdf6
Fix not being able to use and and or inside a function definition (#3150)
* chore: write unit tests using `and` and `or` inside a function definition (WIP)

* fix: #3143 fix scope issues in rawArgs functions by implementing a `PartitionedMap`

* fix: add more unit tests for `ObjectWrappingMap`

* fix: don't let `ObjectWrappingMap` and `PartitionedMap` extend `Map` (risk of having non-overwritten methods)

* docs: update docs about `rawArgs` functions
2024-02-08 09:53:21 +01:00
Jos de Jong
843a5fd550 chore: make the unit test more robust 2023-10-25 14:29:14 +02:00
Jos de Jong
0222ff7aa9 fix: function clone not throwing an error in case of an unsupported type like a function 2023-10-25 14:25:05 +02:00
Jos de Jong
d1c4a56a8e
Fix: #3073 escaping in strings (#3082)
* chore: refactor parsing strings to not rely on `JSON.parse`

* fix: #3073 function `format` not escaping control characters and double quotes in strings

* chore: add more unit tests
2023-10-25 13:37:53 +02:00
David Contreras
49c793ba5a
feat: Indexing with an array of booleans (#2994)
* Included math to syntax when missing

* Included solveODE

* renamed initialStep as firstStep

* Included tests for solveODE

* Test the full state instead of the final state

* Fixed issue with tolerance

* Indexing with an array of booleans

* Indexing with booleans and with empty

* Changed index embedded docs

* removed solveODE

* typos on tests

* included config.predictable

* Throws an error if the size doesn't match

* Included config predictable to get subset

* Can do replacement by broadcasting

* DenseMatrix set can broadcast first

* Added tests for broadcasted subset in the parser

* Faster cloning of deep arrays

* Included docs and better test coverage

* Test coverage for `subset`

* Removed config predictable from subset

* Removed config from index and sparseMatrix

* Redaction and typos

* Cleanup unnecesary changes

* fixed issue when there is no need to broadcast

* Inline ifs

* Included specific broadcasting test

* Reduced repetition

---------

Co-authored-by: David Contreras <david.contreras@guentner.com>
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-07-28 09:30:04 +02:00
Jos de Jong
6dcbc6b793 fix: security vulnerability in FunctionNode and SymbolNode allowing arbitrary code execution via math.evaluate 2023-07-24 12:33:28 +02:00
Chris Chudzicki
13a3d4c198
Linting: StandardJS for src/, test/; Prettier for types/ (#2544)
* setup linting with eslint-config-standard, prettier

* [autofix] npm run lint -- --fix with new setup

* [manual] fix types/ directory errors

* [manual] fix linting errors in test/ directory

* [manual] fix single linting error in src/

* revert ts-expect-error comment change

* error on .only in mocha tests

* fix test description typo

* move some short objects to single line

* add and gitignore eslintcache

* individually suppress ts any

* set --max-warnings to 0

* extract matrices to constants

* update ts-expect-error comments
2022-04-29 12:04:01 +02:00
Glen Whitney
ba3c58e984
fix(FunctionNode): Improve error message when a non-function is called (#2494)
* fix(FunctionNode): Improve error message when a non-function is called

  Also adds tests for as many different varieties of function calls
  and their associate messages when the entity being called is not
  a function as I could come up with.

  Resolves #2493.

* feat(format): Add a truncate option to limit result length.

  Also uses the new option in FunctionNode.js to limit the length of the value
  portion of its new error messages. (As requested in review)

* docs: Add 'truncate' option to the list in the exported version of 'format'
2022-03-25 16:09:33 +01:00
Jos de Jong
e8a50259e7 Remove redundant piece 0*? in regex (see #2363) 2021-12-29 13:29:39 +01:00
jhugman
e80995d52d
Add support for scopes with get and set methods (#2166)
* Add support for scopes with get and set methods

* Fix build for node v12

* Fixup cli and parser tests

* Add tests for simplify and evaluate

* Add example for a custom scope object

* Function calls need child scopes

* Transitionary step: Separate Safe and Scope Property calls

* Renamed identifiers in FunctionNode

* Evaluate with ObjectScopeWrapper

* Simplify tests passing

* Assume all scopes are map-like. Except parser

* Remove isMapLike check in customs.*SafeProperty() methods

* Change MapLike to Map

* Move keywords from an Object to a Set

* Move ScopeProperty functions in to scope.js

* Removed deprecation warning

* Rename scope.js to map.js

* Rename ScopeProperty to MapProperty

* Add tests and docs for map.js

* Put back the micro-optimization of function calls

* Use Map in the parser

* Called scope methods directly in cli.js

* Coercing of scope into a Map is done in Node, not evaluate

* Move createSubScope to its own file

* Fixup following self-review

* Add scope docs

* Final self-review changes

* Address reviewer comments

* Remove MapProperty witness marks

* Converted broken benchmark possibly lost in a rebase

* Use bare map as scope in benchmark

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2021-05-16 13:33:01 +02:00
Flaviu Tamas
a3360d316b
Improve performance of _findUnit (#2065)
* Add unit parser benchmark

* Add LRU to memoize function

* Memoize _findUnit

This fixes some performance issues in my heavily-unit-parsing app.
Another idea might be to do an index of reversed unit names, and search
in that, but this is much easier to implement and still should provide
an improvement in the majority of cases (since I'd imagine that most
users tend to prefer a few units at a time, depending on their
application).

* Optimize memoize function

This should be just a little bit faster than before by using Maps, which
have less overhead than javascript objects.
2020-12-24 09:10:53 +01:00
Jos de Jong
41c5e2fabe Merge branch 'develop' into v8
# Conflicts:
#	HISTORY.md
#	package-lock.json
#	package.json
#	src/expression/embeddedDocs/embeddedDocs.js
#	src/factoriesAny.js
#	src/function/special/erf.js
#	src/plain/number/probability.js
#	src/version.js
2020-11-02 11:59:12 +01:00
Jos de Jong
9fd958110f Publish v7.6.0 2020-11-02 10:17:09 +01:00
Jos de Jong
bc32467182 Add some more tests against possible Object pollution 2020-11-02 10:11:58 +01:00
Jos de Jong
68c6a91801 Update devDependencies 2020-11-02 09:33:11 +01:00
Jos de Jong
83e1963cee Merge branch 'develop' into v8
# Conflicts:
#	HISTORY.md
#	src/function/probability/pickRandom.js
#	test/unit-tests/function/probability/pickRandom.test.js
2020-10-18 10:14:32 +02:00
Jos de Jong
ecb80514e8 Fix object pollution vulnerability in math.config 2020-10-10 10:24:48 +02:00
Jos de Jong
6f00715754
Specify import require paths (continuation of #1941) (#1962)
* Add `.js` extension to source file imports

* Specify package `exports` in `package.json`

Specify package type as `commonjs` (It's good to be specific)

* Move all compiled scripts into `lib` directory

Remove ./number.js (You can use the compiled ones in `./lib/*`)

Tell node that the `esm` directory is type `module` and enable tree shaking.

Remove unused files from packages `files` property

* Allow importing of package.json

* Make library ESM first

* - Fix merge conflicts
- Refactor `bundleAny` into `defaultInstance.js` and `browserBundle.cjs`
- Refactor unit tests to be able to run with plain nodejs (no transpiling)
- Fix browser examples

* Fix browser and browserstack tests

* Fix running unit tests on Node 10 (which has no support for modules)

* Fix node.js examples (those are still commonjs)

* Remove the need for `browserBundle.cjs`

* Generate minified bundle only

* [Security] Bump node-fetch from 2.6.0 to 2.6.1 (#1963)

Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1. **This update includes a security fix.**
- [Release notes](https://github.com/bitinn/node-fetch/releases)
- [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/bitinn/node-fetch/compare/v2.6.0...v2.6.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

* Cleanup console.log

* Add integration tests to test the entry points (commonjs/esm, full/number only)

* Create backward compatibility error messages in the files moved/removed since v8

* Describe breaking changes in HISTORY.md

* Bump karma from 5.2.1 to 5.2.2 (#1965)

Bumps [karma](https://github.com/karma-runner/karma) from 5.2.1 to 5.2.2.
- [Release notes](https://github.com/karma-runner/karma/releases)
- [Changelog](https://github.com/karma-runner/karma/blob/master/CHANGELOG.md)
- [Commits](https://github.com/karma-runner/karma/compare/v5.2.1...v5.2.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

Co-authored-by: Lee Langley-Rees <lee@greenimp.co.uk>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-09-20 18:01:29 +02:00
jos
7b1cd7753e Fixed #1628: Cannot call methods on empty strings or numbers with value 0 2019-09-23 20:23:39 +02:00
Harry Sarson
b6a42c032d run standard --fix 2019-08-21 10:09:10 +01:00
jos
d8a4f3a00a Update to standard@13.0.2 2019-07-20 13:46:31 +02:00
jos
db4910bed4 Move all test related stuff in folder test 2019-06-05 11:45:02 +02:00