mirror of
https://github.com/spacebarchat/server.git
synced 2026-10-23 13:03:08 +00:00
Delete Object.map
This commit is contained in:
1 parent
319b420fc0
commit
54540a8b14
5 files changed
+9
-51
No files matched your search
@@ -31,7 +31,7 @@ export function FieldErrors(fields: Record<string, { code?: string; message: str
|
||||
return new FieldError(
|
||||
50035,
|
||||
"Invalid Form Body",
|
||||
fields.map<ErrorContent, ObjectErrorContent>(({ message, code }) => ({
|
||||
Object.values(fields).map(({ message, code }) => ({
|
||||
_errors: [
|
||||
{
|
||||
message,
|
||||
@@ -39,7 +39,7 @@ export function FieldErrors(fields: Record<string, { code?: string; message: str
|
||||
},
|
||||
],
|
||||
})),
|
||||
errors
|
||||
errors,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export class FieldError extends Error {
|
||||
public code: string | number,
|
||||
public message: string,
|
||||
public errors?: object, // TODO: I don't like this typing.
|
||||
public _ajvErrors?: ErrorObject[]
|
||||
public _ajvErrors?: ErrorObject[],
|
||||
) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import moduleAlias from "module-alias";
|
||||
moduleAlias();
|
||||
import "./Object";
|
||||
import { describe, it } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
describe("Object extensions", () => {
|
||||
it("map", async () => {
|
||||
const obj = { a: 1, b: 2, c: 3 };
|
||||
const result = obj.map((value, key) => `${key}:${value}`);
|
||||
assert.deepEqual(result, { a: "a:1", b: "b:2", c: "c:3" });
|
||||
});
|
||||
});
|
||||
@@ -1,25 +0,0 @@
|
||||
declare global {
|
||||
interface Object {
|
||||
map<SV, TV>(callback: (value: SV, key: string, object: { [index: string]: SV }) => TV): { [index: string]: TV };
|
||||
}
|
||||
}
|
||||
|
||||
export function objectMap<SV, TV>(srcObj: { [index: string]: SV }, callback: (value: SV, key: string, object: { [index: string]: SV }) => TV): { [index: string]: TV } {
|
||||
if (typeof callback !== "function") throw new TypeError(`${callback} is not a function`);
|
||||
const obj: { [index: string]: TV } = {};
|
||||
Object.keys(srcObj).forEach((key) => {
|
||||
obj[key] = callback(srcObj[key], key, srcObj);
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (!Object.prototype.map)
|
||||
Object.defineProperty(Object.prototype, "map", {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-expect-error
|
||||
value: function (cb) {
|
||||
return objectMap(this, cb);
|
||||
},
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
});
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from "./Array";
|
||||
export * from "./Math";
|
||||
export * from "./Url";
|
||||
export * from "./Object";
|
||||
export * from "./String";
|
||||
export * from "./String";
|
||||
Reference in new issue
Block a user