文件
mynode/packages/utils/object.ts
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

24 行
1.0 KiB
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 -- Generic utility used by callers with typed entity interfaces (NoteEntity, FolderEntity, etc.) that lack an index signature; tightening this would require widening every caller's argument.
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);
};