feat:node-modules
This commit is contained in:
40
node_modules/mathjs/lib/esm/expression/node/utils/access.js
generated
vendored
Normal file
40
node_modules/mathjs/lib/esm/expression/node/utils/access.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { errorTransform } from '../../transform/utils/errorTransform.js';
|
||||
import { getSafeProperty } from '../../../utils/customs.js';
|
||||
export function accessFactory(_ref) {
|
||||
var {
|
||||
subset
|
||||
} = _ref;
|
||||
/**
|
||||
* Retrieve part of an object:
|
||||
*
|
||||
* - Retrieve a property from an object
|
||||
* - Retrieve a part of a string
|
||||
* - Retrieve a matrix subset
|
||||
*
|
||||
* @param {Object | Array | Matrix | string} object
|
||||
* @param {Index} index
|
||||
* @return {Object | Array | Matrix | string} Returns the subset
|
||||
*/
|
||||
return function access(object, index) {
|
||||
try {
|
||||
if (Array.isArray(object)) {
|
||||
return subset(object, index);
|
||||
} else if (object && typeof object.subset === 'function') {
|
||||
// Matrix
|
||||
return object.subset(index);
|
||||
} else if (typeof object === 'string') {
|
||||
// TODO: move getStringSubset into a separate util file, use that
|
||||
return subset(object, index);
|
||||
} else if (typeof object === 'object') {
|
||||
if (!index.isObjectProperty()) {
|
||||
throw new TypeError('Cannot apply a numeric index as object property');
|
||||
}
|
||||
return getSafeProperty(object, index.getObjectProperty());
|
||||
} else {
|
||||
throw new TypeError('Cannot apply index: unsupported type of object');
|
||||
}
|
||||
} catch (err) {
|
||||
throw errorTransform(err);
|
||||
}
|
||||
};
|
||||
}
|
||||
51
node_modules/mathjs/lib/esm/expression/node/utils/assign.js
generated
vendored
Normal file
51
node_modules/mathjs/lib/esm/expression/node/utils/assign.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import { errorTransform } from '../../transform/utils/errorTransform.js';
|
||||
import { setSafeProperty } from '../../../utils/customs.js';
|
||||
export function assignFactory(_ref) {
|
||||
var {
|
||||
subset,
|
||||
matrix
|
||||
} = _ref;
|
||||
/**
|
||||
* Replace part of an object:
|
||||
*
|
||||
* - Assign a property to an object
|
||||
* - Replace a part of a string
|
||||
* - Replace a matrix subset
|
||||
*
|
||||
* @param {Object | Array | Matrix | string} object
|
||||
* @param {Index} index
|
||||
* @param {*} value
|
||||
* @return {Object | Array | Matrix | string} Returns the original object
|
||||
* except in case of a string
|
||||
*/
|
||||
// TODO: change assign to return the value instead of the object
|
||||
return function assign(object, index, value) {
|
||||
try {
|
||||
if (Array.isArray(object)) {
|
||||
var result = matrix(object).subset(index, value).valueOf();
|
||||
|
||||
// shallow copy all (updated) items into the original array
|
||||
result.forEach((item, index) => {
|
||||
object[index] = item;
|
||||
});
|
||||
return object;
|
||||
} else if (object && typeof object.subset === 'function') {
|
||||
// Matrix
|
||||
return object.subset(index, value);
|
||||
} else if (typeof object === 'string') {
|
||||
// TODO: move setStringSubset into a separate util file, use that
|
||||
return subset(object, index, value);
|
||||
} else if (typeof object === 'object') {
|
||||
if (!index.isObjectProperty()) {
|
||||
throw TypeError('Cannot apply a numeric index as object property');
|
||||
}
|
||||
setSafeProperty(object, index.getObjectProperty(), value);
|
||||
return object;
|
||||
} else {
|
||||
throw new TypeError('Cannot apply index: unsupported type of object');
|
||||
}
|
||||
} catch (err) {
|
||||
throw errorTransform(err);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user