mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-25 01:25:41 -05:00
1.0 wip
This commit is contained in:
14
src/system/function.ts
Normal file
14
src/system/function.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
// import { debounce as _debounce } from 'lodash';
|
||||
const _debounce = require('lodash.debounce');
|
||||
|
||||
export interface IDeferred {
|
||||
cancel(): void;
|
||||
flush(): void;
|
||||
}
|
||||
|
||||
export namespace Functions {
|
||||
export function debounce<T extends Function>(fn: T, wait?: number, options?: any): T & IDeferred {
|
||||
return _debounce(fn, wait, options);
|
||||
}
|
||||
}
|
||||
55
src/system/iterable.ts
Normal file
55
src/system/iterable.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
export namespace Iterables {
|
||||
export function* filter<T>(source: Iterable<T> | IterableIterator<T>, predicate: (item: T) => boolean): Iterable<T> {
|
||||
for (const item of source) {
|
||||
if (predicate(item)) yield item;
|
||||
}
|
||||
}
|
||||
|
||||
export function* filterMap<T, TMapped>(source: Iterable<T> | IterableIterator<T>, predicateMapper: (item: T) => TMapped | undefined | null): Iterable<TMapped> {
|
||||
for (const item of source) {
|
||||
const mapped = predicateMapper(item);
|
||||
if (mapped) yield mapped;
|
||||
}
|
||||
}
|
||||
|
||||
export function forEach<T>(source: Iterable<T> | IterableIterator<T>, fn: (item: T, index: number) => void): void {
|
||||
let i = 0;
|
||||
for (const item of source) {
|
||||
fn(item, i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
export function find<T>(source: Iterable<T> | IterableIterator<T>, predicate: (item: T) => boolean): T {
|
||||
for (const item of source) {
|
||||
if (predicate(item)) return item;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function first<T>(source: Iterable<T>): T {
|
||||
return source[Symbol.iterator]().next().value;
|
||||
}
|
||||
|
||||
export function* flatMap<T, TMapped>(source: Iterable<T> | IterableIterator<T>, mapper: (item: T) => Iterable<TMapped>): Iterable<TMapped> {
|
||||
for (const item of source) {
|
||||
yield* mapper(item);
|
||||
}
|
||||
}
|
||||
|
||||
export function isIterable(source: Iterable<any>): boolean {
|
||||
return typeof source[Symbol.iterator] === 'function';
|
||||
}
|
||||
|
||||
export function* map<T, TMapped>(source: Iterable<T> | IterableIterator<T>, mapper: (item: T) => TMapped): Iterable<TMapped> {
|
||||
for (const item of source) {
|
||||
yield mapper(item);
|
||||
}
|
||||
}
|
||||
|
||||
export function next<T>(source: IterableIterator<T>): T {
|
||||
return source.next().value;
|
||||
}
|
||||
}
|
||||
15
src/system/object.ts
Normal file
15
src/system/object.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
//import { isEqual as _isEqual } from 'lodash';
|
||||
const _isEqual = require('lodash.isequal');
|
||||
|
||||
export namespace Objects {
|
||||
export function areEquivalent(first: any, second: any): boolean {
|
||||
return _isEqual(first, second);
|
||||
}
|
||||
|
||||
export function* entries(o: any): IterableIterator<[string, any]> {
|
||||
for (let key in o) {
|
||||
yield [key, o[key]];
|
||||
}
|
||||
}
|
||||
}
|
||||
9
src/system/string.ts
Normal file
9
src/system/string.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
//import { escapeRegExp as _escapeRegExp } from 'lodash';
|
||||
const _escapeRegExp = require('lodash.escaperegexp');
|
||||
|
||||
export namespace Strings {
|
||||
export function escapeRegExp(s: string): string {
|
||||
return _escapeRegExp(s);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user