UNPKG

@credo-ts/core

Version:

<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1

33 lines (32 loc) • 1.34 kB
//#region src/modules/w3c-di/proof-processing/normalization.ts /** * Returns true when the value is a plain record-like object that can be safely * traversed and rebuilt during Data Integrity boundary normalization. */ function isPlainObject(value) { if (value === null || typeof value !== "object") return false; const prototype = Object.getPrototypeOf(value); return prototype === Object.prototype || prototype === null; } /** * JavaScript permits object properties to be set to `undefined`, but `undefined` * is not part of the JSON data model used by Data Integrity processing. * * Recursively removes properties whose value is `undefined` from plain-object * inputs before canonicalization. * * Arrays are preserved and normalized element-by-element so that only object * fields are omitted at the service boundary before cryptosuite processing. */ function omitUndefinedFields(value) { if (Array.isArray(value)) return value.map((item) => omitUndefinedFields(item)); if (!isPlainObject(value)) return value; const normalizedEntries = Object.entries(value).flatMap(([key, nestedValue]) => { if (nestedValue === void 0) return []; return [[key, omitUndefinedFields(nestedValue)]]; }); return Object.fromEntries(normalizedEntries); } //#endregion export { omitUndefinedFields }; //# sourceMappingURL=normalization.mjs.map