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,GAAG,CAAC,KAAK,CAAC,CAAC;YACxB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE;gBAC1B,oBAAoB,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;aAChD;SACJ;KACJ;SAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE;QAChD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAC,GAAG;YACzB,IAAI,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;gBACzB,IAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;gBACtB,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE;oBAC1B,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;iBAC9C;aACJ;QACL,CAAC,CAAC,CAAC;KACN;AACL,CAAC;AAED,SAAgB,mBAAmB,CAE/B,GAAQ,EAER,IAAwD;IAExD,oBAAoB,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAC1D,CAAC;AAPD,kDAOC","sourcesContent":["// ==LICENSE-BEGIN==\n// Copyright 2017 European Digital Reading Lab. All rights reserved.\n// Licensed to the Readium Foundation under one or more contributor license agreements.\n// Use of this source code is governed by a BSD-style license\n// that can be found in the LICENSE file exposed on Github (readium) in the project repository.\n// ==LICENSE-END==\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ninterface IStringKeyedObject { [key: string]: any; }\n\nexport function isNullOrUndefined<T>(val: T | undefined | null): val is T {\n // typeof val === \"undefined\" useful if val not declared (avoids ReferenceError throw)\n // val == undefined loose equality => good for both null and undefined\n // val === undefined srict equality => good for undefined only\n // note that if val === null, typeof val === \"object\"\n // whereas if val === undefined, typeof val === \"undefined\"\n return val === undefined || val === null;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function sortObject(obj: any): any {\n if (obj === null) {\n return null;\n }\n if (obj instanceof Array) {\n for (let i = 0; i < obj.length; i++) {\n obj[i] = sortObject(obj[i]);\n }\n return obj;\n } else if (typeof obj !== \"object\") { // || obj === null\n return obj;\n }\n\n const newObj: IStringKeyedObject = {};\n\n Object.keys(obj).sort().forEach((key) => {\n newObj[key] = sortObject(obj[key]);\n });\n\n return newObj;\n}\n\nfunction traverseJsonObjects_(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n parent: any, keyInParent: any, obj: any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n func: (item: any, parent: any, keyInParent: any) => void) {\n\n func(obj, parent, keyInParent);\n\n if (obj instanceof Array) {\n for (let index = 0; index < obj.length; index++) {\n const item = obj[index];\n if (!isNullOrUndefined(item)) {\n traverseJsonObjects_(obj, index, item, func);\n }\n }\n } else if (typeof obj === \"object\" && obj !== null) {\n Object.keys(obj).forEach((key) => {\n if (obj.hasOwnProperty(key)) {\n const item = obj[key];\n if (!isNullOrUndefined(item)) {\n traverseJsonObjects_(obj, key, item, func);\n }\n }\n });\n }\n}\n\nexport function traverseJsonObjects(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n obj: any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n func: (item: any, parent: any, keyInParent: any) => void) {\n\n traverseJsonObjects_(undefined, undefined, obj, func);\n}\n"]}
\No newline at end of file