Skip to content

Commit

Permalink
chore: transpile
Browse files Browse the repository at this point in the history
  • Loading branch information
k0stik committed May 30, 2024
1 parent 3c4298e commit 608d8eb
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 10 deletions.
8 changes: 4 additions & 4 deletions dist/js/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as array from "./shared/array";
import * as assertion from "./shared/assertion";
import * as cls from "./shared/class";
import * as clone from "./shared/clone";
import * as compare from "./shared/compare";
import * as constants from "./shared/constants";
import * as hash from "./shared/hash";
import * as math from "./shared/math";
Expand All @@ -26,7 +26,7 @@ export declare const sharedUtils: {
tree: typeof tree;
url: typeof url;
uuid: typeof uuid;
compare: typeof compare;
assertion: typeof assertion;
};
export declare const Utils: {
array: typeof array;
Expand All @@ -42,7 +42,7 @@ export declare const Utils: {
tree: typeof tree;
url: typeof url;
uuid: typeof uuid;
compare: typeof compare;
assertion: typeof assertion;
};
declare const _default: {
array: typeof array;
Expand All @@ -58,6 +58,6 @@ declare const _default: {
tree: typeof tree;
url: typeof url;
uuid: typeof uuid;
compare: typeof compare;
assertion: typeof assertion;
};
export default _default;
4 changes: 2 additions & 2 deletions dist/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ var __importStar =
Object.defineProperty(exports, "__esModule", { value: true });
exports.Utils = exports.sharedUtils = void 0;
const array = __importStar(require("./shared/array"));
const assertion = __importStar(require("./shared/assertion"));
const cls = __importStar(require("./shared/class"));
const clone = __importStar(require("./shared/clone"));
const compare = __importStar(require("./shared/compare"));
const constants = __importStar(require("./shared/constants"));
const hash = __importStar(require("./shared/hash"));
const math = __importStar(require("./shared/math"));
Expand All @@ -70,7 +70,7 @@ exports.sharedUtils = {
tree,
url,
uuid,
compare,
assertion,
};
exports.Utils = exports.sharedUtils;
exports.default = { ...exports.Utils };
4 changes: 2 additions & 2 deletions dist/js/index_browser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export declare const Utils: {
tree: typeof import("./shared/tree");
url: typeof import("./shared/url");
uuid: typeof import("./shared/uuid");
compare: typeof import("./shared/compare");
assertion: typeof import("./shared/assertion");
};
declare const _default: {
codemirror: typeof codemirror;
Expand All @@ -34,6 +34,6 @@ declare const _default: {
tree: typeof import("./shared/tree");
url: typeof import("./shared/url");
uuid: typeof import("./shared/uuid");
compare: typeof import("./shared/compare");
assertion: typeof import("./shared/assertion");
};
export default _default;
4 changes: 2 additions & 2 deletions dist/js/index_server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export declare const Utils: {
tree: typeof import("./shared/tree");
url: typeof import("./shared/url");
uuid: typeof import("./shared/uuid");
compare: typeof import("./shared/compare");
assertion: typeof import("./shared/assertion");
};
declare const _default: {
file: typeof file;
Expand All @@ -34,6 +34,6 @@ declare const _default: {
tree: typeof import("./shared/tree");
url: typeof import("./shared/url");
uuid: typeof import("./shared/uuid");
compare: typeof import("./shared/compare");
assertion: typeof import("./shared/assertion");
};
export default _default;
6 changes: 6 additions & 0 deletions dist/js/shared/assertion.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export declare function assertShallowDeepAlmostEqual(
expect?: object | boolean | number | null | string | Date,
actual?: object | boolean | number | null | string | Date,
path?: string,
threshold?: number,
): boolean;
70 changes: 70 additions & 0 deletions dist/js/shared/assertion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertShallowDeepAlmostEqual = void 0;
function assertShallowDeepAlmostEqual(expect, actual, path = "", threshold = 0.01) {
// null value
if (expect === null) {
if (!(actual === null)) {
throw new Error(`Expected to have null but got "${actual}" at path "${path}".`);
}
return true;
}
// undefined expected value
if (typeof expect === "undefined") {
if (typeof actual !== "undefined") {
throw new Error(`Expected to have undefined but got "${actual}" at path "${path}".`);
}
return true;
}
// scalar description
if (typeof expect === "boolean" || typeof expect === "string") {
if (expect !== actual) {
throw new Error(`Expected to have "${expect}" but got "${actual}" at path "${path}".`);
}
return true;
}
// numbers — here is some important 'almost equal' stuff
// TODO: configurable threshold
if (typeof expect === "number") {
if (typeof actual !== "number") {
throw new Error(`Expected to have number but got "${actual}" at path "${path}".`);
}
if (Math.abs(expect - actual) > threshold) {
throw new Error(
`Expected to have "${expect}+-${threshold}" but got "${actual}" at path "${path}".`,
);
}
return true;
}
// dates
if (expect instanceof Date) {
if (actual instanceof Date) {
if (expect.getTime() !== actual.getTime()) {
throw new Error(
`Expected to have date "${expect.toISOString()}" but got "${actual.toISOString()}" at path "${path}".`,
);
}
} else {
throw new Error(
`Expected to have date "${expect.toISOString()}" but got "${actual}" at path "${path}".`,
);
}
return true;
}
if (actual === null) {
throw new Error(`Expected to have an array/object but got null at path "${path}".`);
}
// array/object description
// eslint-disable-next-line no-restricted-syntax, guard-for-in
for (const prop in expect) {
// @ts-ignore
if (typeof actual[prop] === "undefined" && typeof expect[prop] !== "undefined") {
throw new Error(`Expected "${prop}" field to be defined at path "${path}".`);
}
const newPath = path + (path === "/" ? "" : "/") + prop;
// @ts-ignore
shallowDeepAlmostEqual(expect[prop], actual[prop], newPath, threshold);
}
return true;
}
exports.assertShallowDeepAlmostEqual = assertShallowDeepAlmostEqual;

0 comments on commit 608d8eb

Please sign in to comment.