manyfest 1.0.39 → 1.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -66,6 +66,24 @@ class ManyfestObjectAddressSetValue
|
|
|
66
66
|
// The "Name" of the Object contained too the left of the bracket
|
|
67
67
|
let tmpBoxedPropertyName = pAddress.substring(0, tmpBracketStartIndex).trim();
|
|
68
68
|
|
|
69
|
+
// The "Reference" to the property within it, either an array element or object property
|
|
70
|
+
let tmpBoxedPropertyReference = pAddress.substring(tmpBracketStartIndex+1, tmpBracketStopIndex).trim();
|
|
71
|
+
// Attempt to parse the reference as a number, which will be used as an array element
|
|
72
|
+
let tmpBoxedPropertyNumber = parseInt(tmpBoxedPropertyReference, 10);
|
|
73
|
+
let tmpIndexIsNumeric = !isNaN(tmpBoxedPropertyNumber);
|
|
74
|
+
|
|
75
|
+
if (pObject[tmpBoxedPropertyName] == null)
|
|
76
|
+
{
|
|
77
|
+
if (tmpIndexIsNumeric)
|
|
78
|
+
{
|
|
79
|
+
pObject[tmpBoxedPropertyName] = [];
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
{
|
|
83
|
+
pObject[tmpBoxedPropertyName] = {};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
69
87
|
// If the subproperty doesn't test as a proper Object, none of the rest of this is possible.
|
|
70
88
|
// This is a rare case where Arrays testing as Objects is useful
|
|
71
89
|
if (typeof(pObject[tmpBoxedPropertyName]) !== 'object')
|
|
@@ -73,11 +91,6 @@ class ManyfestObjectAddressSetValue
|
|
|
73
91
|
return false;
|
|
74
92
|
}
|
|
75
93
|
|
|
76
|
-
// The "Reference" to the property within it, either an array element or object property
|
|
77
|
-
let tmpBoxedPropertyReference = pAddress.substring(tmpBracketStartIndex+1, tmpBracketStopIndex).trim();
|
|
78
|
-
// Attempt to parse the reference as a number, which will be used as an array element
|
|
79
|
-
let tmpBoxedPropertyNumber = parseInt(tmpBoxedPropertyReference, 10);
|
|
80
|
-
|
|
81
94
|
// Guard: If the referrant is a number and the boxed property is not an array, or vice versa, return undefined.
|
|
82
95
|
// This seems confusing to me at first read, so explaination:
|
|
83
96
|
// Is the Boxed Object an Array? TRUE
|
|
@@ -105,6 +118,7 @@ class ManyfestObjectAddressSetValue
|
|
|
105
118
|
}
|
|
106
119
|
|
|
107
120
|
// Return the value in the property
|
|
121
|
+
//TODO: For cases where we have chained [][] properties, this needs to recurse somehow
|
|
108
122
|
pObject[tmpBoxedPropertyName][tmpBoxedPropertyReference] = pValue;
|
|
109
123
|
return true;
|
|
110
124
|
}
|
|
@@ -156,6 +170,20 @@ class ManyfestObjectAddressSetValue
|
|
|
156
170
|
let tmpBoxedPropertyReference = tmpSubObjectName.substring(tmpBracketStartIndex+1, tmpBracketStopIndex).trim();
|
|
157
171
|
|
|
158
172
|
let tmpBoxedPropertyNumber = parseInt(tmpBoxedPropertyReference, 10);
|
|
173
|
+
let tmpIndexIsNumeric = !isNaN(tmpBoxedPropertyNumber);
|
|
174
|
+
|
|
175
|
+
//if (typeof(pObject[tmpBoxedPropertyName]) !== 'object')
|
|
176
|
+
if (pObject[tmpBoxedPropertyName] == null)
|
|
177
|
+
{
|
|
178
|
+
if (tmpIndexIsNumeric)
|
|
179
|
+
{
|
|
180
|
+
pObject[tmpBoxedPropertyName] = [];
|
|
181
|
+
}
|
|
182
|
+
else
|
|
183
|
+
{
|
|
184
|
+
pObject[tmpBoxedPropertyName] = {};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
159
187
|
|
|
160
188
|
// Guard: If the referrant is a number and the boxed property is not an array, or vice versa, return undefined.
|
|
161
189
|
// This seems confusing to me at first read, so explaination:
|
|
@@ -171,7 +199,7 @@ class ManyfestObjectAddressSetValue
|
|
|
171
199
|
// BUT
|
|
172
200
|
// StudentData.Sections.Algebra.Students is an array, so the ["JaneDoe"].Grade is not possible to access
|
|
173
201
|
// TODO: Should this be an error or something? Should we keep a log of failures like this?
|
|
174
|
-
if (Array.isArray(pObject[tmpBoxedPropertyName])
|
|
202
|
+
if (Array.isArray(pObject[tmpBoxedPropertyName]) != tmpIndexIsNumeric)
|
|
175
203
|
{
|
|
176
204
|
return false;
|
|
177
205
|
}
|
|
@@ -165,6 +165,52 @@ suite
|
|
|
165
165
|
fTestComplete();
|
|
166
166
|
}
|
|
167
167
|
);
|
|
168
|
+
test
|
|
169
|
+
(
|
|
170
|
+
'Indexed subobject are settable',
|
|
171
|
+
(fTestComplete)=>
|
|
172
|
+
{
|
|
173
|
+
let _Manyfest = new libManyfest({});
|
|
174
|
+
let _SimpleObject = {};
|
|
175
|
+
_Manyfest.setValueAtAddress(_SimpleObject, `_Object['SubObject'].Property`, '123');
|
|
176
|
+
Expect(_Manyfest.getValueAtAddress(_SimpleObject, `_Object.SubObject.Property`))
|
|
177
|
+
.to.equal('123');
|
|
178
|
+
Expect(_SimpleObject._Object.SubObject.Property)
|
|
179
|
+
.to.equal('123');
|
|
180
|
+
fTestComplete();
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
test
|
|
184
|
+
(
|
|
185
|
+
'Indexed subobject are settable unquoted',
|
|
186
|
+
(fTestComplete)=>
|
|
187
|
+
{
|
|
188
|
+
let _Manyfest = new libManyfest({});
|
|
189
|
+
let _SimpleObject = {};
|
|
190
|
+
_Manyfest.setValueAtAddress(_SimpleObject, `_Object[SubObject].Property`, '123');
|
|
191
|
+
Expect(_Manyfest.getValueAtAddress(_SimpleObject, `_Object.SubObject.Property`))
|
|
192
|
+
.to.equal('123');
|
|
193
|
+
Expect(_SimpleObject._Object.SubObject.Property)
|
|
194
|
+
.to.equal('123');
|
|
195
|
+
fTestComplete();
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
//TODO: known broken case for multiple bracketed properties
|
|
199
|
+
test.skip
|
|
200
|
+
(
|
|
201
|
+
'Indexed subobject are settable double brackets',
|
|
202
|
+
(fTestComplete)=>
|
|
203
|
+
{
|
|
204
|
+
let _Manyfest = new libManyfest({});
|
|
205
|
+
let _SimpleObject = {};
|
|
206
|
+
_Manyfest.setValueAtAddress(_SimpleObject, `_Object[SubObject]['Property']`, '123');
|
|
207
|
+
Expect(_Manyfest.getValueAtAddress(_SimpleObject, `_Object.SubObject.Property`))
|
|
208
|
+
.to.equal('123');
|
|
209
|
+
Expect(_SimpleObject._Object.SubObject.Property)
|
|
210
|
+
.to.equal('123');
|
|
211
|
+
fTestComplete();
|
|
212
|
+
}
|
|
213
|
+
);
|
|
168
214
|
}
|
|
169
215
|
);
|
|
170
216
|
}
|