Skip to content

Commit

Permalink
chore: deno fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-shuman committed Dec 24, 2023
1 parent aabb196 commit 1bcfc8a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 33 deletions.
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,35 @@
## Why?

I plan on building a minimal adless version of [wordle](https://en.wikipedia.org/wiki/Wordle) and wanted to open source the logic.
I plan on building a minimal adless version of
[wordle](https://en.wikipedia.org/wiki/Wordle) and wanted to open source the
logic.

### Getting started

This module exports a single `wordle()` function which exports [nanostores](https://github.com/nanostores/nanostores) and an `attempt()` function to test words.
This module exports a single `wordle()` function which exports
[nanostores](https://github.com/nanostores/nanostores) and an `attempt()`
function to test words.

- `word`: a nanostore which holds the current game's word
- `attempts`: a nanostore which holds the current game's guesses
- `attempt()`: a function which takes in a single string and returns an object with a `error?: WordleError` property.
- `attempt()`: a function which takes in a single string and returns an object
with a `error?: WordleError` property.

### Errors

The `attempt()` function will return an object with an `error?: WordleError` property if the attempt failed for any reason. Common errors are (for an exhaustive list see [mod.ts](./mod.ts)):

- `"max_attempts_reached"`: the game is already over since the number of attempts has reached `options?.maxAttempts` (6 by default)
- `"too_few_characters"`: the attempted word has less characters then the current word
- `"too_many_characters"`: the attempted word has more characters then the current word
- `"invalid_attempt"`: the attempt did not pass the `options?.validateAttempt()` function
The `attempt()` function will return an object with an `error?: WordleError`
property if the attempt failed for any reason. Common errors are (for an
exhaustive list see [mod.ts](./mod.ts)):

- `"max_attempts_reached"`: the game is already over since the number of
attempts has reached `options?.maxAttempts` (6 by default)
- `"too_few_characters"`: the attempted word has less characters then the
current word
- `"too_many_characters"`: the attempted word has more characters then the
current word
- `"invalid_attempt"`: the attempt did not pass the `options?.validateAttempt()`
function

## Tasks

Expand Down
29 changes: 20 additions & 9 deletions README.node.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,32 @@
## Why?

I plan on building a minimal adless version of [wordle](https://en.wikipedia.org/wiki/Wordle) and wanted to open source the logic.
I plan on building a minimal adless version of
[wordle](https://en.wikipedia.org/wiki/Wordle) and wanted to open source the
logic.

### Getting started

This module exports a single `wordle()` function which exports [nanostores](https://github.com/nanostores/nanostores) and an `attempt()` function to test words.
This module exports a single `wordle()` function which exports
[nanostores](https://github.com/nanostores/nanostores) and an `attempt()`
function to test words.

- `word`: a nanostore which holds the current game's word
- `attempts`: a nanostore which holds the current game's guesses
- `attempt()`: a function which takes in a single string and returns an object with a `error?: WordleError` property.
- `attempt()`: a function which takes in a single string and returns an object
with a `error?: WordleError` property.

### Errors

The `attempt()` function will return an object with an `error?: WordleError` property if the attempt failed for any reason. Common errors are (for an exhaustive list see [./src/mod.ts](./mod.ts)):

- `"max_attempts_reached"`: the game is already over since the number of attempts has reached `options?.maxAttempts` (6 by default)
- `"too_few_characters"`: the attempted word has less characters then the current word
- `"too_many_characters"`: the attempted word has more characters then the current word
- `"invalid_attempt"`: the attempt did not pass the `options?.validateAttempt()` function
The `attempt()` function will return an object with an `error?: WordleError`
property if the attempt failed for any reason. Common errors are (for an
exhaustive list see [./src/mod.ts](./mod.ts)):

- `"max_attempts_reached"`: the game is already over since the number of
attempts has reached `options?.maxAttempts` (6 by default)
- `"too_few_characters"`: the attempted word has less characters then the
current word
- `"too_many_characters"`: the attempted word has more characters then the
current word
- `"invalid_attempt"`: the attempt did not pass the `options?.validateAttempt()`
function
18 changes: 9 additions & 9 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"exclude": [
"./node"
],
"tasks": {
"test": "deno test",
"dev": "deno task test --watch",
"node": "deno run --allow-env --allow-read --allow-write --allow-run dnt.ts"
}
}
"exclude": [
"./node"
],
"tasks": {
"test": "deno test",
"dev": "deno task test --watch",
"node": "deno run --allow-env --allow-read --allow-write --allow-run dnt.ts"
}
}
12 changes: 6 additions & 6 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { persistentAtom } from "npm:@nanostores/[email protected]";
import { WritableAtom, action, atom } from "npm:[email protected]";
import { action, atom, WritableAtom } from "npm:[email protected]";

export type WordleError =
| "max_attempts_reached"
Expand All @@ -13,7 +13,7 @@ export function wordle(
persistKey?: string;
maxAttempts?: number;
validateAttempt?: (word: string) => boolean;
}
},
) {
if (options?.persistKey) {
console.log("key is", `"wordle-${options?.persistKey}"`);
Expand All @@ -27,9 +27,9 @@ export function wordle(
const $attempts: WritableAtom<string[]> =
options?.persistKey && options?.persistKey.length > 0
? persistentAtom(`wordle-${options?.persistKey}`, [], {
encode: JSON.stringify,
decode: JSON.parse,
})
encode: JSON.stringify,
decode: JSON.parse,
})
: atom([]);

const maxAttempts = options?.maxAttempts ?? 6;
Expand Down Expand Up @@ -64,7 +64,7 @@ export function wordle(
store.set([...store.get(), attemptedWord]);

return {};
}
},
);

return { word: $word, attempts: $attempts, attempt, maxAttempts };
Expand Down

0 comments on commit 1bcfc8a

Please sign in to comment.