test/node_modules/@vuepress/plugin-blog/lib/node/store.js
2024-08-13 09:27:52 +08:00

31 lines
725 B
JavaScript

export class Store {
store;
constructor() {
this.store = [];
}
addItem(item) {
const index = this.store.indexOf(item);
if (index === -1) {
this.store.push(item);
return this.store.length - 1;
}
return index;
}
addItems(items) {
return items.map((item) => this.addItem(item));
}
clearItem(item) {
const index = this.store.indexOf(item);
if (index !== -1)
this.store[index] = '';
}
toJSON() {
return JSON.stringify(this.store);
}
}
export const prepareStore = async (app, store) => {
await app.writeTemp(`blog/store.js`, `\
export const store = ${store.toJSON()};
`);
};