• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript fp.filter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中lodash/fp.filter函数的典型用法代码示例。如果您正苦于以下问题:TypeScript filter函数的具体用法?TypeScript filter怎么用?TypeScript filter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了filter函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: filter

    return filter((snippet) => {
      const descriptionMatch = snippet.description.match(regex);
      const fileNameMatch = size(filter((file) => file.filename.match(regex), snippet.files)) > 0;
      const contentMatch =
        size(filter((file) => file.content && file.content.match(regex), snippet.files)) > 0;

      return descriptionMatch || fileNameMatch || contentMatch;
    }, snippets);
开发者ID:Gisto,项目名称:Gisto,代码行数:8,代码来源:snippets.ts


示例2: pkgsNotInstalled

function pkgsNotInstalled (pkgs) {
  const uninstalledPkgs = _.filter(isPkgNotInstalled, pkgs)
  const lines = _.map(pkg => Object({
    desc: `使用到的依赖 ${pkg.moduleName} 还没有安装`,
    valid: false
  }), uninstalledPkgs)
  return lines
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:8,代码来源:packageValidator.ts


示例3: taroCliVersionNotMatch

function taroCliVersionNotMatch (pkgs) {
  const pkgsNotMatch = _.filter(pkg => isPkgInstalled(pkg) && isCliVersionNotMatch(pkg), pkgs)
  const lines = _.map(pkg => Object({
    desc: `${pkg.moduleName} (${pkg.installed}) 与当前使用的 @tarojs/cli (${pkgVersion}) 版本不一致, 请更新为统一的版本`,
    valid: false
  }), pkgsNotMatch)
  return lines
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:8,代码来源:packageValidator.ts


示例4: orderBy

export const filterSnippetsList = (
  snippets: ISnippet,
  filterText: string,
  filterTags: string,
  filterLanguage: string,
  filterStatus: string,
  filterTruncated: string,
  filterUntagged: string
) => {
  // @ts-ignore
  const sortedSnippets: ISnippet = orderBy(
    [getSetting('settings-snippet-order-field', 'created')],
    [getSetting('settings-snippet-order-direction', 'desc')],
    snippets
  );

  if (!isEmpty(trim(filterText))) {
    return filterByFreeText(sortedSnippets, trim(filterText));
  }

  if (!isEmpty(filterTags)) {
    return filterByTags(sortedSnippets, filterTags);
  }

  if (!isEmpty(trim(filterLanguage))) {
    return filterByLanguage(sortedSnippets, trim(filterLanguage));
  }

  if (!isEmpty(trim(filterStatus))) {
    return filterByStatus(sortedSnippets, trim(filterStatus));
  }

  if (filterTruncated) {
    // @ts-ignore
    return filter({ truncated: true }, sortedSnippets);
  }

  if (filterUntagged) {
    return filter((snippet) => snippet.tags === null || size(snippet.tags) === 0, sortedSnippets);
  }

  return sortedSnippets;
};
开发者ID:Gisto,项目名称:Gisto,代码行数:43,代码来源:snippets.ts


示例5: switch

const filterByStatus = (snippets: ISnippet, filterStatus: string) => {
  switch (filterStatus) {
    case 'private': {
      return filter((snippet) => snippet.public === false, snippets);
    }
    case 'public': {
      return filter((snippet) => snippet.public === true, snippets);
    }
    case 'starred': {
      return filter((snippet) => snippet.star === true, snippets);
    }
    case 'untitled': {
      return filter((snippet) => snippet.description === 'untitled', snippets);
    }
    default: {
      return snippets;
    }
  }
};
开发者ID:Gisto,项目名称:Gisto,代码行数:19,代码来源:snippets.ts


示例6: RegExp

const filterByFreeText = (snippets: ISnippet, filterText: string) => {
  try {
    new RegExp(filterText, 'gi');
  } catch (e) {
    return false;
  }

  const regex = new RegExp(filterText, 'gi');

  if (filterText !== '') {
    if (isTag(filterText)) {
      return filterByTagsText(snippets, filterText);
    }

    if (hasTag(filterText)) {
      const textMatches = filter((snippet) => {
        return !!snippet.description.includes(removeTags(filterText));
      }, snippets);

      const matchedTag = head(filterText.match(/#.+/gi));

      return filter((snippet) => {
        return !!includes(matchedTag, snippet.tags);
      }, textMatches);
    }

    return filter((snippet) => {
      const descriptionMatch = snippet.description.match(regex);
      const fileNameMatch = size(filter((file) => file.filename.match(regex), snippet.files)) > 0;
      const contentMatch =
        size(filter((file) => file.content && file.content.match(regex), snippet.files)) > 0;

      return descriptionMatch || fileNameMatch || contentMatch;
    }, snippets);
  }

  return snippets;
};
开发者ID:Gisto,项目名称:Gisto,代码行数:38,代码来源:snippets.ts


示例7: checkPkgs

async function checkPkgs () {
  let errorLines: any[] = []
  const pkgs = await npmCheck()
    .then(_.invoke('all'))
    .then(_.get('packages'))
  const taroPkgs = _.filter(isTaroPkg, pkgs)

  errorLines = _.concat(errorLines, pkgsNotInstalled(pkgs))
  errorLines = _.concat(errorLines, taroShouldUpdate(taroPkgs))
  errorLines = _.concat(errorLines, taroCliVersionNotMatch(taroPkgs))
  errorLines = _.compact(errorLines)

  return {
    desc: '检查依赖',
    lines: errorLines
  }
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:17,代码来源:packageValidator.ts


示例8: flow

export const prepareFilesForUpdate = (snippet: ISnippet) => {
  const cleanFiles = flow([
    map((file) => {
      return pick(['filename', 'content', 'originalFileName', 'delete', 'isNew'], file);
    }),
    // we do not support saving/editing specific files
    filter(
      (file: IFile) =>
        !file.filename.match(
          /png|jpg|jpeg|gif|bmp|tiff|tif|webp|xpm|exif|icns|ico|jp2|ai|psd|pdf/gi
        )
    )
  ])(snippet.files);

  const filesClean = keyBy('originalFileName', cleanFiles);

  const files = reduce(
    (acc, file) => {
      if (file.delete) {
        acc[file.originalFileName] = null;
      } else if (file.isNew) {
        acc[file.filename] = {
          filename: file.filename,
          content: file.content
        };
      } else {
        acc[file.originalFileName] = {
          filename: file.filename,
          content: file.content
        };
      }

      return acc;
    },
    {},
    filesClean
  );

  return {
    description: snippet.description,
    files
  };
};
开发者ID:Gisto,项目名称:Gisto,代码行数:43,代码来源:snippets.ts


示例9: lowfp

() => {
  const adapterLS = new LocalStorage<DbSchema>("test.json");
  const dbFP = lowfp(adapterLS);
  // Get posts
  const postsFP = dbFP("posts");

  // replace posts with a new array resulting from concat
  // and persist database
  const write: Post[] = postsFP.write(
    concat<Post>({ title: "lowdb is awesome", views: random(0, 5) })
  );

  // Find post by id
  const post: Post | undefined = postsFP(find<Post>({ id: 1 }));

  // Find top 5 fives posts
  const popular: Post[] = postsFP([
    sortBy<Post>("views") as PostsAction,
    take(5) as PostsAction
  ]);

  const filtered: Post[] = dbFP("posts")(filter<Post>({ published: true }));
  const writeAction: Post[] = dbFP("posts").write(concat<Post>({ id: 123 }));
  const writeAction2: string = dbFP(["user", "name"]).write(() => "typicode");

  async () => {
    const adapterAsync = new FileAsync<DbSchema>("test.json");
    const dbAsyncPromise = lowfp(adapterAsync);
    const dbAsync = await dbAsyncPromise;
    const postsWithDefault = dbAsync("posts", [{ title: "baz" }] as Post[]);

    const func: Promise<Post[]> = postsWithDefault.write(post => [
      ...post,
      { title: "another" }
    ]);
  };

  type PostsAction = (posts: Post[]) => Post[];
};
开发者ID:csrakowski,项目名称:DefinitelyTyped,代码行数:39,代码来源:lowdb-tests.ts



注:本文中的lodash/fp.filter函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript fp.flow函数代码示例发布时间:2022-05-25
下一篇:
TypeScript fp.cloneDeep函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap