Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cawa-93 committed Dec 24, 2022
0 parents commit 4ee6224
Show file tree
Hide file tree
Showing 11 changed files with 2,539 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom: https://www.buymeacoffee.com/kozack/
14 changes: 14 additions & 0 deletions .github/renovate.json
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)"
]
}
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/electron-nano-store.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions README.md
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/'
})
```
Loading

0 comments on commit 4ee6224

Please sign in to comment.