https://github.com/synonymdev/slashtags-profile
Slashtags Profiles library
https://github.com/synonymdev/slashtags-profile
Last synced: 9 months ago
JSON representation
Slashtags Profiles library
- Host: GitHub
- URL: https://github.com/synonymdev/slashtags-profile
- Owner: synonymdev
- License: mit
- Archived: true
- Created: 2023-04-14T09:58:31.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-06T03:44:43.000Z (over 2 years ago)
- Last Synced: 2025-05-18T13:02:03.036Z (11 months ago)
- Language: JavaScript
- Size: 33.2 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slashtags-profile
Slashtags Profile helper module.
## Install
```bash
npm install @synonymdev/slashtags-profile
```
## Usage
Initialize
```js
const { Client } = require('@synonymdev/web-relay')
const SlashtagsProfile = require('@synonymdev/slashtags-profile')
const client = new Client({ storage: "path/to/storage", relay: address })
const writer = new SlashtagsProfile(client)
const profile = { name: 'foo' }
await writer.put(profile)
const url = await writer.createURL()
```
Resolve profile as a reader
```js
const { Client } = require('@synonymdev/web-relay')
const SlashtagsProfile = require('@synonymdev/slashtags-profile')
const client = new Client({ storage: "path/to/storage "})
const reader = new SlashtagsProfile(client)
const resolved = await reader.get(url) // URL from writer side
// {name: 'foo'}
```
## API
#### `const profile = new SlashtagsProfile(WebRelayClient)`
Create a new SlashtagsProfile instance.
- `WebRelayClient` [slashtags-web-relay](https://github.com/slashtags/web-relay) instance.
#### `const url = await profile.createURL()`
Creates a sharable `url` to allow remote readers to read this profile.
#### `await profile.close()`
Closes the underlying web relay client.
#### `await profile.put(profile)`
Puts a new profile value. `profile` param should be an object following its type definition.
#### `await profile.del()`
Deletes the value from the underlying hyperdrive.
#### `await profile.get([url])`
Read a local profile if no `url` is passed, or a remote one if `url` is passed.
#### `await profile.subscribe(url, onupdate)`
Watch updates to a remote file, and call `onupdate(profile)` function with current profile.