How to use array-find - 10 common examples

To help you get started, we’ve selected a few array-find examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Qiuyaxian / lm-ui / lm-angular / src / components / popup-picker / filters.ts View on Github external
let rs = map(name, (one, index) => {
    let parent: any = ''
    if (index === 2) {
      // 可能存在区名一样的情况,比如南山区
      parent = find(list, item => {
        return item.name === name[1]
      }) || { value: '__' } 

      if (specialMap[name[0]]) {
        parent = {
          value: specialMap[name[0]]
        }
      }
      return find(list, item => {
        return item.name === one && item.parent === parent.value
      })
    } else {
      if (index === 1 && specialMap[name[0]]) {
        return {
          value: specialMap[name[0]]
        }
github u-wave / web / src / utils / parseChatMarkup.js View on Github external
return tokenize(message).map(token => {
    switch (token.type) {
    case 'italic':
      return { type: 'italic', content: parse(token.text, opts) };
    case 'bold':
      return { type: 'bold', content: parse(token.text, opts) };
    case 'code':
      return { type: 'code', content: [ token.text ] };
    case 'strike':
      return { type: 'strike', content: parse(token.text, opts) };
    case 'mention':
      const mention = users && find(users, user => user.username.toLowerCase() === token.text.toLowerCase());
      return mention
        ? { type: 'mention', user: mention }
        : token.raw;
    case 'link':
      return { type: 'link', text: token.text, href: token.text };
    default:
      return token.text;
    }
  });
}
github TankerHQ / sdk-js / packages / core / src / Groups / Manager.js View on Github external
groupsIds.forEach(groupId => {
      const resultFromCache = find(cacheResults, result => utils.equalArray(result.groupId, groupId));
      if (!resultFromCache) {
        missingGroupIds.push(groupId);
      }
    });
    return {
github TankerHQ / sdk-js / packages / core / src / Groups / ManagerHelper.js View on Github external
export function assertExpectedGroups(groups: Array, expectedGroupIds: Array) {
  const missingGroupIds = [];
  for (const groupId of expectedGroupIds) {
    const fetchedGroup = find(groups, group => utils.equalArray(group.groupId, groupId));
    if (!fetchedGroup) {
      missingGroupIds.push(utils.toBase64(groupId));
    }
  }
  if (missingGroupIds.length > 0) {
    const message = `The following groups do not exist on the trustchain: "${missingGroupIds.join('", "')}"`;
    throw new InvalidArgument(message);
  }
}
github Qiuyaxian / lm-ui / lm-angular / src / filters / value2name / value2name.ts View on Github external
let rs = map(value, (one, index) => {
    if (list.length && Object.prototype.toString.call(list[0]) === '[object Array]') {
      return find(list[index], item => {
        return item.value === one
      })
    } else {
      return find(list, item => {
        return item.value === one
      })
    }
  })
  rs = rs.filter(one => {
github u-wave / web / src / components / PanelSwitcher / Group.js View on Github external
const PanelGroup = ({ children, className, selected }) => {
  const view = find(children, child => child.props.name === selected);
  return (
    <div>
      {view}
    </div>
  );
};
github u-wave / web / src / actions / ChatActionCreators.js View on Github external
return (dispatch, getState) => {
    const settings = settingsSelector(getState());
    const currentUser = currentUserSelector(getState());
    const users = userListSelector(getState());
    const sender = find(users, user => user._id === message.userID);
    const mentions = [
      ...users.map(user => user.username),
      ...getAvailableGroupMentions(sender)
    ];

    if (isMuted(getState(), message.userID)) {
      return;
    }

    const parsed = parseChatMarkup(message.text, { mentions });
    resolveMentions(parsed, getState());

    const isMention = currentUser ? hasMention(parsed, currentUser._id) : false;

    dispatch({
      type: RECEIVE_MESSAGE,
github TankerHQ / sdk-js / packages / core / src / Users / Verify.js View on Github external
export function verifyDeviceRevocation(entry: DeviceRevocationEntry, authorUser: User) {
  const authorDevice: Device = find(authorUser.devices, d => utils.equalArray(d.deviceId, entry.author));

  if (!tcrypto.verifySignature(entry.hash, entry.signature, authorDevice.devicePublicSignatureKey))
    throw new InvalidBlockError('invalid_signature', 'signature is invalid', { entry, authorUser });

  const revokedDevice = find(authorUser.devices, d => utils.equalArray(d.deviceId, entry.device_id));
  if (!revokedDevice)
    throw new InvalidBlockError('invalid_revoked_device', 'can\'t find target of device revocation block', { entry });
  if (revokedDevice.revoked)
    throw new InvalidBlockError('device_already_revoked', 'target of device_revocation block is already revoked', { entry, revokedDevice });

  if (entry.nature === NATURE.device_revocation_v1) {
    if (authorUser.userPublicKeys.length !== 0)
      throw new InvalidBlockError('invalid_revocation_version', 'cannot use a device revocation v1 if the target has a user key', { entry, authorUser });
  } else {
    const newKeys = entry.user_keys;
    if (!newKeys)
github Qiuyaxian / lm-ui / lm-angular / src / components / popup-picker / filters.ts View on Github external
if (specialMap[name[0]]) {
        parent = {
          value: specialMap[name[0]]
        }
      }
      return find(list, item => {
        return item.name === one && item.parent === parent.value
      })
    } else {
      if (index === 1 && specialMap[name[0]]) {
        return {
          value: specialMap[name[0]]
        }
      }
      return find(list, item => {
        return item.name === one
      })
    }
  })
github Qiuyaxian / lm-ui / lm-angular / src / filters / value2name / value2name.ts View on Github external
let rs = map(value, (one, index) => {
    if (list.length && Object.prototype.toString.call(list[0]) === '[object Array]') {
      return find(list[index], item => {
        return item.value === one
      })
    } else {
      return find(list, item => {
        return item.value === one
      })
    }
  })
  rs = rs.filter(one => {

array-find

ES6 Array.find ponyfill. Return the first array element which satisfies a testing function.

MIT
Latest version published 10 years ago

Package Health Score

62 / 100
Full package analysis

Popular array-find functions