lodash#endsWith TypeScript Examples

The following examples show how to use lodash#endsWith. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sort-action.ts    From S2 with MIT License 5 votes vote down vote up
sortByCustom = (params: SortActionParams): string[] => {
  const { sortByValues, originValues } = params;

  // 从 originValues 中过滤出所有包含 sortByValue 的 id
  const idWithPre = originValues.filter((originItem) =>
    sortByValues.find((value) => endsWith(originItem, value)),
  );
  // 将 id 拆分为父节点和目标节点
  const idListWithPre = idWithPre.map((idStr) => {
    const ids = idStr.split(ID_SEPARATOR);
    if (ids.length > 1) {
      const parentId = ids.slice(0, ids.length - 1).join(ID_SEPARATOR);
      return [parentId, ids[ids.length - 1]];
    }
    return ids;
  });
  // 获取父节点顺序
  const parentOrder = Array.from(new Set(idListWithPre.map((id) => id[0])));
  // 排序
  idListWithPre.sort((a: string[], b: string[]) => {
    const aParent = a.slice(0, a.length - 1);
    const bParent = b.slice(0, b.length - 1);
    // 父节点不同时,按 parentOrder 排序
    if (aParent.join() !== bParent.join()) {
      const aParentIndex = parentOrder.indexOf(aParent[0]);
      const bParentIndex = parentOrder.indexOf(bParent[0]);
      return aParentIndex - bParentIndex;
    }
    // 父节点相同时,按 sortByValues 排序
    const aIndex = sortByValues.indexOf(a[a.length - 1]);
    const bIndex = sortByValues.indexOf(b[b.length - 1]);
    return aIndex - bIndex;
  });
  // 拼接 id
  const sortedIdWithPre = idListWithPre.map((idArr) =>
    idArr.join(ID_SEPARATOR),
  );

  return getListBySorted(originValues, sortedIdWithPre);
}
Example #2
Source File: str.monad.ts    From relate with GNU General Public License v3.0 5 votes vote down vote up
endsWith(other: string | Str): boolean {
        return endsWith(`${this}`, `${other}`);
    }
Example #3
Source File: apiConfig.ts    From erda-ui with GNU Affero General Public License v3.0 4 votes vote down vote up
ApiMap = {
  sortList: {
    getFetchObj: ({ sortTab }: { sortTab: string }) => {
      const fetchMap = {
        time: {
          fetchApi: 'ta_top_avg_time',
          query: { group: 'province', limit: 20, sort: 'avg_plt', avg: 'plt' },
          dataKey: 'avg.plt',
        },
        percent: {
          fetchApi: 'ta_top_percent_time',
          query: { group: 'province', limit: 20, sort: 'sumPercent_plt', sumPercent: 'plt' },
          dataKey: 'sumPercent.plt',
        },
        cpm: {
          fetchApi: 'ta_top_cpm',
          query: { group: 'province', limit: 20, sort: 'cpm_plt', cpm: 'plt' },
          dataKey: 'cpm.plt',
        },
      };
      const { query = {}, fetchApi = '', dataKey = '' } = fetchMap[sortTab] || {};
      return { fetchApi, extendQuery: { ...query }, extendHandler: { dataKey } };
    },
    dataHandler: sortHandler(),
  },
  performanceInterval: {
    fetchApi: 'ta_performance/histogram',
    query: { ...commonQuery, avg: ['tcp', 'srt', 'plt', 'rlt'] },
    dataHandler: multipleDataHandler(['avg.tcp', 'avg.srt', 'avg.plt', 'avg.rlt']),
  },
  pagePerformanceTrends: {
    fetchApi: 'ta_page_timing/histogram',
    query: { ...commonQuery, count: 'plt', avg: 'plt' },
    dataHandler: multipleDataHandler(['avg.plt', 'count.plt']),
  },
  regionalLoadingTime: {
    fetchApi: 'ta_map',
    query: { ...commonQuery, group: 'province', avg: 'plt', cpm: 'plt' },
    dataHandler: (orignData: object) => {
      const reData: any = {
        results: [],
        pieces: [
          { lt: 1, label: '<1s' },
          { gte: 1, lt: 2, label: '1 ~ 2s' },
          { gte: 2, lt: 3, label: '2 ~ 3s' },
          { gte: 3, lt: 4, label: '3 ~ 4s' },
          { gte: 4, lt: 5, label: '4 ~ 5s' },
          { gte: 5, lt: 6, label: '5 ~ 6s' },
          { gte: 6, lt: 7, label: '6 ~ 7s' },
          { gte: 7, label: '>= 7s' },
        ],
      };
      const list = get(orignData, 'results[0].data');
      if (list.length > 0) {
        const arr = map(list, (item) => {
          const { tag = '', name = '', data = 0 } = item['avg.plt'] || {};
          const cpm = item['cpm.plt'] || {};
          let _name = tag || name;
          if (endsWith(_name, '省') || endsWith(_name, '市')) {
            _name = _name.slice(0, _name.length - 1);
          }
          return { name: _name, value: data / 1000, tps: cpm.data || 0 };
        });
        reData.results = [{ data: arr, type: i18n.t('msp:average load time') }];
      }
      return { ...reData };
    },
  },
  slowTrack: {
    fetchApi: 'ta_timing_slow',
    query: {
      group: 'doc_path',
      limit: 10,
      sort: 'max_plt',
      max: 'plt',
      min: 'plt',
      maxFieldTimestamp: 'plt',
      source: true,
    },
    dataHandler: slowHandler(['max:max.plt', 'time:maxFieldTimestamp.plt', 'min:min.plt']),
  },
}