0.2.7 • Published 8 months ago

sk-lanyard v0.2.7

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

sk-lanyard (SvelteKit + Lanyard)

SvelteKit integration with Lanyard, an API to fetch your Discord presence.

sk-lanyard is fully typed and supports the entire Lanyard API, using both REST and WebSockets.

The useLanyard function returns a reactive store containing presence data.

Demo

<script>
	import { useLanyard } from 'sk-lanyard';
	const presence = useLanyard({ method: 'rest', id: '524722785302609941' });
</script>

<pre>
    <!-- Because presence is a reactive store, use $presence to access the data -->
    <code>{JSON.stringify($presence ?? {}, null, 2)}</code>
</pre>

Usage

import { useLanyard } from 'sk-lanyard';

// Optionally import Lanyard types
import type { LanyardData, LanyardHello } from 'sk-lanyard';

REST

// Use the REST API to fetch a single user
const lanyard = useLanyard({ method: 'rest', id: '524722785302609941' });
// Use an interval of 1000 ms
const lanyard = useLanyard({
	method: 'rest',
	pollInterval: 1000,
	id: '524722785302609941'
});
// Use a custom endpoint
const lanyard = useLanyard({
	method: 'rest',
	restUrl: 'https://lanyard.example.com/rest',
	id: '524722785302609941'
});

WebSockets

// Use the WebSockets API to subscribe to a single user
const lanyard = useLanyard({ method: 'ws', id: '524722785302609941' });
// Subscribe to multiple users
const lanyard = useLanyard({
	method: 'ws',
	ids: ['524722785302609941', '299707523370319883']
});
// Subscribe to all users tracked by Lanyard
const lanyard = useLanyard({ method: 'ws', all: true });
// Use a custom endpoint
const lanyard = useLanyard({
	method: 'ws',
	wsUrl: 'wss://lanyard.example.com/ws',
	id: '524722785302609941'
});
0.2.1

8 months ago

0.2.0

8 months ago

0.2.7

8 months ago

0.2.6

8 months ago

0.2.3

8 months ago

0.2.2

8 months ago

0.2.5

8 months ago

0.2.4

8 months ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago