Skip to content

Commit

Permalink
format existing
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatiusmb committed Jul 7, 2023
1 parent 5d8a8d5 commit eb66238
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function fetcher({
{ headers, from, using }: SendOptions,
method: HTTPMethods,
url: string,
body?: any
body?: any,
): Promise<{ kind: 'error'; error: string } | { kind: 'success'; value: T }> {
let response: Response;
try {
Expand Down
2 changes: 1 addition & 1 deletion src/bits/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function binary<T>(
check: {
item: UnaryFunction<T, false | UnaryFunction<T>>;
pointer: UnaryFunction<T, boolean>;
}
},
): T | undefined {
let start = 0, final = sorted.length - 1; // prettier-ignore
while (start <= final) {
Expand Down
10 changes: 5 additions & 5 deletions src/core/compare/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,32 @@ suites['inspect/']('inspect', () => {
suites['undefined/']('sort undefined values with null values above', () => {
assert.equal(
[undefined, 3, 0, null, 1, -1, undefined, -2, undefined, null].sort(compare.undefined),
[3, 0, 1, -1, -2, null, null, undefined, undefined, undefined]
[3, 0, 1, -1, -2, null, null, undefined, undefined, undefined],
);
});

suites['boolean/']('sort boolean values with true above', () => {
assert.equal(
[true, false, true, false, true, false, true, false, true, false].sort(compare.boolean),
[true, true, true, true, true, false, false, false, false, false]
[true, true, true, true, true, false, false, false, false, false],
);
});

suites['number/']('sort number in descending order', () => {
assert.equal(
[5, 3, 9, 6, 0, 2, 1, -1, 4, -2].sort(compare.number),
[9, 6, 5, 4, 3, 2, 1, 0, -1, -2]
[9, 6, 5, 4, 3, 2, 1, 0, -1, -2],
);
});

suites['string/']('sort string in alphabetical order', () => {
assert.equal(
['k', 'h', 'g', 'f', 'e', 'l', 'd', 'm', 'c', 'b', 'j', 'i', 'a'].sort(compare.string),
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm']
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'],
);
assert.equal(
['K', 'H', 'G', 'F', 'E', 'L', 'D', 'M', 'C', 'B', 'J', 'I', 'A'].sort(compare.string),
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M']
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'],
);
});

Expand Down
6 changes: 3 additions & 3 deletions src/core/compare/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ compare.key('name')({ name: 'abc' }, { name: 'def', foo: maybe ? 1 : undefined }
compare.key('name', compare.string)({ name: 'abc' }, { name: 'def' });
compare.key('name.first', compare.string)(
{ name: { first: 'abc-xyz' } },
{ name: { first: 'xyz-def' } }
{ name: { first: 'xyz-def' } },
);
compare.key('date.updated', compare.date)(
{ id: '', date: { updated: new Date() } },
{ id: '', date: { updated: new Date() } }
{ id: '', date: { updated: new Date() } },
);
compare.key('date.pub.note')(
{ date: { pub: { note: 'yay' } } },
{ date: { pub: { note: 'yay' } } }
{ date: { pub: { note: 'yay' } } },
);

interface Example {
Expand Down
8 changes: 4 additions & 4 deletions src/core/compare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export function wildcard(x: any, y: any): number {

export function inspect(
x: Record<TS.IndexSignature, any>,
y: Record<TS.IndexSignature, any>
y: Record<TS.IndexSignature, any>,
): number {
const common = [...new Set([...Object.keys(x), ...Object.keys(y)])].filter(
(k) => k in x && k in y && typeof x[k] === typeof y[k] && x[k] !== y[k]
(k) => k in x && k in y && typeof x[k] === typeof y[k] && x[k] !== y[k],
);
for (
let i = 0, key = common[i], data = typeof x[key];
Expand All @@ -55,15 +55,15 @@ type KeyValidator<Keys, Expected> = Keys extends [infer I extends string, ...inf
: Expected;
export function key<
Inferred extends Record<TS.IndexSignature, any>,
Identifier extends keyof Inferred = TS.Paths<Inferred>
Identifier extends keyof Inferred = TS.Paths<Inferred>,
>(identifier: string & Identifier, comparator?: Wildcard) {
const trail = identifier.split('.');
const drill = (o: Inferred) => trail.reduce((ret, prop) => ret[prop], o);

type Properties = TS.Split<Identifier, '.'>;
return <X extends Inferred, Y extends Inferred>(
x: TS.WhenAny<keyof X, X, KeyValidator<Properties, X>>,
y: TS.WhenAny<keyof Y, Y, KeyValidator<Properties, Y>>
y: TS.WhenAny<keyof Y, Y, KeyValidator<Properties, Y>>,
) => (comparator || wildcard)(drill(x as Inferred), drill(y as Inferred));
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/lambda/pipe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pipe(name, cap, cap, split);
pipe(
(v: boolean) => +v,
(v: number) => (v > 0 ? 'y' : 'n'),
(v: string) => v === 'y'
(v: string) => v === 'y',
);

// ---- errors ----
Expand Down
2 changes: 1 addition & 1 deletion src/core/lambda/pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Last, UnaryFunction as Constraint } from '../../typings/helpers.js

type Validator<
Functions extends Constraint[],
Computed extends Constraint = (v: ReturnType<Functions[0]>) => ReturnType<Functions[1]>
Computed extends Constraint = (v: ReturnType<Functions[0]>) => ReturnType<Functions[1]>,
> = Functions extends [infer Resolved, infer _, ...infer Rest]
? Rest extends Constraint[]
? [Resolved, ...Validator<[Computed, ...Rest]>]
Expand Down
8 changes: 4 additions & 4 deletions src/core/standard/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ suites['identical/']('identical primitive checks', () => {
assert.ok(
std.identical(
() => {},
() => {}
)
() => {},
),
);
assert.ok(
std.identical(
() => '',
() => 0
)
() => 0,
),
);
});
suites['identical/']('identical array checks', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/standard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function capitalize(text: string, { cap, normalize }: CapitalizeOptions =
export function execute(
condition: boolean,
correct: () => AlsoPromise<void> | AnyFunction<[]>,
otherwise: () => AlsoPromise<void> | AnyFunction<[]> = () => {}
otherwise: () => AlsoPromise<void> | AnyFunction<[]> = () => {},
) {
condition ? correct() : otherwise();
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/standard/unique.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ suites['object/']('make array of object unique', () => {
{ id: 'ab', name: 'C' },
{ id: 'ef', name: 'D' },
],
'id'
'id',
),
[{ id: 'ab', name: 'A' }, { id: 'cd' }, { id: 'ef', name: 'B' }]
[{ id: 'ab', name: 'A' }, { id: 'cd' }, { id: 'ef', name: 'B' }],
);

assert.equal(
Expand All @@ -42,14 +42,14 @@ suites['object/']('make array of object unique', () => {
{ id: 'ef', name: { first: 'D' } },
{ id: 'hi', name: { last: 'wa' } },
],
'name.first'
'name.first',
),
[
{ id: 'ab', name: { first: 'A' } },
{ id: 'cd', name: { first: 'B' } },
{ id: 'ab', name: { first: 'C' } },
{ id: 'ef', name: { first: 'D' } },
]
],
);
});

Expand Down
2 changes: 1 addition & 1 deletion src/core/standard/unique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Paths } from '../../typings/prototypes.js';
*/
export default function unique<
Inferred extends Record<IndexSignature, any>,
Identifier extends Paths<Inferred>
Identifier extends Paths<Inferred>,
>(array: readonly Inferred[], key: string & Identifier): Inferred[];
export default function unique<T>(array: readonly T[]): T[];
export default function unique<T, I>(array: readonly T[], key?: string & I): T[] {
Expand Down
2 changes: 1 addition & 1 deletion src/core/temporal/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ suites['format/']('basic rendering', () => {

assert.equal(
`Valid from: [${renderer('YYYY-MM-DD ~ HH:mm:ss')}]`,
'Valid from: [2017-09-08 ~ 13:02:03]'
'Valid from: [2017-09-08 ~ 13:02:03]',
);
});
suites['format/']('throw on invalid date', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/std/csv/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { read } from './index.js';

test('parse csv edge cases correctly', () => {
const parsed = read(
'"1st col","2 w/ escaped """" double quotes""","3, w/, commas",4 w/ no quotes,"5 w/ CRLF\r\n"\r\n"1st col","2 w/ escaped """" double quotes""","3, w/, commas",4 w/ no quotes,"5 w/ CRLF\r\n"'
'"1st col","2 w/ escaped """" double quotes""","3, w/, commas",4 w/ no quotes,"5 w/ CRLF\r\n"\r\n"1st col","2 w/ escaped """" double quotes""","3, w/, commas",4 w/ no quotes,"5 w/ CRLF\r\n"',
);

const json = [
Expand Down
6 changes: 3 additions & 3 deletions src/std/ntv/array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ suites['arr/zip']('zip multiple arrays of objects', () => {
[{ a: 0 }, { x: 0 }],
[{ b: 0 }, { y: 0 }],
[{ c: 0 }, { z: 0 }],
[{ d: 0 }, { x: 1 }]
[{ d: 0 }, { x: 1 }],
);

assert.equal(zipped, [
Expand All @@ -29,7 +29,7 @@ suites['arr/zip']('zip multiple uneven arrays', () => {
[{ d: 0 }, { x: 1 }],
[null, null, { w: 0 }, { w: 0 }],
[null, null, { x: 0 }, { x: 0 }],
[null, null, { v: 1 }, { y: 0 }]
[null, null, { v: 1 }, { y: 0 }],
);

assert.equal(zipped, [
Expand All @@ -44,7 +44,7 @@ suites['arr/zip']('zip remove all nullish index', () => {
[{ a: 0 }, null, { x: 0 }, null, { a: 0 }, undefined],
[{ b: 0 }, null, { y: 0 }, undefined, { b: 0 }, null],
[{ c: 0 }, null, { z: 0 }, undefined, { c: 0 }, null],
[{ d: 0 }, null, { x: 1 }, null, { d: 0 }, undefined]
[{ d: 0 }, null, { x: 1 }, null, { d: 0 }, undefined],
);

assert.equal(zipped, [
Expand Down
12 changes: 6 additions & 6 deletions src/std/ntv/object.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ suites['obj/iterate']('iterate over nested objects', () => {

const statement = currencies.reduce(
(cs, c) => ({ ...cs, [c]: { income: 100, expense: 40 } }),
{} as { [k: string]: { income: number; expense: number } }
{} as { [k: string]: { income: number; expense: number } },
);
const nested = months.reduce(
(ms, m) => ({ ...ms, [m]: statement }),
{} as { [k: string]: typeof statement }
{} as { [k: string]: typeof statement },
);

assert.equal(
Expand All @@ -87,21 +87,21 @@ suites['obj/iterate']('iterate over nested objects', () => {
jpy: { balance: 60 },
};
return a;
}, {})
}, {}),
);
});
suites['obj/iterate']('iterate with empty/falsy return', () => {
assert.equal(
ntv.iterate({}, ([]) => {}),
{}
{},
);

assert.equal(
ntv.iterate(
{ a: '0', b: 1, c: null, d: '3', e: undefined, f: false },
([k, v]) => v != null && v !== false && [k, v]
([k, v]) => v != null && v !== false && [k, v],
),
{ a: '0', b: 1, d: '3' }
{ a: '0', b: 1, d: '3' },
);

type Nested = { [P in 'a' | 'b']?: { [K in 'x' | 'y']: { foo: string } } };
Expand Down
2 changes: 1 addition & 1 deletion src/std/ntv/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function iterate<T extends object, I = T[keyof T]>(
callback: AnyFunction<
[entry: Entries<T>[number], index: number],
void | Falsy | [IndexSignature, I]
> = ([k, v]) => [k, clone(v) as I]
> = ([k, v]) => [k, clone(v) as I],
): I extends T[keyof T] ? T : unknown {
const pairs = entries(object);
const memo: typeof pairs = [];
Expand Down
6 changes: 3 additions & 3 deletions src/std/tsf/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ test('parses template correctly', () => {
foo: 'hello',
bar: 'world',
}),
'/hello/world'
'/hello/world',
);
assert.equal(
r1({
foo: (v) => v,
bar: (v) => v,
}),
'/foo/bar'
'/foo/bar',
);
assert.equal(
r1({
foo: (v) => [...v].reverse().join(''),
bar: (v) => [...v].reverse().join(''),
}),
'/oof/rab'
'/oof/rab',
);
});

Expand Down
4 changes: 2 additions & 2 deletions src/std/tsf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function tsf<Input extends string>(
| `${string}{{${string}}${string}`
| `${string}{${string}}}${string}`
? 'Unbalanced braces detected in template'
: Input
: Input,
) {
const parts: string[] = [];
for (let i = 0, start = 0; i < template.length; i += 1) {
Expand All @@ -36,7 +36,7 @@ export function tsf<Input extends string>(
return function render(
table: Record<RequiredProps, AcceptedValues | UnaryFunction<string, AcceptedValues>> & {
[K in OptionalProps]?: AcceptedValues | UnaryFunction<string, AcceptedValues>;
}
},
) {
let transformed = '';
for (let i = 0; i < parts.length; i += 1) {
Expand Down
10 changes: 5 additions & 5 deletions src/typings/prototypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type IntersectUnion<U> = /** distributive conditional type */ (
/** Joins a list of string with custom delimiter */
export type Join<
StringList extends readonly string[],
Delimiter extends string = '-'
Delimiter extends string = '-',
> = StringList extends readonly [infer Head, infer Next, ...infer Rest]
? Join<
[`${Head & string}${Delimiter}${Next & string}`, ...Extract<Rest, readonly string[]>],
Expand Down Expand Up @@ -70,7 +70,7 @@ export type PartialOmit<
T,
Keys extends keyof T,
Saved = { [P in Exclude<keyof T, Keys>]: T[P] },
Final = Saved & { [P in keyof T]?: T[P] }
Final = Saved & { [P in keyof T]?: T[P] },
> = { [P in keyof Final]: Final[P] };

/**
Expand Down Expand Up @@ -105,15 +105,15 @@ export type SingleProperty<T> = {
/** Slices a list beginning from the starting index */
export type Slice<List extends any[], Start extends number = 0> = List extends [
...Extend<Start>,
...infer Sliced
...infer Sliced,
]
? Sliced
: [];

/** Splits a string with custom separator */
export type Split<
Key extends IndexSignature,
Separator extends string
Separator extends string,
> = Key extends `${infer Prefix}${Separator}${infer Rest}`
? [Prefix, ...Split<Rest, Separator>]
: [Key];
Expand All @@ -124,5 +124,5 @@ export type Split<
export type Tuple<
Size extends number,
T extends any[] = [],
Virtual extends any[] = []
Virtual extends any[] = [],
> = Virtual['length'] extends Size ? Virtual : Tuple<Size, T, [T, ...Virtual]>;
2 changes: 1 addition & 1 deletion src/web/navigator/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function copy(
handler: {
accept?(): AlsoPromise<void>;
reject?(): AlsoPromise<void>;
} = {}
} = {},
) {
const ncb = navigator.clipboard;

Expand Down
2 changes: 1 addition & 1 deletion src/web/query/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Flatten } from '../../typings/prototypes.js';
type CombineExisting<
A extends Record<IndexSignature, any>,
B extends Record<IndexSignature, any>,
Duplicate = Intersection<A, B>
Duplicate = Intersection<A, B>,
> = Omit<A, keyof Duplicate> &
Omit<B, keyof Duplicate> & {
[P in keyof Duplicate]: Flatten<[A[P], B[P]]>;
Expand Down
2 changes: 1 addition & 1 deletion src/web/query/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type BoundValues = Nullish | Primitives;
*/
export default function qse<T extends object>(
bound: T[keyof T] extends BoundValues | readonly BoundValues[] ? T : never,
transformer = (final: string) => `?${final}`
transformer = (final: string) => `?${final}`,
): string {
const enc = encodeURIComponent;

Expand Down

0 comments on commit eb66238

Please sign in to comment.