-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4ee6224
Showing
11 changed files
with
2,539 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
custom: https://www.buymeacoffee.com/kozack/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": [ | ||
"config:base", | ||
":semanticCommits", | ||
":semanticCommitTypeAll(deps)", | ||
":semanticCommitScopeDisabled", | ||
":automergeAll", | ||
":automergeBranch", | ||
":disableDependencyDashboard", | ||
":pinVersions", | ||
":onlyNpm", | ||
":label(dependencies)" | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[![Stand With Ukraine](https://raw.github.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://stand-with-ukraine.pp.ua) | ||
|
||
--- | ||
|
||
# Nano Electron store | ||
<a href="https://www.buymeacoffee.com/kozack" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-red.png" alt="Buy Me A Coffee" style="height: 60px !important;" ></a> | ||
|
||
A simple, super minimalistic data store on a file system with TypeScript support. This package is flat wrapper around [fs-nano-store](https://github.com/cawa-93/fs-nano-store) and automatically resolves the path to the user data directory. | ||
|
||
## Usage | ||
|
||
```ts | ||
// In Electron Preload Script | ||
import {defineStore} from "electron-nano-store"; | ||
import {contextBridge} from 'electron' | ||
|
||
/** | ||
* Declare types for you storage | ||
*/ | ||
interface UserStore { | ||
name: string, | ||
role: 'admin' | 'user' | ||
} | ||
|
||
contextBridge.exposeInMainWorld('userStorePromise', defineStore<UserStore>('user')) | ||
``` | ||
```ts | ||
// Somewhere in the renderer context of your application | ||
|
||
// Tell typesctipt about store | ||
declare global { | ||
interface Window { | ||
userStorePromise: Promise<TNanoStore<UserStore>> | ||
} | ||
} | ||
|
||
// Use it | ||
const {get, set} = await window.userStorePromise | ||
get('role') // 'admin' | 'user' | ||
set('name', 123) // Type error: Argument of type number is not assignable to parameter of type string | ||
``` | ||
|
||
## Data location | ||
By default all data saving in user data dir - This is usually the path returned by `electron.app.getPath('userData')`. You can change this by setting custom path: | ||
|
||
```ts | ||
import {defineStore} from "./index"; | ||
|
||
defineStore('store-name', { | ||
userDataPath: '/path/to/custom/dir/' | ||
}) | ||
``` |
Oops, something went wrong.