index int64 0 0 | repo_id stringlengths 16 181 | file_path stringlengths 28 270 | content stringlengths 1 11.6M | __index_level_0__ int64 0 10k |
|---|---|---|---|---|
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/compare.test.ts | import compare from './compare';
describe('compare()', () => {
it('returns 1 if a is greater than b', () => {
const result = compare(2, 1);
expect(result).toBe(1);
});
it('returns -1 if a is greater than b', () => {
const result = compare(1, 2);
expect(result).toBe(-1);
... | 9,600 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/compare.ts | /**
* Basic comparator function that transforms order via >,< into the numeric order that sorting functions typically require
*/
const compare = (a: any, b: any) => {
if (a > b) {
return 1;
}
if (a < b) {
return -1;
}
return 0;
};
export default compare;
| 9,601 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/debounce.test.ts | import debounce from './debounce';
describe('debounce()', () => {
beforeAll(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.clearAllTimers();
});
afterAll(() => {
jest.useRealTimers();
});
it('delays invoking function until after wait time', () => {
... | 9,602 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/debounce.ts | export { default } from 'lodash/debounce';
| 9,603 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/diff.test.ts | import diff from './diff';
describe('diff()', () => {
it('finds all values that are present in a given first array but not present in a given second array', () => {
const output = diff([1, null, 'a', true], [1, undefined, 'a', false]);
const expected = [null, true];
expect(output).toEqual... | 9,604 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/diff.ts | /**
* Returns all elements included in the first array BUT NOT in the second one
*/
const diff = <T>(arr1: T[], arr2: T[]) => arr1.filter((a) => !arr2.includes(a));
export default diff;
| 9,605 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/getRandomString.test.ts | import { disableRandomMock, initRandomMock } from '@proton/testing/lib/mockRandomValues';
import getRandomString, { DEFAULT_CHARSET } from './getRandomString';
describe('getRandomString()', () => {
const getConsecutiveArray = (length: number) => [...Array(length).keys()];
const mockedRandomValues = jest
... | 9,606 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/getRandomString.ts | export const DEFAULT_CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
export default function getRandomString(length: number, charset = DEFAULT_CHARSET) {
const values = crypto.getRandomValues(new Uint32Array(length));
let result = '';
for (let i = 0; i < length; i++) {
... | 9,607 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/getSafeErrorObject.test.ts | import { getSafeArray, getSafeErrorObject, getSafeObject, getSafeValue } from './getSafeErrorObject';
describe('getSafeValue', () => {
const error = new Error('blah');
const testCases = [
{ name: 'number', value: 3, expected: 3 },
{ name: 'string', value: 'abc', expected: 'abc' },
{ na... | 9,608 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/getSafeErrorObject.ts | /* eslint @typescript-eslint/no-use-before-define: 0 */
const isError = (e: any): e is Error => e instanceof Error || (e && typeof e.message === 'string');
type SafeValue = string | number | boolean | undefined | null | SafeObject | SafeValue[];
type SafeObject = { [key: string]: SafeValue };
export type SafeErrorObj... | 9,609 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/groupWith.test.ts | import groupWith from './groupWith';
describe('groupWith', () => {
it('groups items of an array into a two dimensional array based on a condition of whether or not two items should be grouped', () => {
expect(groupWith((a, b) => a === b, [1, 1, 1, 2, 2, 3])).toEqual([[1, 1, 1], [2, 2], [3]]);
});
... | 9,610 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/groupWith.ts | /**
* Groups elements in an array by a provided comparison function.
* E.g. `[1, 1, 2, 3, 3] => [[1, 1], [2], [3, 3]]`
*/
const groupWith = <T>(compare: (a: T, b: T) => boolean, arr: T[] = []) => {
const { groups } = arr.reduce<{ groups: T[][]; remaining: T[] }>(
(acc, a) => {
const { groups,... | 9,611 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/identity.test.ts | import identity from './identity';
describe('identity()', () => {
it('returns the value as reference', () => {
const value = {};
expect(identity(value)).toBe(value);
});
});
| 9,612 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/identity.ts | export default function identity<T>(value: T) {
return value;
}
| 9,613 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/isArrayOfUint8Array.test.ts | import isArrayOfUint8Array from './isArrayOfUint8Array';
describe('isArrayOfUint8Array()', () => {
it('returns true if array is empty', () => {
const result = isArrayOfUint8Array([]);
expect(result).toBe(true);
});
it('returns true if every item is an instance of Uint8Array', () => {
... | 9,614 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/isArrayOfUint8Array.ts | export default function isArrayOfUint8Array(arr: any[]): arr is Uint8Array[] {
return arr.every((el) => el instanceof Uint8Array);
}
| 9,615 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/isBetween.test.ts | import isBetween from './isBetween';
describe('isBetween()', () => {
it('returns true if a given number is between two other given number', () => {
expect(isBetween(5, -10, 10)).toBe(true);
});
it('returns true if a given number is exactly equal to the min', () => {
expect(isBetween(-10, -... | 9,616 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/isBetween.ts | /**
* Tells whether or not a given value is between two other given min and max values,
* including the min value, but excluding the max value.
*/
const isBetween = (value: number, min: number, max: number) => value >= min && value < max;
export default isBetween;
| 9,617 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/isFunction.test.ts | import isFunction from './isFunction';
it('should return true for class', () => {
const result = isFunction(class Any {});
expect(result).toEqual(true);
});
it('should return true for function', () => {
const result = isFunction(() => {});
expect(result).toEqual(true);
});
it('should return true for ... | 9,618 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/isFunction.ts | function isFunction(value: any): value is (...args: any[]) => any {
return typeof value === 'function';
}
export default isFunction;
| 9,619 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/isLastWeek.test.ts | import isLastWeek from './isLastWeek';
describe('isLastWeek', () => {
beforeEach(() => {
jest.useFakeTimers().setSystemTime(new Date('2023-03-27T20:00:00'));
});
afterEach(() => {
jest.useRealTimers();
});
it('should return true if the date is in the last week', () => {
co... | 9,620 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/isLastWeek.ts | /* This helper is inspired from https://github.com/date-fns/date-fns/blob/main/src/isSameWeek/index.ts helper */
import { startOfWeek, subDays } from 'date-fns';
/**
* The {@link isLastWeek} function options.
*/
/**
* @name isLastWeek
* @category Week Helpers
* @summary Is the given date in the last week?
*
* ... | 9,621 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/isTruthy.test.ts | import isTruthy from './isTruthy';
describe('isTruthy()', () => {
it('tells whether a value is JavaScript "truthy" or not', () => {
expect(isTruthy(false)).toBe(false);
expect(isTruthy(null)).toBe(false);
expect(isTruthy(0)).toBe(false);
expect(isTruthy(undefined)).toBe(false);
... | 9,622 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/isTruthy.ts | export default function isTruthy<T>(t: T | undefined | null | void | false | number): t is T {
return !!t;
}
| 9,623 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/jest.config.js | module.exports = {
setupFilesAfterEnv: ['./jest.setup.js'],
preset: 'ts-jest',
testEnvironment: './jest.env.js',
collectCoverageFrom: ['*.ts'],
coverageReporters: ['text', 'lcov', 'cobertura'],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
... | 9,624 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/jest.env.js | // Stolen from: https://github.com/ipfs/jest-environment-aegir/blob/master/src/index.js
// Overcomes error from jest internals.. this thing: https://github.com/facebook/jest/issues/6248
// Mostly needed for making OpenPGP.js works
const JSDOMEnvironment = require('jest-environment-jsdom').default;
class MyEnvironment... | 9,625 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/jest.setup.js | // JSDom does not include a full implementation of webcrypto
const crypto = require('crypto').webcrypto;
global.crypto.subtle = crypto.subtle;
| 9,626 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/lastItem.test.ts | import lastItem from './lastItem';
describe('lastItem()', () => {
it('should return undefined when array is empty', () => {
const result = lastItem([]);
expect(result).toBe(undefined);
});
it('should return only item when array is of length 1', () => {
const item = 'item';
... | 9,627 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/lastItem.ts | /**
* Returns the last item in an array
*/
export default function lastItem<T>(array: ArrayLike<T>): T | undefined {
return array[array.length - 1];
}
| 9,628 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/mergeUint8Arrays.test.ts | import mergeUint8Arrays from './mergeUint8Arrays';
describe('mergeUint8Arrays()', () => {
it('returns empty array if arrays is empty', () => {
const arrays: Uint8Array[] = [];
const result = mergeUint8Arrays(arrays);
expect(result).toStrictEqual(new Uint8Array());
});
it('merges ... | 9,629 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/mergeUint8Arrays.ts | export default function mergeUint8Arrays(arrays: Uint8Array[]) {
const length = arrays.reduce((sum, arr) => sum + arr.length, 0);
const chunksAll = new Uint8Array(length);
arrays.reduce((position, arr) => {
chunksAll.set(arr, position);
return position + arr.length;
}, 0);
return chu... | 9,630 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/mod.test.ts | import mod from './mod';
describe('mod()', () => {
it('should return a positive remainder', () => {
expect(mod(-4, 3)).toEqual(2);
expect(mod(-3, 3)).toEqual(0);
expect(mod(-2, 3)).toEqual(1);
expect(mod(-1, 3)).toEqual(2);
expect(mod(0, 3)).toEqual(0);
expect(mod(1,... | 9,631 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/mod.ts | // Modulo with negative number support
export default (n: number, m: number) => ((n % m) + m) % m;
| 9,632 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/move.test.ts | import move from './move';
describe('move()', () => {
it('should return a new array', () => {
const list = [1, 2, 3, 4, 5];
expect(move(list, 0, 0) !== list).toBeTruthy();
});
it('should correctly move elements to new positions', () => {
const list = [1, 2, 3, 4, 5];
expect... | 9,633 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/move.ts | /**
* Returns a new array with the item moved to the new position.
* @param list List of items
* @param from Index of item to move. If negative, it will begin that many elements from the end.
* @param to Index of where to move the item. If negative, it will begin that many elements from the end.
* @return New arra... | 9,634 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/noop.test.ts | import noop from './noop';
describe('noop()', () => {
it('returns undefined', () => {
expect(noop()).toBe(undefined);
});
});
| 9,635 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/noop.ts | export default function noop() {
return undefined;
}
| 9,636 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/orderBy.test.ts | import orderBy from './orderBy';
describe('orderBy()', () => {
it('orders an array of objects by the numeric value of a given property of the objects in the array', () => {
const arrayOfObjects = [{ id: 7 }, { id: 3 }, { id: 3 }, { id: 6 }, { id: 18 }, { id: 2 }];
const output = orderBy(arrayOfObj... | 9,637 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/orderBy.ts | /**
* Order collection of object by a specific key
*/
const orderBy = <T, K extends keyof T>(collection: T[], key: K) => {
return collection.slice().sort((a, b) => {
if (a[key] > b[key]) {
return 1;
}
if (a[key] < b[key]) {
return -1;
}
return 0;
... | 9,638 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/package.json | {
"name": "@proton/utils",
"description": "Generic business-agnostic utils.",
"scripts": {
"check-types": "tsc",
"lint": "eslint . --ext ts --quiet --cache",
"test": "jest --coverage --runInBand --ci",
"test:dev": "jest --watch"
},
"dependencies": {
"lodash": ... | 9,639 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/partition.test.ts | import partition from './partition';
describe('partition()', () => {
it('returns empty arrays if array is empty', () => {
const array: string[] = [];
const predicate = (item: string): item is string => {
return typeof item === 'string';
};
const result = partition(array... | 9,640 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/partition.ts | /**
* Creates an array of elements split into two groups, the first of which contains elements predicate returns
* truthy for, the second of which contains elements predicate returns falsey for.
*/
export default function partition<T, K = T>(arr: (T | K)[], predicate: (item: T | K) => item is T): [T[], K[]] {
co... | 9,641 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/percentOf.test.ts | import percentOf from './percentOf';
describe('percentOf()', () => {
it('returns the value of a percentage of another value', () => {
const output = percentOf(10, 200);
expect(output).toBe(20);
});
it("returns a decimal in case the percentage can't be resolved in integers", () => {
... | 9,642 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/percentOf.ts | /**
* Returns "percent" percent of "n".
*/
export default function percentOf(percent: number, n: number) {
return n * (percent * 0.01);
}
| 9,643 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/percentage.test.ts | import percentage from './percentage';
describe('percentage()', () => {
it('returns the percentage between an entire and a fraction', () => {
const output = percentage(500, 100);
expect(output).toBe(20);
});
it("returns a decimal in case the percentage can't be resolved in integers", () =... | 9,644 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/percentage.ts | export default function percentage(entire: number, fraction: number) {
/*
* Safeguard against division by 0 error as well as
* NaN inputs for either "entire" or "fraction".
*/
if (!entire || !fraction) {
return 0;
}
return (fraction / entire) * 100;
}
| 9,645 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/randomIntFromInterval.test.ts | import randomIntFromInterval from './randomIntFromInterval';
describe('randomIntFromInterval()', () => {
it('should be able to return min', () => {
jest.spyOn(Math, 'random').mockReturnValue(0);
const min = 1;
const max = 100;
const result = randomIntFromInterval(min, max);
... | 9,646 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/randomIntFromInterval.ts | /**
* Returns a random integer within an interval inclusive of the min and max.
*
* Does not use a cryptographically-secure pseudorandom number generator
*/
export default function randomIntFromInterval(
/**
* The smallest value in the interval
*/
min: number,
/**
* The largest value in t... | 9,647 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/range.test.ts | import range from './range';
describe('range()', () => {
it('defaults to creating a specific array if no arguments are provided', () => {
expect(range()).toEqual([0]);
});
it('returns an empty array if end is before start', () => {
expect(range(10, 2)).toEqual([]);
});
it('returns... | 9,648 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/range.ts | /**
* Build an array with a numeric range, specified by a start, an end, and a step
*/
const range = (start = 0, end = 1, step = 1) => {
const result = [];
for (let index = start; index < end; index += step) {
result.push(index);
}
return result;
};
export default range;
| 9,649 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/remove.test.ts | import remove from './remove';
describe('remove()', () => {
it('removes an item from an array', () => {
const output = remove(['a', 'b', 'c'], 'b');
expect(output).toEqual(['a', 'c']);
});
it('removes only the first occurence should there be multiple', () => {
const output = remove... | 9,650 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/remove.ts | /**
* Remove the first occurrence of an item from an array. Return a copy of the updated array
*/
const remove = <T>(arr: T[], item: T) => {
const i = arr.indexOf(item);
if (i === -1) {
return arr;
}
const result = arr.slice();
result.splice(i, 1);
return result;
};
export default rem... | 9,651 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/removeIndex.test.ts | import removeIndex from './removeIndex';
describe('removeIndex()', () => {
it('removes item at a given index from an array', () => {
const output = removeIndex(['a', 'b', 'c', 'd', 'e'], 2);
const expected = ['a', 'b', 'd', 'e'];
expect(output).toEqual(expected);
});
});
| 9,652 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/removeIndex.ts | /**
* Removes item at "index" from "array"
*/
const removeIndex = <T>(array: T[], index: number) => array.filter((_, i) => i !== index);
export default removeIndex;
| 9,653 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/replace.test.ts | import replace from './replace';
describe('replace()', () => {
it('replaces an item from an array', () => {
const output = replace(['a', 'b', 'c'], 'b', 'x');
expect(output).toEqual(['a', 'x', 'c']);
});
it('replaces only the first occurence should there be multiple', () => {
const... | 9,654 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/replace.ts | /**
* Replace the first occurrence of an item from an array by another item. Return a copy of the updated array
*/
export default <T>(arr: T[], item: T, replacement: T) => {
const i = arr.indexOf(item);
if (i === -1) {
return arr;
}
const result = arr.slice();
result.splice(i, 1, replaceme... | 9,655 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/shallowEqual.test.ts | import shallowEqual from './shallowEqual';
describe('shallowEqual()', () => {
it('returns true when comparing 2 empty arrays', () => {
const result = shallowEqual([], []);
expect(result).toBe(true);
});
it('returns true if arrays contain the same items', () => {
const result = sha... | 9,656 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/shallowEqual.ts | /**
* Determine if two arrays are shallowy equal (i.e. they have the same length and the same elements)
*/
export default function shallowEqual<T>(a: T[], b: T[]) {
if (a.length !== b.length) {
return false;
}
for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return fal... | 9,657 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/shuffle.test.ts | import shuffle from './shuffle';
describe('shuffle()', () => {
it('returns empty array when empty array is passed', () => {
const result = shuffle([]);
expect(result).toStrictEqual([]);
});
it('returns same array when array of length 1 is passed', () => {
const input = [0];
... | 9,658 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/shuffle.ts | /**
* Fisher–Yates shuffle implementation - https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
*/
export default function shuffle<T>(array: T[]): T[] {
const arrayCopy = [...array];
for (let i = arrayCopy.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + ... | 9,659 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/throttle.test.ts | import throttle from './throttle';
describe('throttle()', () => {
beforeAll(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.clearAllTimers();
});
afterAll(() => {
jest.useRealTimers();
});
it('invokes function at most once every wait milliseconds', () => ... | 9,660 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/throttle.ts | export { default } from 'lodash/throttle';
| 9,661 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/truncate.test.ts | import truncate, { DEFAULT_TRUNCATE_OMISSION } from './truncate';
describe('truncate()', () => {
it('returns empty sting if provided string is empty', () => {
expect(truncate('', 0)).toEqual('');
expect(truncate('', 1)).toEqual('');
expect(truncate('', 2)).toEqual('');
});
it('trun... | 9,662 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/truncate.ts | export const DEFAULT_TRUNCATE_OMISSION = '…';
/**
* Truncate `str` to a maximum length `charsToDisplay`.
* Appends `omission` if `str` is too long.
*
* The length of the string returned (which may include
* the omission) will not exceed `charsToDisplay`.
*/
export default function truncate(
/**
* String... | 9,663 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/tsconfig.json | {
"extends": "../../tsconfig.base.json"
}
| 9,664 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/unary.test.ts | import unary from './unary';
describe('unary()', () => {
it('should handle functions with no arguments', () => {
const myFunction = () => {
return 'myFunction';
};
const unaryFunction = unary(myFunction);
expect(unaryFunction('I still require an argument')).toEqual('my... | 9,665 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/unary.ts | /**
* Wrap a function to ensure only one argument will pass through
*/
export default function unary<A, B>(fn: (...args: any) => B) {
return (arg: A) => fn(arg);
}
| 9,666 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/uncapitalize.test.ts | import uncapitalize from './uncapitalize';
describe('uncapitalize()', () => {
it('returns an empty string when an empty string is provided', () => {
expect(uncapitalize('')).toBe('');
});
it('uncapitalizes a single letter', () => {
expect(uncapitalize('A')).toBe('a');
});
it('unca... | 9,667 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/uncapitalize.ts | /**
* Uncapitalize the first letter in a string.
*/
export default function uncapitalize(str: string) {
if (str === '') {
return '';
}
return str[0].toLowerCase() + str.slice(1);
}
| 9,668 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/unique.test.ts | import unique from './unique';
describe('unique()', () => {
it('should return same', () => {
expect(unique([1, 2])).toEqual([1, 2]);
});
it('should only return unique items', () => {
expect(unique([1, 2, 1])).toEqual([1, 2]);
});
});
| 9,669 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/unique.ts | import uniqueBy from './uniqueBy';
const unique = <T>(array: T[]) => uniqueBy(array, (x) => x);
export default unique;
| 9,670 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/uniqueBy.test.ts | import uniqueBy from './uniqueBy';
describe('uniqueBy()', () => {
it('should only get unique items', () => {
const list = [{ foo: 'abc' }, { foo: 'bar' }, { foo: 'asd' }, { foo: 'bar' }, { foo: 'bar' }];
expect(uniqueBy(list, ({ foo }) => foo)).toEqual([{ foo: 'abc' }, { foo: 'bar' }, { foo: 'asd' ... | 9,671 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/uniqueBy.ts | /**
* Extract the elements from an array that are unique according to a comparator function
*/
const uniqueBy = <T>(array: T[], comparator: (t: T) => any) => {
const seen = new Set();
return array.filter((value) => {
const computed = comparator(value);
const hasSeen = seen.has(computed);
... | 9,672 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/updateItem.test.ts | import updateItem from './updateItem';
describe('updateItem()', () => {
it('returns empty array if array is empty', () => {
const array: any[] = [];
const index = 1;
const newItem = 'new item';
const result = updateItem(array, index, newItem);
expect(result).toStrictEqual(... | 9,673 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/updateItem.ts | /**
* Updates an item in an array.
*/
export default function updateItem<T>(array: T[], index: number, newItem: T) {
return array.map((item, i) => {
if (i !== index) {
return item;
}
return newItem;
});
}
| 9,674 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/withDecimalPrecision.test.ts | import withDecimalPrecision from './withDecimalPrecision';
describe('withDecimalPrecision()', () => {
it('returns the same number when the precision is infinity', () => {
const list = [2.234, 5, 381712.0001, -1, -1.38, -0.99, -10282.12312];
expect(list.map((x) => withDecimalPrecision(x, Infinity)))... | 9,675 |
0 | petrpan-code/ProtonMail/WebClients/packages | petrpan-code/ProtonMail/WebClients/packages/utils/withDecimalPrecision.ts | /**
* Round a number, x, to a certain number, n, of decimal places.
* If n < 0, keep the significative digits up to 10 ** (-n)
*/
export default function withDecimalPrecision(x: number, n: number) {
// assume n is an integer. Round to integer otherwise
const powerOfTen = 10 ** Math.round(n);
if (powerOfT... | 9,676 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/.cz.toml | [tool.commitizen]
name = "cz_conventional_commits"
version = "0.0.1"
tag_format = "$version"
| 9,677 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/.dockerignore | .git
dist
uploads
frontend/node_modules
internal/frontend/frontend_generated.go
internal/migrations/migrations_generated.go
taskcafe
conf/taskcafe.toml
| 9,678 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/.pre-commit-config.yaml | repos:
- repo: local
hooks:
- id: eslint
name: eslint
entry: scripts/lint.sh
language: system
files: \.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx
types: [file]
- hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
repo: https://github.com/pre-commit/pre-com... | 9,679 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/.tmuxinator.yml | name: taskcafe
root: .
windows:
- services:
root: ./
panes:
- api:
- go run cmd/taskcafe/main.go web
- yarn:
- cd frontend
- yarn start
- worker:
- go run cmd/taskcafe/main.go worker
- web/editor:
root: ./frontend
panes:
... | 9,680 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/CHANGELOG.md | # Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## UNRELEASED
### Added
- On login page, redirects to `/register` i... | 9,681 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/CODE_OF_CONDUCT.md | # Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex ch... | 9,682 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/CONTRIBUTING.md | ## Contributing
Thanks for wanting to contribute to Taskcafe!
### Where do I go from here?
So you want to contribute to Taskcafe? Great!
If you have noticed a bug, please [create an issue](https://github.com/JordanKnott/taskcafe/issues/new/choose) for it before starting any work on a pull request.
If there is a [n... | 9,683 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/Dockerfile | FROM node:14.5-alpine as frontend
RUN apk --no-cache add curl
WORKDIR /usr/src/app
COPY frontend .
RUN yarn install
RUN yarn build
FROM golang:1.14.5-alpine as backend
WORKDIR /usr/src/app
COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download
COPY . .
COPY --from=frontend /usr/src/app/build ./frontend/build
RUN go... | 9,684 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/LICENSE | MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, dist... | 9,685 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/Pipfile | [[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
pre-commit = "*"
[requires]
python_version = "3.9"
| 9,686 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/Pipfile.lock | {
"_meta": {
"hash": {
"sha256": "76a59164ad995ef4d02794470696e6f1dd199ede126c2d92a2bc1011eb288f69"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.9"
},
"sources": [
{
"name": "pypi",
"url":... | 9,687 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/README.md | <p align="center">
<img width="450px" src="./.github/taskcafe-full.png" align="center" alt="Taskcafe logo" />
</p>
<p align="center">
<a href="https://discord.gg/JkQDruh">
<img alt="Discord" src="https://img.shields.io/discord/745396499613220955" />
</a>
<a href="https://github.com/JordanKnott/taskcafe/relea... | 9,688 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/docker-compose.dev.yml | version: "3"
services:
postgres:
image: postgres:12.3-alpine
restart: always
networks:
- taskcafe-test
environment:
POSTGRES_USER: taskcafe
POSTGRES_PASSWORD: taskcafe_test
POSTGRES_DB: taskcafe
volumes:
- taskcafe-postgres:/var/lib/postgresql/data
ports:
- ... | 9,689 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/docker-compose.migrate.yml | version: '3'
services:
migrate:
build: .
entrypoint: ./taskcafe migrate
volumes:
- ./migrations:/root/migrations
depends_on:
- postgres
networks:
- taskcafe-test
| 9,690 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/docker-compose.yml | version: "3"
services:
web:
image: taskcafe/taskcafe:latest
# build: .
ports:
- "3333:3333"
depends_on:
- postgres
networks:
- taskcafe-test
environment:
TASKCAFE_DATABASE_HOST: postgres
TASKCAFE_MIGRATE: "true"
volumes:
- taskcafe-uploads:/root/uploads
... | 9,691 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/go.mod | module github.com/jordanknott/taskcafe
go 1.13
require (
github.com/99designs/gqlgen v0.13.0
github.com/RichardKnop/machinery v1.9.1
github.com/brianvoe/gofakeit/v5 v5.11.2
github.com/go-chi/chi v3.3.2+incompatible
github.com/go-chi/cors v1.2.0
github.com/go-redis/redis v6.15.8+incompatible
github.com/go-redis... | 9,692 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/go.sum | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.37.4/go.mod h1:NHPJ89PdicEuT9hdPXMROBD91xc5uRDxsMtSB16k7hw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp... | 9,693 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/gqlgen.yml | # Where are all the schema files located? globs are supported eg src/**/*.graphqls
schema:
- internal/graph/schema/*.gql
# Where should the generated server code go?
exec:
filename: internal/graph/generated.go
package: graph
# Uncomment to enable federation
# federation:
# filename: graph/generated/federatio... | 9,694 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/magefile.go | //+build mage
package main
import (
"errors"
"fmt"
"io/ioutil"
"net/http"
"os"
"regexp"
"strings"
"time"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/shurcooL/vfsgen"
)
const (
packageName = "github.com/jordanknott/taskcafe"
)
var semverRegex = regexp.MustCompile(`^(?P<major>... | 9,695 |
0 | petrpan-code/JordanKnott | petrpan-code/JordanKnott/taskcafe/sqlc.yaml | version: "1"
packages:
- name: "db"
emit_json_tags: true
emit_prepared_queries: false
emit_interface: true
path: "internal/db"
queries: "./internal/db/query/"
schema: "./migrations/"
| 9,696 |
0 | petrpan-code/JordanKnott/taskcafe/cmd | petrpan-code/JordanKnott/taskcafe/cmd/mage/main.go | // +build ignore
package main
import (
"os"
"github.com/magefile/mage/mage"
)
func main() { os.Exit(mage.Main()) }
| 9,697 |
0 | petrpan-code/JordanKnott/taskcafe/cmd | petrpan-code/JordanKnott/taskcafe/cmd/taskcafe/main.go | package main
import (
"github.com/jordanknott/taskcafe/internal/commands"
_ "github.com/lib/pq"
)
func main() {
commands.Execute()
}
| 9,698 |
0 | petrpan-code/JordanKnott/taskcafe | petrpan-code/JordanKnott/taskcafe/conf/air.toml | # Config file for [Air](https://github.com/cosmtrek/air) in TOML format
# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"
[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./dist/taskcafe cmd/taskc... | 9,699 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.