Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ jobs:
run: deno task lint-docs

- name: Format
run: deno fmt --check
run: deno task format-check

- name: Test
run: deno task test-coverage

- name: Generate Coverage
run: deno coverage --exclude='tests/' --lcov coverage/ >
run:
deno coverage --exclude='tests/' --lcov coverage/ >
coverage.lcov

- name: Publish Coverage
Expand Down
6 changes: 1 addition & 5 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"recommendations": [
"denoland.vscode-deno"
]
}
{ "recommendations": ["denoland.vscode-deno", "esbenp.prettier-vscode"] }
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"deno.enable": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"[yaml]": {
"editor.insertSpaces": true,
"editor.tabSize": 4,
"editor.autoIndent": "advanced",
"diffEditor.ignoreTrimWhitespace": false
}
},
"[typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }
}
20 changes: 2 additions & 18 deletions .zed/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
{
"format_on_save": "on",
"formatter": [
{
"code_action": "source.organizeImports"
},
"language_server"
],
"formatter": [{ "code_action": "source.organizeImports" }, "prettier"],
"languages": {
"JavaScript": {
"formatter": "language_server",
"language_servers": [
"deno",
"!typescript-language-server",
Expand All @@ -17,7 +11,6 @@
]
},
"TSX": {
"formatter": "language_server",
"language_servers": [
"deno",
"!typescript-language-server",
Expand All @@ -26,7 +19,6 @@
]
},
"TypeScript": {
"formatter": "language_server",
"language_servers": [
"deno",
"!typescript-language-server",
Expand All @@ -35,13 +27,5 @@
]
}
},
"lsp": {
"deno": {
"settings": {
"deno": {
"enable": true
}
}
}
}
"lsp": { "deno": { "settings": { "deno": { "enable": true } } } }
}
4 changes: 1 addition & 3 deletions .zed/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
{
"command": "deno test -A --filter '/^$ZED_CUSTOM_DENO_TEST_NAME$/' $ZED_FILE",
"label": "deno test",
"tags": [
"js-test"
]
"tags": ["js-test"]
}
]
11 changes: 5 additions & 6 deletions @coven/compare/FlatDifference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ import type { UpdateDifference } from "./UpdateDifference.ts";
* @see {@linkcode FlatPath}
* @see {@linkcode UpdateDifference}
*/
export type FlatDifference =
& (
| Omit<CreateDifference, "path">
| Omit<DeleteDifference, "path">
| Omit<UpdateDifference, "path">
)
export type FlatDifference = (
| Omit<CreateDifference, "path">
| Omit<DeleteDifference, "path">
| Omit<UpdateDifference, "path">
)
& FlatPath;
67 changes: 34 additions & 33 deletions @coven/compare/compareIterables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,38 @@ import { pathPrepend } from "./pathPrepend.ts";
* @param left Original iterable.
* @returns Curried generator with `left` in context.
*/
export const compareIterables = <LeftItem>(
left: Iterable<LeftItem>,
): CurriedComparison<Iterable<LeftItem>> =>
/**
* Curried {@linkcode compareIterables} with `left` set in context.
*
* @param right New iterable.
* @returns Generator with differences.
*/
(right) =>
iteratorFunctionToIterableIterator(function* (): Generator<Difference> {
const leftIterator = getIterator(left);
const rightIterator = getIterator(right);
export const compareIterables =
<LeftItem>(
left: Iterable<LeftItem>,
): CurriedComparison<Iterable<LeftItem>> =>
/**
* Curried {@linkcode compareIterables} with `left` set in context.
*
* @param right New iterable.
* @returns Generator with differences.
*/
(right) =>
iteratorFunctionToIterableIterator(function* (): Generator<Difference> {
const leftIterator = getIterator(left);
const rightIterator = getIterator(right);

for (
let index = 0,
{ done: leftDone = false, value: leftValue } = leftIterator
.next(),
{ done: rightDone = false, value: rightValue } = rightIterator
.next();
!(leftDone && rightDone);
index += 1,
{ done: leftDone = false, value: leftValue } = leftIterator
.next(),
{ done: rightDone = false, value: rightValue } = rightIterator
.next()
) {
yield* map(pathPrepend(index))(
compare(leftDone ? MISSING_VALUE : leftValue)(
rightDone ? MISSING_VALUE : rightValue,
),
);
}
});
for (
let index = 0,
{ done: leftDone = false, value: leftValue } =
leftIterator.next(),
{ done: rightDone = false, value: rightValue } =
rightIterator.next();
!(leftDone && rightDone);
index += 1,
{ done: leftDone = false, value: leftValue } =
leftIterator.next(),
{ done: rightDone = false, value: rightValue } =
rightIterator.next()
) {
yield* map(pathPrepend(index))(
compare(leftDone ? MISSING_VALUE : leftValue)(
rightDone ? MISSING_VALUE : rightValue,
),
);
}
});
31 changes: 15 additions & 16 deletions @coven/compare/compareObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,19 @@ export const compareObjects = (left: object): CurriedComparison<unknown> => {
const differentiateLeft = differentiate(left);
const isLeftConstructor = is(left.constructor);

return leftIsIterator
/**
* Curried {@linkcode compareObjects} with `left` set in context.
*
* @param right New object.
* @returns Generator with differences.
*/
? (right) =>
isLeft(right)
? EMPTY_ITERABLE_ITERATOR
: (isObject(right) && isLeftConstructor(right.constructor)
? isIterable(right)
? compareIterableLeft
: comparePropertiesLeft
: differentiateLeft)(right as Iterable<unknown>)
: comparePropertiesLeft;
return leftIsIterator ?
/**
* Curried {@linkcode compareObjects} with `left` set in context.
*
* @param right New object.
* @returns Generator with differences.
*/
(right) =>
isLeft(right) ?
EMPTY_ITERABLE_ITERATOR
: (isObject(right) && isLeftConstructor(right.constructor) ?
isIterable(right) ? compareIterableLeft
: comparePropertiesLeft
: differentiateLeft)(right as Iterable<unknown>)
: comparePropertiesLeft;
};
21 changes: 11 additions & 10 deletions @coven/compare/compareProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,22 @@ export const compareProperties = (left: object): CurriedComparison<unknown> => {
* @yields Differences.
*/
return (right) =>
isLeft(right) ? EMPTY_ITERABLE_ITERATOR : isObject(right)
? flat(
isLeft(right) ? EMPTY_ITERABLE_ITERATOR
: isObject(right) ?
flat(
map((key: string | symbol) =>
map(pathPrepend(key))(
compare(
key in left
? left[key as keyof typeof left]
: MISSING_VALUE,
key in left ?
left[key as keyof typeof left]
: MISSING_VALUE,
)(
key in right
? right[key as keyof typeof right]
: MISSING_VALUE,
key in right ?
right[key as keyof typeof right]
: MISSING_VALUE,
),
)
),
)(unique(append(getKeys(right))(ownKeysLeft))),
)
: differentiateLeft(right);
: differentiateLeft(right);
};
14 changes: 7 additions & 7 deletions @coven/compare/differentiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ export const differentiate = (left: unknown): CurriedComparison<unknown> => {
* @returns Difference object.
*/
return (right) =>
isLeft(right) ? EMPTY_ITERABLE_ITERATOR : toIterable({
...(right === MISSING_VALUE
? { left, kind: DELETE_KIND }
: left === MISSING_VALUE
? { kind: CREATE_KIND, right }
isLeft(right) ?
EMPTY_ITERABLE_ITERATOR
: toIterable({
...(right === MISSING_VALUE ? { left, kind: DELETE_KIND }
: left === MISSING_VALUE ? { kind: CREATE_KIND, right }
: { left, kind: UPDATE_KIND, right }),
path: EMPTY_ITERABLE_ITERATOR,
});
path: EMPTY_ITERABLE_ITERATOR,
});
};
16 changes: 8 additions & 8 deletions @coven/compare/getKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ export const getKeys = (object: object): IterableIterator<string | symbol> =>
> {
yield* Reflect.ownKeys(object);

hasPrototype(object)
? yield* Reflect.ownKeys(object.prototype)
: undefined;
hasPrototype(object) ?
yield* Reflect.ownKeys(object.prototype)
: undefined;

const constructor = object.constructor;

(
isObjectConstructor(constructor)
|| isFunctionConstructor(constructor)
)
? undefined
: yield* getKeys(constructor);
isObjectConstructor(constructor)
|| isFunctionConstructor(constructor)
) ?
undefined
: yield* getKeys(constructor);
}),
);
2 changes: 1 addition & 1 deletion @coven/compare/pathPrepend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { setPath } from "./setPath.ts";
*/
export const pathPrepend = (
property: PropertyKey,
): (difference: Difference) => Difference => {
): ((difference: Difference) => Difference) => {
const prependProperty = prepend([property]);

/**
Expand Down
Loading