1 | import { errorTransform } from '../../transform/utils/errorTransform.js';
|
2 | import { setSafeProperty } from '../../../utils/customs.js';
|
3 | export function assignFactory(_ref) {
|
4 | var {
|
5 | subset,
|
6 | matrix
|
7 | } = _ref;
|
8 |
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | return function assign(object, index, value) {
|
24 | try {
|
25 | if (Array.isArray(object)) {
|
26 |
|
27 | return matrix(object).subset(index, value).valueOf();
|
28 | } else if (object && typeof object.subset === 'function') {
|
29 |
|
30 | return object.subset(index, value);
|
31 | } else if (typeof object === 'string') {
|
32 |
|
33 | return subset(object, index, value);
|
34 | } else if (typeof object === 'object') {
|
35 | if (!index.isObjectProperty()) {
|
36 | throw TypeError('Cannot apply a numeric index as object property');
|
37 | }
|
38 |
|
39 | setSafeProperty(object, index.getObjectProperty(), value);
|
40 | return object;
|
41 | } else {
|
42 | throw new TypeError('Cannot apply index: unsupported type of object');
|
43 | }
|
44 | } catch (err) {
|
45 | throw errorTransform(err);
|
46 | }
|
47 | };
|
48 | } |
\ | No newline at end of file |