MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / object

Function object

lib.commonjs/providers/format.js:36–62  ·  view source on GitHub ↗
(format, altNames)

Source from the content-addressed store, hash-verified

34// Any FormatFunc may return `undefined` to have the value omitted
35// from the result object. Calls preserve `this`.
36function object(format, altNames) {
37 return ((value) => {
38 const result = {};
39 for (const key in format) {
40 let srcKey = key;
41 if (altNames && key in altNames && !(srcKey in value)) {
42 for (const altKey of altNames[key]) {
43 if (altKey in value) {
44 srcKey = altKey;
45 break;
46 }
47 }
48 }
49 try {
50 const nv = format[key](value[srcKey]);
51 if (nv !== undefined) {
52 result[key] = nv;
53 }
54 }
55 catch (error) {
56 const message = (error instanceof Error) ? error.message : "not-an-error";
57 (0, index_js_4.assert)(false, `invalid value for value.${key} (${message})`, "BAD_DATA", { value });
58 }
59 }
60 return result;
61 });
62}
63exports.object = object;
64function formatBoolean(value) {
65 switch (value) {

Callers 2

format.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected