Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/penpenpng/nostr-typedef

Type definitions for Nostr applications made with TypeScript
https://github.com/penpenpng/nostr-typedef

nostr type-definitions typedefs types

Last synced: 27 days ago
JSON representation

Type definitions for Nostr applications made with TypeScript

Awesome Lists containing this project

README

        

# nostr-typedef

**nostr-typedef** provides domain-specific type definitions (and useful doc comments) that are often needed to develop Nostr application with TypeScript.
It doesn't contain any implementations, but contains only type definitions.
Therefore, it doesn't affect the bundle size of your application at all.

## Installation

For example, if your product is a library and some applications may depend on it, the dependency must be declared in `dependencies` field.
In short, `-S` option is required.

```sh
npm install -S nostr-typedef
```

If not, that is, if your application is not depended on anything else, you can put the dependency in `devDependencies` field.

```sh
npm install -D nostr-typedef
```

## Example

```ts
import type * as Nostr from "nostr-typedef";

// OK. No type errors.
const message: Nostr.ToRelayMessage.REQ = ["REQ", "subId", { kinds: [0] }];

// NG. Required fields are missed so a type error occurs.
const event: Nostr.Event = {};
```

## Types

For a complete list, see [index.d.ts](./index.d.ts).

Particularly useful ones are listed below:

- types
- `Event`
- `UnsignedEvent`
- `EventParameters`
- `Filter`
- namespaces
- `Kind`
- `Tag`
- `Content`
- `ToRelayMessage`
- `ToClientMessage`
- `Nip07`
- `Nip11`