MCPcopy Create free account
hub / github.com/FlashpointProject/launcher / prop

Method prop

src/shared/utils/ObjectParser.ts:169–195  ·  view source on GitHub ↗
(label: L, funcOrOptional?: ((prop: P[L]) => void) | boolean, optional?: boolean)

Source from the content-addressed store, hash-verified

167 }
168
169 prop<L extends keyof P>(label: L, funcOrOptional?: ((prop: P[L]) => void) | boolean, optional?: boolean): IObjectParserProp<P[L]> {
170 // Figure out which argument is used for what purpose
171 let func: ((prop: P[L]) => void)|undefined; // ("func" from parameter)
172 let isOptional: boolean; // ("optional" from parameter)
173 if (typeof funcOrOptional === 'function') {
174 func = funcOrOptional;
175 isOptional = !!optional;
176 } else { isOptional = !!funcOrOptional; }
177
178 // Check if property exists
179 if (this._property !== null &&
180 this._property !== undefined &&
181 Object.prototype.hasOwnProperty.call(this._property, label)) {
182 // Property callback
183 if (func) { func(this._property[label]); }
184 // Create and return wrapper (around property)
185 const prop = this._property && this._property[label];
186 return new ObjectParserProp(prop, this._context, createStack(this._stack, label)) as any;
187 } else {
188 // Error callback
189 if (!isOptional) {
190 this._context.onError(new ObjectParserError(this._stack, `Property "${label as any}" was not found.`));
191 }
192 // Create and return wrapper (around nothing)
193 return new ObjectParserPropNone();
194 }
195 }
196}
197
198/**

Callers

nothing calls this directly

Calls 2

createStackFunction · 0.85
onErrorMethod · 0.45

Tested by

no test coverage detected