Skip to content

Commit 3623e2c

Browse files
committed
Merge branch 'dev'
2 parents c4a3e35 + 3e3b9b3 commit 3623e2c

File tree

7 files changed

+88
-36
lines changed

7 files changed

+88
-36
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
11
# Typer Diff
22

3-
![Typer Diff](assets/demo.png)
3+
![Typer Diff Demo](assets/demo.png)
4+
5+
`type-diff` is a library to diff two strings, useful for showing for typing games (like [monkeytype](https://monkeytype.com/)) or for showing differences between two strings. It is a simple library that is easy to use and has no dependencies. It is also very fast and lightweight.
6+
7+
## Usage
8+
9+
**Usage:**
10+
11+
```typescript
12+
import { diff } from "typer-diff";
13+
14+
// ...
15+
return diff(text.original, text.text);
16+
// ...
17+
```
18+
19+
**Types:**
20+
21+
```typescript
22+
type DiffItem = {
23+
value: string;
24+
type: "correct" | "extra" | "missing" | "wrong" | "untouched" | "spacer";
25+
};
26+
type DiffResult = {
27+
diff: DiffItem[];
28+
end: boolean;
29+
};
30+
declare const diff: (originalText: string, typedText: string) => DiffResult;
31+
32+
export { type DiffItem, type DiffResult, diff };
33+
```

apps/docs/README.md

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,11 @@
1-
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
1+
# Typer Diff Demo App
22

3-
## Getting Started
3+
![Typer Diff Demo](https://raw.githubusercontent.com/techboy-coder/typer-diff/main/assets/demo.png?token=GHSAT0AAAAAACSUZ6AC33WMWGPI4HJ5X47KZTYIUYQ)
44

5-
First, run the development server:
5+
`type-diff` is a library to diff two strings, useful for showing for typing games or for showing differences between two strings. It is a simple library that is easy to use and has no dependencies. It is also very fast and lightweight.
66

7-
```bash
8-
npm run dev
9-
# or
10-
yarn dev
11-
# or
12-
pnpm dev
13-
# or
14-
bun dev
15-
```
7+
## Demo App
168

17-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
9+
This is a simple Next.js app that uses the `typer-diff` library to show an input field where you can type and see the diff between the original text and the typed text. (Similar to typing games like [monkeytype](https://monkeytype.com/)).
1810

19-
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20-
21-
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
22-
23-
## Learn More
24-
25-
To learn more about Next.js, take a look at the following resources:
26-
27-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29-
30-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
31-
32-
## Deploy on Vercel
33-
34-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35-
36-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
11+
Check out the [demo](https://typer-diff.vercel.app/).

apps/docs/app/layout.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ export default function RootLayout({
1818
<html lang="en">
1919
<body
2020
className={`bg-black text-white font-mono h-screen overscroll-none`}>
21+
<nav className="flex justify-center items-center space-x-4 text-white/75 py-20">
22+
<a
23+
href="https://github.com/techboy-coder/typer-diff"
24+
target="_blank">
25+
github
26+
</a>
27+
<a
28+
href="https://npmjs.com/package/typer-diff"
29+
target="_blank">
30+
npm
31+
</a>
32+
</nav>
2133
{children}
2234
</body>
2335
</html>

apps/docs/app/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import HiddenInput from "./components/HiddenInput";
33

44
export default function Home() {
55
return (
6-
<div className="h-full leading-relaxed flex flex-col justify-center items-center">
6+
<div className=" leading-relaxed flex flex-col justify-center items-center">
7+
<span className="text-xl text-white font-mono py-10">
8+
Start typing to see <em>typer-diff</em> in action.
9+
</span>
710
<DiffText></DiffText>
811
<HiddenInput></HiddenInput>
912
</div>

apps/docs/data/state.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ export const diffText = atom((get) => {
1414
});
1515

1616
export const allowModifications = atom((get) => {
17-
const diff = get(diffText);
18-
return !diff.end;
17+
// incase you want to stop modifications (e.g. when the user has finished typing)
18+
// const diff = get(diffText);
19+
// return !diff.end;
20+
return true;
1921
});
2022

2123
export const isTyping = atom(true);

packages/typer-diff/README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
11
# Typer Diff
22

3-
![Typer Diff Demo](demo.png)
3+
![Typer Diff Demo](https://raw.githubusercontent.com/techboy-coder/typer-diff/main/assets/demo.png?token=GHSAT0AAAAAACSUZ6AC33WMWGPI4HJ5X47KZTYIUYQ)
4+
5+
`type-diff` is a library to diff two strings, useful for showing for typing games (like [monkeytype](https://monkeytype.com/)) or for showing differences between two strings. It is a simple library that is easy to use and has no dependencies. It is also very fast and lightweight.
6+
7+
## Usage
8+
9+
**Usage:**
10+
11+
```typescript
12+
import { diff } from "typer-diff";
13+
14+
// ...
15+
return diff(text.original, text.text);
16+
// ...
17+
```
18+
19+
**Types:**
20+
21+
```typescript
22+
type DiffItem = {
23+
value: string;
24+
type: "correct" | "extra" | "missing" | "wrong" | "untouched" | "spacer";
25+
};
26+
type DiffResult = {
27+
diff: DiffItem[];
28+
end: boolean;
29+
};
30+
declare const diff: (originalText: string, typedText: string) => DiffResult;
31+
32+
export { type DiffItem, type DiffResult, diff };
33+
```

packages/typer-diff/demo.png

-67.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)