You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2026-04-24 19:55:13 +02:00
24 lines
891 B
TypeScript
24 lines
891 B
TypeScript
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
|
export const objectValueFromPath = (o: any, path: string) => {
|
|
const elements = path.split('.');
|
|
let result = { ...o };
|
|
while (elements.length && result) {
|
|
const e = elements.splice(0, 1)[0];
|
|
result = result[e];
|
|
}
|
|
return result;
|
|
};
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
|
export function checkObjectHasProperties(object: any, properties: string[]) {
|
|
for (const prop of properties) {
|
|
if (!(prop in object)) throw new Error(`Missing property "${prop}": ${JSON.stringify(object)}`);
|
|
}
|
|
}
|
|
|
|
export const hasOwnProperty = <T extends object, Property extends string>(
|
|
object: T, property: Property,
|
|
): object is T & Record<Property, unknown> => {
|
|
return !!object && Object.prototype.hasOwnProperty.call(object, property);
|
|
};
|