Pārlūkot izejas kodu

Removes lodash usages -- only debounce is left

main
Eric Amodio pirms 2 gadiem
vecāks
revīzija
92d27ae3ee
3 mainītis faili ar 37 papildinājumiem un 6 dzēšanām
  1. +2
    -2
      src/commands/quickCommand.steps.ts
  2. +26
    -2
      src/system/array.ts
  3. +9
    -2
      src/system/object.ts

+ 2
- 2
src/commands/quickCommand.steps.ts Parādīt failu

@ -302,12 +302,12 @@ export async function getBranchesAndOrTags(
if (include.includes('branches') && branchesByRepo != null) {
branches = sortBranches(
intersection(...branchesByRepo, (b1: GitBranch, b2: GitBranch) => b1.name === b2.name),
intersection(branchesByRepo, (b1: GitBranch, b2: GitBranch) => b1.name === b2.name),
);
}
if (include.includes('tags') && tagsByRepo != null) {
tags = sortTags(intersection(...tagsByRepo, (t1: GitTag, t2: GitTag) => t1.name === t2.name));
tags = sortTags(intersection(tagsByRepo, (t1: GitTag, t2: GitTag) => t1.name === t2.name));
}
}

+ 26
- 2
src/system/array.ts Parādīt failu

@ -1,5 +1,3 @@
// eslint-disable-next-line no-restricted-imports
export { findLastIndex, intersectionWith as intersection } from 'lodash-es';
import { join } from './iterable';
export function chunk<T>(source: T[], size: number): T[][] {
@ -64,6 +62,14 @@ export function filterMapAsync(
}, []);
}
export function findLastIndex<T>(source: T[], predicate: (value: T, index: number, obj: T[]) => boolean): number {
let l = source.length;
while (l--) {
if (predicate(source[l], l, source)) return l;
}
return -1;
}
export function groupBy<T>(source: readonly T[], groupingKey: (item: T) => string): Record<string, T[]> {
return source.reduce<Record<string, T[]>>((groupings, current) => {
const value = groupingKey(current);
@ -113,6 +119,24 @@ export function groupByFilterMap(
}, new Map<TKey, TMapped[]>());
}
export function intersection<T>(sources: T[][], comparator: (a: T, b: T) => boolean): T[] {
const results: T[] = [];
const length = sources.length;
outer: for (const item of sources[0]) {
let i = length - 1;
while (i--) {
if (!sources[i + 1].some(v => comparator(v, item))) break outer;
}
if (!results.some(v => comparator(v, item))) {
results.push(item);
}
}
return results;
}
export function isStringArray<T extends any[]>(array: readonly string[] | T): array is string[] {
return typeof array[0] === 'string';
}

+ 9
- 2
src/system/object.ts Parādīt failu

@ -1,5 +1,12 @@
// eslint-disable-next-line no-restricted-imports
export { isEqual as areEqual } from 'lodash-es';
export function areEqual(a: any, b: any): boolean {
if (a === b) return true;
if (a == null || b == null) return false;
const aType = typeof a;
if (aType === typeof b && (aType === 'string' || aType === 'number' || aType === 'boolean')) return false;
return JSON.stringify(a) === JSON.stringify(b);
}
export function flatten(o: any, options: { prefix?: string; skipNulls: true; stringify: true }): Record<string, string>;
export function flatten(

||||||
x
 
000:0
Notiek ielāde…
Atcelt
Saglabāt