Typscript konvertálása common javascriptre
2022-04-05T23:46:14+02:00
2022-04-11T13:04:56+02:00
2022-08-12T08:25:31+02:00
ShadowMember
Hello
Éppen próbálom a typescript kódot átirni common javascriptre, mert javascriptes hobby projektem van.

Ezt a részt nem tudom hogyan kell átirni common javascriptre:

getCredentials(): Array<{ account: string; password: string }> { return Object.entries(store.store).reduce((credentials, [account, buffer]) => { return [...credentials, { account, password: safeStorage.decryptString(Buffer.from(buffer, 'latin1')) }]; }, [] as Array<{ account: string; password: string }>); },
Innen van: Replacing Keytar with Electron's safeStorage in Ray - Freek Van der Herten's blog on PHP, Laravel and JavaScript

Eddig igy van nekem:

const { safeStorage } = require('electron'); const Store = require('electron-store'); const store = new Store({ name: 'idunfsa-encrypted', watch: true, encryptionKey: 'liJAwTiC5sHQZQ9gPpRNn8sQ3p', }); module.exports = { setPassword(key, password) { const buffer = safeStorage.encryptString(password); store.set(key, buffer.toString('latin1')); }, deletePassword(key) { store.delete(key); }, getCredentials(account) { return Object.entries(store.store).reduce((credentials, [account, buffer]) => { return [...credentials, { account, password: safeStorage.decryptString(Buffer.from(buffer, 'latin1')) }]; }, }


De viszont a getCredentials valahogy nem működik. Próbáltam google-zni, de semmi siker.
Köszönöm előre is a válaszokat.
Mutasd a teljes hozzászólást!
Feltételezve a következő definíciókat:

class Store<T> { store!: T; constructor(arg: {name: string, watch: boolean, encryptionKey: string}) { } set(key: string, arg: string) { } delete(key: string) { } } class Buffer { toString(arg: string) : string { return ""; } static from(arg1: Buffer, arg2: string) : Buffer { return new Buffer; } } const safeStorage = class { static encryptString(arg: string) : Buffer { return new Buffer; } static decryptString(arg: Buffer) : string { return ""; } }
A getCredentials helyes alakja ez:

getCredentials() { return Object.entries(store.store).reduce((credentials, [account, buffer]) => { return [...credentials, { account, password: safeStorage.decryptString(Buffer.from(buffer, 'latin1')) }]; }, []); }
Mutasd a teljes hozzászólást!

abcd