getHandlerForCommand(commandName) { if (isString(commandName) === false) { throw new InvalidCommandException(); } const handlerName = commandName.replace('Command', 'Handler'); if (has(this.handlers, handlerName) === false) { MissingHandlerException.forCommand(commandName); } return this.handlers[handlerName]; }
__addProperty(path, nameForError, value) { if (!value) { throw new Error(`${nameForError} must have a value. Can't be ${value}`); } else if (has(this, path)) { throw new Error(`Can't add ${nameForError} to outgoingMessage that already has ${nameForError}`); } set(this, path, value); return this; }
__removeProperty(path, nameForError) { if (!has(this, path)) { throw new Error(`Can't remove ${nameForError} from outgoingMessage that doesn't have any ${nameForError}`); } unset(this, path); return this; }
__setupServer() { if (this.settings.server && this.settings.port) { throw new Error( 'IncompatibleArgumentsError: Please specify only ' + 'one of port and server'); } if (this.settings.server) { this.server = this.settings.server; } else { const port = has(this, 'settings.port') ? this.settings.port : 3000; this.server = this.__listen(port); } this.__setupServersRequestListeners(); }
const collectionHasFields = fieldKeys => every(option => every(field => has(field)(option))(fieldKeys))
/** * Allows you to set a field that will be highlighted. The field is * added to the current list of fields. * * @param {string} field A field name. * @returns {Highlight} returns `this` so that calls can be chained */ field(field) { if (!isNil(field) && !has(this._fields, field)) { this._fields[field] = {}; } return this; }
/** * Internal helper function for determining the aggregation name. * * @returns {string} Aggregation name * @private */ _aggsName() { if (!isEmpty(this._name)) return this._name; if (has(this._aggsDef, 'field')) { return `agg_${this.aggType}_${this._aggsDef.field}`; } // At this point, it would be difficult to construct a unique // aggregation name. Error out. throw new Error('Aggregation name could not be determined'); }
checkForNestedForm(props) { forEach(props.section, (input) => { if (input.type === 'enum') { forEach(input.items, (item) => { if (has(item, 'items')) { this.setState({ hasNestedInput: true, inputWithNestedForm: input.target, section: item.items }); if (props.values[input.target] === item.value) { this.setState({ showNestedForm: true }); } else { this.setState({ showNestedForm: false }); } } }); } }); }
export function EasyComputedStyle(computed, base = Object.create(null)) { return new Proxy(base, { ownKeys(target) { return Reflect.ownKeys(styleProperties); }, has(target, key) { return has(styleProperties, key); }, get(target, key) { if (!has(styleProperties, key)) throw new Error(`Failed to get a style property: '${key}' is not a valid style property name.`); return computed.get(key); } }); }
export function parsePropertyValue(propertyName, rawValue) { if (!has(styleProperties, propertyName)) throw new Error(`Failed to parse a style property: '${propertyName}' is not a valid style property.`); let property = styleProperties[propertyName]; if (isUndefined(property.parsers)) throw new Error(`Failed to parse a style property: '${propertyName}' has no declared parser.`); if (rawValue === `inherit`) return StyleInherit.inherit; let styleValue = parseRawValue(rawValue, property.parsers); if (isUndefined(styleValue)) throw new Error(`Failed to parse a style property: '${rawValue}' is not a valid value for property '${propertyName}'.`); return styleValue; }
/** * * @private * @param {string} clauseType * @param {string|Object|Array} clauses */ _setSearchClause(clauseType, clauses) { // Replace the field. Don't care about previous contents if (Array.isArray(clauses)) this._queryOpts[clauseType] = clauses; else if (!has(this._queryOpts, clauseType)) { // Keep the single `like` without array. this._queryOpts[clauseType] = clauses; } else { // Wrap the single `like` in an array if (!Array.isArray(this._queryOpts[clauseType])) { this._queryOpts[clauseType] = [this._queryOpts[clauseType]]; } // Append to array this._queryOpts[clauseType].push(clauses); } }
function getDataFromConfigs(configs) { const data = {}; forEach(configs.sections, (section) => { forEach(section.items, (item) => { data[item.target] = item.value; if (has(item, 'items')) { forEach(item.items, (itemValue) => { data[itemValue.target] = itemValue.value; }); } }); }); if (configs.name === 'form.security.name' && includes(split(get(data, 'security.xframe.value'), ' '), 'ALLOW-FROM')) { const allowFromValue = split(get(data, 'security.xframe.value'), ' ')[0]; const allowFromValueNested = split(get(data, 'security.xframe.value'), ' ')[1]; data['security.xframe.value'] = allowFromValue; data['security.xframe.value.nested'] = allowFromValueNested; } return data; }
props.listContent.attributes.filter(attr => has(attr.params, 'target'))
/** * Override default `toJSON` to return DSL representation of the geo shape * class instance. * * @override * @returns {Object} returns an Object which maps to the elasticsearch query DSL */ toJSON() { if (!has(this._body, 'type') || !has(this._body, 'coordinates')) { throw new Error( 'For all types, both the inner `type` and `coordinates` fields are required.' ); } return this._body; }