feat:node-modules

This commit is contained in:
houjunxiang
2025-11-24 10:26:18 +08:00
parent 753766893b
commit 8a3e48d856
8825 changed files with 567399 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
import { typeOf } from '../../../utils/is.js';
/**
* Improve error messages for statistics functions. Errors are typically
* thrown in an internally used function like larger, causing the error
* not to mention the function (like max) which is actually used by the user.
*
* @param {Error} err
* @param {String} fnName
* @param {*} [value]
* @return {Error}
*/
export function improveErrorMessage(err, fnName, value) {
// TODO: add information with the index (also needs transform in expression parser)
var details;
if (String(err).includes('Unexpected type')) {
details = arguments.length > 2 ? ' (type: ' + typeOf(value) + ', value: ' + JSON.stringify(value) + ')' : ' (type: ' + err.data.actual + ')';
return new TypeError('Cannot calculate ' + fnName + ', unexpected type of argument' + details);
}
if (String(err).includes('complex numbers')) {
details = arguments.length > 2 ? ' (type: ' + typeOf(value) + ', value: ' + JSON.stringify(value) + ')' : '';
return new TypeError('Cannot calculate ' + fnName + ', no ordering relation is defined for complex numbers' + details);
}
return err;
}