Skip to content

Commit

Permalink
Fix loading settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaoumov committed Jul 17, 2024
1 parent 753b88b commit 7fa7b93
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/BetterMarkdownLinksPluginSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ export default class BetterMarkdownLinksPluginSettings {
public automaticallyConvertNewLinks = true;
public ignoreIncompatibleObsidianSettings: boolean = false;

public static load(value: unknown): BetterMarkdownLinksPluginSettings {
if (!value) {
return new BetterMarkdownLinksPluginSettings();
}

return value as BetterMarkdownLinksPluginSettings;
public static load(data: unknown): BetterMarkdownLinksPluginSettings {
return BetterMarkdownLinksPluginSettings.clone(data as BetterMarkdownLinksPluginSettings);
}

public static clone(settings?: BetterMarkdownLinksPluginSettings): BetterMarkdownLinksPluginSettings {
return Object.assign(new BetterMarkdownLinksPluginSettings(), settings);
const target = new BetterMarkdownLinksPluginSettings();
if (settings) {
for (const key of Object.keys(target) as Array<keyof BetterMarkdownLinksPluginSettings>) {
if (key in settings && typeof settings[key] === typeof target[key]) {
target[key] = settings[key];
}
}
}

return target;
}
}

0 comments on commit 7fa7b93

Please sign in to comment.