mya/node_modules/@capacitor/preferences/dist/plugin.js
Fabio Micheluz 04b045714b
Some checks are pending
Build Android APK / build (push) Waiting to run
android ok
2026-01-22 11:28:12 +01:00

88 lines
2.9 KiB
JavaScript

var capacitorPreferences = (function (exports, core) {
'use strict';
const Preferences = core.registerPlugin('Preferences', {
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.PreferencesWeb()),
});
class PreferencesWeb extends core.WebPlugin {
constructor() {
super(...arguments);
this.group = 'CapacitorStorage';
}
async configure({ group }) {
if (typeof group === 'string') {
this.group = group;
}
}
async get(options) {
const value = this.impl.getItem(this.applyPrefix(options.key));
return { value };
}
async set(options) {
this.impl.setItem(this.applyPrefix(options.key), options.value);
}
async remove(options) {
this.impl.removeItem(this.applyPrefix(options.key));
}
async keys() {
const keys = this.rawKeys().map((k) => k.substring(this.prefix.length));
return { keys };
}
async clear() {
for (const key of this.rawKeys()) {
this.impl.removeItem(key);
}
}
async migrate() {
var _a;
const migrated = [];
const existing = [];
const oldprefix = '_cap_';
const keys = Object.keys(this.impl).filter((k) => k.indexOf(oldprefix) === 0);
for (const oldkey of keys) {
const key = oldkey.substring(oldprefix.length);
const value = (_a = this.impl.getItem(oldkey)) !== null && _a !== void 0 ? _a : '';
const { value: currentValue } = await this.get({ key });
if (typeof currentValue === 'string') {
existing.push(key);
}
else {
await this.set({ key, value });
migrated.push(key);
}
}
return { migrated, existing };
}
async removeOld() {
const oldprefix = '_cap_';
const keys = Object.keys(this.impl).filter((k) => k.indexOf(oldprefix) === 0);
for (const oldkey of keys) {
this.impl.removeItem(oldkey);
}
}
get impl() {
return window.localStorage;
}
get prefix() {
return this.group === 'NativeStorage' ? '' : `${this.group}.`;
}
rawKeys() {
return Object.keys(this.impl).filter((k) => k.indexOf(this.prefix) === 0);
}
applyPrefix(key) {
return this.prefix + key;
}
}
var web = /*#__PURE__*/Object.freeze({
__proto__: null,
PreferencesWeb: PreferencesWeb
});
exports.Preferences = Preferences;
return exports;
})({}, capacitorExports);
//# sourceMappingURL=plugin.js.map