withProps(({ facilities }) => ({ // compact removes any falseisch values from the array // (bike parks are included in the hub but return null from graphQL carParks) realtime: every(compact(facilities), 'realtime'), maxCapacity: sumBy(compact(facilities), 'maxCapacity'), spacesAvailable: sumBy(compact(facilities), 'spacesAvailable'), }))(ParkAndRidePopup),
core.on('user-dn', async action => { const roomsFollowing = store.getRelatedRooms().filter(rel => rel.role === 'follower').map(rel => rel.id); const places = action.user.params && action.user.params.places ? action.user.params.places : []; const rooms = places.filter(it => it.type !== 'state').map(it => it.id); const states = places.filter(it => it.type === 'state').map(it => it.id); const roomsData = {}; try { const results = await Promise.all(rooms.map(id => query('getRooms', { ref: id }))); for (let i = 0, l = results.length; i < l; i++) { if (results[i] && results[i].length) { const room = results[i][0]; if (room) { roomsData[room.id] = room; } } } } catch (e) { // ignore } const parentRooms = []; for (let i = 0, l = rooms.length; i < l; i++) { const room = roomsData[rooms[i]]; if (room && room.guides) { if (room.guides.alsoAutoFollow) { parentRooms.push(room.guides.alsoAutoFollow); } if (room.guides.alsoAutoFollowList) { Array.prototype.push.apply(parentRooms, room.guides.alsoAutoFollowList); } } } const roomsToProcess = [ ...rooms, ...parentRooms ]; const statesToProcess = states.length ? parentRooms.map(room => states[0] + '-in-' + room) : []; const roomsSaved = [ ...roomsToProcess, ...statesToProcess ]; const roomsShouldFollow = compact(difference(roomsSaved, roomsFollowing)); const roomsShouldLeave = compact(difference(roomsFollowing, roomsSaved)); try { await Promise.all([].concat( roomsShouldFollow.map(room => dispatch('join', { to: room })), roomsShouldLeave.map(room => dispatch('part', { to: room })) )); } catch (e) { // ignore } });
/** * @private */ function highlightNode( node, term, wrapperNode ) { var nodes = [], found = false, pos, leftText, midText, remainingText; if ( node.nodeName === '#text' ) { remainingText = node.nodeValue; } while ( true ) { pos = remainingText.toLowerCase().indexOf( term.toLowerCase() ); if ( !remainingText || pos === -1 ) { break; } found = true; leftText = remainingText.slice( 0, pos ); nodes.push( document.createTextNode( leftText ) ); midText = remainingText.slice( pos, pos + term.length ); nodes.push( wrap( midText, wrapperNode ) ); remainingText = remainingText.slice( pos + term.length ); } nodes.push( document.createTextNode( remainingText ) ); nodes = compact( nodes ); if ( nodes.length && found ) { replaceChildNodesWithGroup( node.parentElement, nodes, node ); } }
function validate( { users, fields, domainSuffix } ) { var errors; users = filter( { users, fields } ); users = users.map( function( user ) { return mapValues( user, function( field, key ) { var error = null; if ( isEmpty( field.value ) ) { error = i18n.translate( 'This field is required.' ); } else if ( includes( [ 'firstName', 'lastName' ], key ) ) { if ( field.value.length > 60 ) { error = i18n.translate( 'This field can\'t be longer than 60 characters.' ); } } else if ( 'email' === key ) { if ( /[^[0-9a-z_'.-]/i.test( field.value ) ) { error = i18n.translate( 'Only number, letters, dashes, underscores, apostrophes and periods are allowed.' ); } else if ( ! emailValidator.validate( `${ field.value }@${ domainSuffix }` ) ) { error = i18n.translate( 'Please provide a valid email address.' ); } } return Object.assign( {}, field, { error: error } ); } ); } ); errors = compact( flatten( users.map( function( user ) { return values( user ).map( property( 'error' ) ); } ) ) ); return { errors, users }; }
const mapStateToProps = function(state, ownProps) { const formId = ownProps.formId // get saved & server provided errors, concat them together let errors = null if (state.rform[formId] && state.rform[formId].errors) { errors = state.rform[formId].errors[ownProps.attribute] || [] } errors = compact(concat(errors, ownProps.serverErrors)) let value = ownProps.defaultValue const attrs = state.rform[ownProps.formId] if ( attrs && ownProps.submodel && attrs[ownProps.submodel] && !isNil(attrs[ownProps.submodel][ownProps.attribute]) ) { value = Number(attrs[ownProps.submodel][ownProps.attribute]) } else if (attrs && !isNil(attrs[ownProps.attribute])) { value = Number(attrs[ownProps.attribute]) } return { errors, value, } }
return function(reviewers) { body = body.trim(); reviewers = uniq(reviewers); if (body.match(regexp)) { var args = compact(body.split(' ')).reverse().slice(0, -1).reverse(); var newStatus = args.shift(); var updatedReviews = extractMentions(args.join(' ')).filter(function(reviewer) { return reviewers.indexOf(reviewer) !== -1; }); updatedReviews.forEach(function(reviewer) { if (newStatus.trim() === ':-1:') { denodeify(client.repos.createStatus)({ user: repo, repo: name, sha: sha, state: 'failure', description: '@' + author + ' rejected the pull-request for @' + reviewer, context: 'Review my code - @' + reviewer }); } if (newStatus.trim() === ':+1:') { denodeify(client.repos.createStatus)({ user: repo, repo: name, sha: sha, state: 'success', description: '@' + author + ' accepted the pull-request for @' + reviewer, context: 'Review my code - @' + reviewer }); } }); } };
/** * Utility method used to create new wrappers with a mapping function that returns an array of * nodes in response to a single node wrapper. The returned wrapper is a single wrapper around * all of the mapped nodes flattened (and de-duplicated). * * @param {Function} fn * @returns {ReactWrapper} */ flatMap(fn) { const nodes = this.getNodesInternal().map((n, i) => fn.call(this, this.wrap(n), i)); const flattened = flatten(nodes, true); const uniques = unique(flattened); const compacted = compact(uniques); return this.wrap(compacted); }
}, (err, result) => { t.equal(err, null) t.equal(nock.activeMocks().length, 0, 'no mocks left') t.equal(compact(map(result, 'graticule')).length, 5) t.equal(result.length, 5) t.end() })
return lookupPaths.map(function(lookupPath) { var blueprints = dir(lookupPath); var packagePath = path.join(lookupPath, '../package.json'); var source; if (existsSync(packagePath)) { source = require(packagePath).name; } else { source = path.basename(path.join(lookupPath, '..')); } blueprints = blueprints.map(function(blueprintPath) { var blueprint = Blueprint.load(blueprintPath); var name; if (blueprint) { name = blueprint.name; blueprint.overridden = includes(seen, name); seen.push(name); return blueprint; } return; }); return { source: source, blueprints: compact(blueprints) }; });
}, (err, result) => { t.equal(err, null, 'no error') t.equal(nock.activeMocks().length, 0, 'no mocks left') t.equal(result.length, 3, '3 total results') t.equal(compact(map(result, 'graticule')).length, 3, 'has 3 graticule results (fri/sat/sun)') t.end() })
getSites: function( sites, pluginSlug ) { var plugin, plugins = this.getPlugins( sites ), pluginSites; if ( ! plugins ) { return; } plugins = plugins.filter( _filters.isEqual.bind( this, pluginSlug ) ); plugin = plugins.pop(); if ( ! plugin ) { return null; } pluginSites = uniq( compact( plugin.sites.map( function( site ) { // we create a copy of the site to avoid any possible modification down the line affecting the main list let pluginSite = site.jetpack ? new JetpackSite( sitesList.getSite( site.ID ) ) : new Site( sitesList.getSite( site.ID ) ); pluginSite.plugin = site.plugin; if ( site.visible ) { return pluginSite; } } ) ) ); return pluginSites.sort( function( first, second ) { return first.title.toLowerCase() > second.title.toLowerCase() ? 1 : -1; } ); },
}, (err, result) => { t.equal(err, null) t.equal(nock.activeMocks().length, 0, 'no mocks left') t.equal(result.length, 4, '4 total results') t.equal(compact(map(result, 'graticule')).length, 4, 'has 4 graticule results (fri/sat/sun/mon)') t.end() })
async function fetchThreadDetail ({ jar, senderID, messageCount, messageLimit = 7500, before = null }) { const messageThread = await handleFetch({ jar, senderID, messageCount, messageLimit, before }) .then(async (json) => { const messageThread = json.o0.data.message_thread if (!messageThread.messages.page_info) { throw new Error('No page_info.') } return messageThread }) .catch((err) => { console.error(err) messageLimit = messageLimit / 2 if (messageLimit > 1000) { return handleFetch({ jar, senderID, messageCount, messageLimit, before }) } else { throw new Error('Too many error on fetch.') } }) const messages = _compact(formatMessagesGraphQLResponse(messageThread)) messageCount = messageCount - messages.length if (messageThread.messages.page_info.has_previous_page && messages[0] && messageCount) { return (await fetchThreadDetail({ jar, senderID, messageCount, messageLimit, before: messages[0].timestamp })).concat(messages) } else { return messages } }
const mjmlElementParser = elem => { if (!elem) { throw new NullElementError('Null element found in mjmlElementParser') } const tagName = elem.tagName.toLowerCase() const attributes = dom.getAttributes(elem) const element = { tagName, attributes } if (!MJMLElements[tagName]) { warning(false, `Unregistered element: ${tagName}, skipping it`) return } if (endingTags.indexOf(tagName) !== -1) { const $ = dom.parseXML(elem) element.content = $(tagName).html().trim() } else { const children = dom.getChildren(elem) element.children = children ? compact(filter(children, child => child.tagName).map(mjmlElementParser)) : [] } return element }
constructor(config) { const fieldsetId = uniqueId(); const addBtnId = uniqueId(); const selectId = uniqueId(); const editorId = uniqueId(); const items = Array.isArray(config.items) ? config.items : []; const fieldsetItems = items.reduce((acc, item) => [...acc, ...[ config.removeButton, { block: 'label', labelText: item.label, rightMark: config.labelRightMark }, { block: 'text', value: item.value || '', name: item.name, textAlign: config.newItemInputTextAlign } ]], []); const finalConfig = Object.assign({}, config, { items: [{ block: 'fieldset', id: fieldsetId, label: config.itemLabel, labelWidth: config.itemLabel ? 3 : 0, layout: items.map(() => ({ count: 3, width: [1, 8, 3] })), items: fieldsetItems }, config.comment, { block: 'actions', id: editorId, items: [ Object.assign(config.actions.label, { cls: config.actions.label.cls || 'col-sm-3' }), Object.assign(config.actions.select, { cls: config.actions.select.cls || 'col-sm-7', id: selectId }), Object.assign(config.actions.addButton, { cls: config.actions.addButton.cls || 'col-sm-2 btn-default', id: addBtnId }) ] }] }); finalConfig.items = compact(finalConfig.items); super(finalConfig); this.maxLength = config.maxLength; this.currentLength = items.length; this.editor = this.getItemById(editorId); this.addBtn = this.editor.getItemById(addBtnId); this.fieldset = this.getItemById(fieldsetId); this.select = this.editor.getItemById(selectId); }
// * Grbl v0.9 // [G38.2 G54 G17 G21 G91 G94 M0 M5 M9 T0 F20. S0.] // * Grbl v1.1 // [GC:G0 G54 G17 G21 G90 G94 M0 M5 M9 T0 S0.0 F500.0] static parse(line) { const r = line.match(/^\[(?:GC:)?((?:[a-zA-Z][0-9]+(?:\.[0-9]*)?\s*)+)\]$/); if (!r) { return null; } const payload = {}; const words = _compact(r[1].split(' ')) .map((word) => { return _trim(word); }); for (let i = 0; i < words.length; ++i) { const word = words[i]; // Gx, Mx if (word.indexOf('G') === 0 || word.indexOf('M') === 0) { const r = _find(GRBL_MODAL_GROUPS, (group) => { return _includes(group.modes, word); }); if (!r) { continue; } const prevWord = _get(payload, 'modal.' + r.group, ''); if (prevWord) { _set(payload, 'modal.' + r.group, ensureArray(prevWord).concat(word)); } else { _set(payload, 'modal.' + r.group, word); } continue; } // T: tool number if (word.indexOf('T') === 0) { _set(payload, 'tool', word.substring(1)); continue; } // F: feed rate if (word.indexOf('F') === 0) { _set(payload, 'feedrate', word.substring(1)); continue; } // S: spindle speed if (word.indexOf('S') === 0) { _set(payload, 'spindle', word.substring(1)); continue; } } return { type: GrblLineParserResultParserState, payload: payload }; }
function getErrors( field, value, cardDetails ) { return compact( field.rules.map( function( rule ) { var validator = getValidator( rule ); if ( ! validator.isValid( value, cardDetails ) ) { return validator.error( field.description ); } } ) ); }
export function inferDisplayUrl (final_urls, path_1, path_2) { const domain = finalUrlsDomain(final_urls) if (!domain) return null const url = join(compact([domain, path_1, path_2]), '/') return url.replace(/\/$/g, '') }
getScopeUrl () { const {company, workspace, folder} = this.context.params return '/' + join(compact([ `c/${company}`, workspace && `w/${workspace}`, folder && `f/${folder}` ]), '/') }
getForProcess: formValues => { const { name, path, ...rest } = formValues; const argz = processArguments(rest, ARGUMENTS, true, argumentsOrder); return { cli: CLI_NAME, name, cliName: CLI_INSTALL_NAME, path, argz: compact([name, ...argz]) }; }
const parseHead = head => { each(compact(filter(dom.getChildren(head), child => child.tagName)), (element) => { const handler = MJMLHeadElements[element.tagName.toLowerCase()] if (handler) { handler(element, { setMjCssClasses, setMjDefaultAttributes }) } else { warning(false, `No handler found for: ${element.tagName}, in mj-head, skipping it`) } }) }
module.exports = function(env) { function matchFilter(task) { if(config.tasks[task]) { if(task === 'js') { task = env === 'production' ? 'webpack:production' : false } return task } } function exists(value) { return !!value } return { assetTasks: compact(assetTasks.map(matchFilter).filter(exists)), codeTasks: compact(codeTasks.map(matchFilter).filter(exists)) } }
const createProcessTiles = (workers) => function* processTiles(action) { const files = action.payload; const buffers = yield files.map(file => call(readFile, file)); let tiles = yield buffers.map(buffer => call(processTile, workers, buffer)); // Remove any null's from errors tiles = compact(tiles); yield put(actions.addTiles(tiles)); };
.then(r => { tree.unset(getDeepCursor(tree, compact([ 'user', ['companies', company], workspace && ['workspaces', workspace], folder && ['folders', folder], ['orders', order] ]))) tree.commit() return r })
export function debugInst(inst, indentLength = 2) { if (typeof inst === 'string' || typeof inst === 'number') return escape(inst); if (!inst) return ''; if (inst._stringText) { return inst._stringText; } if (!inst.getPublicInstance) { const internal = internalInstance(inst); return debugInst(internal, indentLength); } const publicInst = inst.getPublicInstance(); if (typeof publicInst === 'string' || typeof publicInst === 'number') return escape(publicInst); if (!publicInst && !inst._renderedComponent) return ''; // do stuff with publicInst const currentElement = inst._currentElement; const type = typeName(currentElement); const props = propsString(currentElement); const children = []; if (isDOMComponent(publicInst)) { const renderedChildren = renderedChildrenOfInst(inst); if (!renderedChildren) { children.push(...childrenOfNode(currentElement)); } else { children.push(...objectValues(renderedChildren)); } } else if ( !REACT013 && isElement(currentElement) && typeof currentElement.type === 'function' ) { children.push(inst._renderedComponent); } else if ( REACT013 && isCompositeComponent(publicInst) ) { children.push(inst._renderedComponent); } const childrenStrs = compact(children.map(n => debugInst(n, indentLength))); const beforeProps = props ? ' ' : ''; const nodeClose = childrenStrs.length ? `</${type}>` : '/>'; const afterProps = childrenStrs.length ? '>' : ' '; const childrenIndented = childrenStrs.length ? `\n${childrenStrs.map(x => indent(indentLength + 2, x)).join('\n')}\n` : ''; return `<${type}${beforeProps}${props}${afterProps}${childrenIndented}${nodeClose}`; }
exports.titlecase = function (str) { if (str && str.toString) str = str.toString(); if (typeof str !== 'string' || !str.length) return ''; str = str.replace(/([a-z])([A-Z])/g, '$1 $2'); var parts = str.split(/\s|_|\-/); for (var i = 0; i < parts.length; i++) { if (parts[i] && !/^[A-Z0-9]+$/.test(parts[i])) { parts[i] = exports.upcase(parts[i]); } } return compact(parts).join(' '); };
handler: ($, { defaultAttributes, cssClasses }) => { each(compact(filter($.children, child => child.tagName)), elem => { const tagName = elem.tagName.toLowerCase() const attributes = elem.attribs if (tagName === 'mj-class') { return cssClasses[attributes.name] = omit(attributes, ['name']) } defaultAttributes[tagName] = attributes }) }
const buildTree = createTask(function builder (attributes, levels, mount = false) { function extend (attr) { attr = assign({}, attr) for (let i = levels.length - 1; i >= 0; i--) { const {id: level, mount} = levels[i] const levelInfo = mount(attr) if (levelInfo) { attr[level] = levelInfo } else { return null } } return attr } if (isEmpty(levels)) { return attributes } if (mount) { attributes = compact(map(attributes, extend)) } const {id: level, openByDefault} = head(levels) const grouped = groupBy(attributes, `${level}.id`) const innerLevel = tail(levels) const format = (items, id) => buildTree(items, innerLevel) .then(list => { const sample = head(items) grouped[id] = { id, shared: get(sample, [level, 'shared']), name: get(sample, [level, 'name']), ids: flatten(map(list, ids)), openByDefault, list: list } }) return Promise.all(map(grouped, format)) .then(() => orderBy( grouped, ['shared', 'name'], ['desc', 'asc'] )) })
module.exports = function (env) { function matchFilter(task) { if (config.tasks[task]) { if (task === 'ftl' && env === 'production') { task = 'copyftl'; } if (task === 'scripts') { task = env === 'production' ? 'uglify' : 'scripts'; } return task; } } function exists(value) { return !!value; } return { assetTasks: compact(assetTasks.map(matchFilter).filter(exists)), codeTasks: compact(codeTasks.map(matchFilter).filter(exists)) }; };
(expressionInfo: InstructionOrExpressionInformation) => { update( tree, compact(expressionInfo.fullGroupName.split(GROUP_DELIMITER)), groupInfo => { const existingGroupInfo = groupInfo || {}; return { ...existingGroupInfo, [expressionInfo.displayedName]: expressionInfo, }; } ); }