|
27 | 27 | - 📊 Similarity percentage calculation |
28 | 28 | - 🔧 Easy to integrate |
29 | 29 |
|
| 30 | +## Basic Usage 🚀 |
| 31 | + |
| 32 | +### Install the Package |
| 33 | +First, install the `text-compare` package using **npm or yarn**: |
| 34 | + |
| 35 | +```bash |
| 36 | +npm install text-compare |
| 37 | +# or |
| 38 | +yarn add text-compare |
| 39 | +``` |
| 40 | +After installing, here's a quick example to get you started: |
| 41 | +```js |
| 42 | +import { useTextComparison } from 'text-compare'; |
| 43 | + |
| 44 | +const TextDiffer = () => { |
| 45 | + const text1 = 'The quick brown fox jumps over the lazy dog'; |
| 46 | + const text2 = 'The quick blue fox leaps over the happy dog'; |
| 47 | + |
| 48 | + const { comparisonResult, similarity } = useTextComparison(text1, text2); |
| 49 | + |
| 50 | + return ( |
| 51 | + <> |
| 52 | + <div className="flex gap-1 mb-4">{comparisonResult}</div> |
| 53 | + <div>Similarity: {similarity.toFixed(2)}%</div> |
| 54 | + </> |
| 55 | + ); |
| 56 | +}; |
| 57 | +``` |
| 58 | + |
| 59 | +## 🛠️ Advanced Usage |
| 60 | + |
| 61 | +### Customization Options |
| 62 | + |
| 63 | +The `useTextComparison` hook accepts an options object for customization: |
| 64 | + |
| 65 | +```jsx |
| 66 | +const options = { |
| 67 | + customColors: { |
| 68 | + commonColor: '#1E90FF', // DodgerBlue for common words |
| 69 | + removedColor: '#FF6347', // TomatoRed for removed words |
| 70 | + addedColor: '#32CD32', // LimeGreen for added words |
| 71 | + } |
| 72 | +}; |
| 73 | + |
| 74 | +const { comparisonResult, similarity } = useTextComparison(text1, text2, options); |
| 75 | +``` |
| 76 | + |
| 77 | +### Available Options |
| 78 | + |
| 79 | +| Option | Type | Description | |
| 80 | +|--------|---------|-------------| |
| 81 | +| `customColors` | object | An object containing color configurations for text highlighting. Properties: `commonColor` (for matching words), `removedColor` (for removed words), `addedColor` (for added words) | |
| 82 | + |
30 | 83 | ## 🚀 Getting Started Guide |
31 | 84 |
|
32 | 85 | Follow the steps below to set up and work with the `text-compare` project. |
@@ -92,53 +145,6 @@ npm run dev |
92 | 145 | npm start |
93 | 146 | ``` |
94 | 147 |
|
95 | | -## Basic Usage 🚀 |
96 | | - |
97 | | -Here's a quick example to get you started: |
98 | | - |
99 | | -```js |
100 | | -import { useTextComparison } from 'text-compare'; |
101 | | - |
102 | | -const TextDiffer = () => { |
103 | | - const text1 = 'The quick brown fox jumps over the lazy dog'; |
104 | | - const text2 = 'The quick blue fox leaps over the happy dog'; |
105 | | - |
106 | | - const { comparisonResult, similarity } = useTextComparison(text1, text2); |
107 | | - |
108 | | - return ( |
109 | | - <> |
110 | | - <div className="flex gap-1 mb-4">{comparisonResult}</div> |
111 | | - <div>Similarity: {similarity.toFixed(2)}%</div> |
112 | | - </> |
113 | | - ); |
114 | | -}; |
115 | | -``` |
116 | | - |
117 | | -## 🛠️ Advanced Usage |
118 | | - |
119 | | -### Customization Options |
120 | | - |
121 | | -The `useTextComparison` hook accepts an options object for customization: |
122 | | - |
123 | | -```jsx |
124 | | -const options = { |
125 | | - customColors: { |
126 | | - commonColor: '#1E90FF', // DodgerBlue for common words |
127 | | - removedColor: '#FF6347', // TomatoRed for removed words |
128 | | - addedColor: '#32CD32', // LimeGreen for added words |
129 | | - } |
130 | | -}; |
131 | | - |
132 | | -const { comparisonResult, similarity } = useTextComparison(text1, text2, options); |
133 | | -``` |
134 | | - |
135 | | -### Available Options |
136 | | - |
137 | | -| Option | Type | Description | |
138 | | -|--------|---------|-------------| |
139 | | -| `customColors` | object | An object containing color configurations for text highlighting. Properties: `commonColor` (for matching words), `removedColor` (for removed words), `addedColor` (for added words) | |
140 | | - |
141 | | - |
142 | 148 | ## Contributing 🤝 |
143 | 149 |
|
144 | 150 | Contributions, issues, and feature requests are welcome! Feel free to check the [issues page](https://github.com/CreoWis/text-compare/issues). |
|
0 commit comments