Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
devjmetivier committed Dec 28, 2024
1 parent b680270 commit 3d2463b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/all-primitives.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KeyDictionary, type KeyPrefixConfig } from 'typekey';
import { KeyDictionary, type KeyPrefixConfig } from '@delicious-simplicity/typekey';

const dict = {
boolean: ['value'] as const,
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KeyDictionary, type KeyPrefixConfig } from 'typekey';
import { KeyDictionary, type KeyPrefixConfig } from '@delicious-simplicity/typekey';

const dict = {
user: ['id'] as const,
Expand Down
16 changes: 16 additions & 0 deletions examples/next-fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { KeyDictionary, type KeyPrefixConfig } from '@delicious-simplicity/typekey';

const dict = {
user: ['id'] as const,
} satisfies KeyPrefixConfig;

const keyDictionary = new KeyDictionary(dict);

keyDictionary.generateKey('user', { id: 1 });
// => 'user:["1"]'

fetch('https://api.example.com', {
next: {
tags: [keyDictionary.generateKey('user', { id: 1 })],
},
});
2 changes: 1 addition & 1 deletion examples/with-key-length-options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KeyDictionary, type KeyDictionaryOptions, type KeyPrefixConfig } from 'typekey';
import { KeyDictionary, type KeyDictionaryOptions, type KeyPrefixConfig } from '@delicious-simplicity/typekey';

const dict = {
user: ['id'] as const,
Expand Down
2 changes: 1 addition & 1 deletion examples/with-throw-option.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KeyDictionary, type KeyDictionaryOptions, type KeyPrefixConfig } from 'typekey';
import { KeyDictionary, type KeyDictionaryOptions, type KeyPrefixConfig } from '@delicious-simplicity/typekey';

const dict = {
user: ['id'] as const,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"license": "MIT",
"main": "dist/index.js",
"name": "@delicious-simplicity/typekey",
"private": false,
"repository": {
"type": "git",
"url": "git+https://github.com/delicious-simplicity/typekey.git"
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ A TypeScript library for generating consistent, type-safe cache keys from a stru
import { KeyDictionary, type KeyPrefixConfig } from "typekey";

const dict = {
user: ["id"] as const,
user: ["id"] as const, // must declare parameters `as const` for type safety
} satisfies KeyPrefixConfig;

const keyDictionary = new KeyDictionary(dict);

keyDictionary.generateKey("user", { id: 1 });
keyDictionary.generateKey("user", { id: 1 }); // `id` parameter has intellisense 🎉
// => 'user:["1"]'
```

Expand All @@ -46,7 +46,7 @@ Generates cache keys based on a provided configuration of prefixes and parameter
Generates a cache key for the specified prefix with itsz parameters.

- `prefix` (required): The prefix to use for the generated key. Must be one of the keys from the `config` object passed to the constructor.
- `params` (required): An object containing the parameter values for the specified prefix. The parameter names must match those defined in the `config` object for the given prefix.
- `params` (required): An object containing the parameter values for the specified prefix. The parameter names must match those defined in the `config` object for the given prefix. Parameters must be declared `as const` in order to preserve type safety.

Returns: The generated cache key as a string.

Expand Down

0 comments on commit 3d2463b

Please sign in to comment.