MCPcopy
hub / github.com/OpenBMB/AgentVerse / GetValue

Function GetValue

ui/src/phaser3-rex-plugins/plugins/utils/object/GetValue.js:23–55  ·  view source on GitHub ↗
(source, key, defaultValue)

Source from the content-addressed store, hash-verified

21 * @return {*} The value of the requested key.
22 */
23var GetValue = function (source, key, defaultValue) {
24 if (!source || typeof source === 'number') {
25 return defaultValue;
26 }
27 else if (source.hasOwnProperty(key)) {
28 return source[key];
29 }
30 else if (key.indexOf('.') !== -1) {
31 var keys = key.split('.');
32 var parent = source;
33 var value = defaultValue;
34
35 // Use for loop here so we can break early
36 for (var i = 0; i < keys.length; i++) {
37 if (parent.hasOwnProperty(keys[i])) {
38 // Yes it has a key property, let's carry on down
39 value = parent[keys[i]];
40
41 parent = parent[keys[i]];
42 }
43 else {
44 // Can't go any further, so reset to default
45 value = defaultValue;
46 break;
47 }
48 }
49
50 return value;
51 }
52 else {
53 return defaultValue;
54 }
55};
56
57export default GetValue;

Callers 15

constructorMethod · 0.85
constructorMethod · 0.85
constructorMethod · 0.85
constructorMethod · 0.85
constructorMethod · 0.85
constructorMethod · 0.85
constructorMethod · 0.85
constructorMethod · 0.85
AddPageFunction · 0.85
constructorMethod · 0.85
CreateContentFunction · 0.85
constructorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected