Skip to content

Commit

Permalink
Document default options
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel-rowe committed Sep 14, 2024
1 parent ba465b5 commit 99f5a3b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@ const str2 = 'Goodbye, world! 💩'

// default behavior: UTF-8 char diff
assertDiffsEqual(
differ.diff(str1, str2),
[[-1, 'Hell'], [1, 'G'], [0, 'o'], [1, 'odbye'], [0, ', world! '], [-1, '💫'], [1, '💩']],
differ.diff(str1, str2),
[[-1, 'Hell'], [1, 'G'], [0, 'o'], [1, 'odbye'], [0, ', world! '], [-1, '💫'], [1, '💩']],
)

// word diff with `Intl.Segmenter`
assertDiffsEqual(
differ.diff(str1, str2, { segmenter: segmenters.word }),
[[-1, 'Hello'], [1, 'Goodbye'], [0, ', world! '], [-1, '💫'], [1, '💩']],
differ.diff(str1, str2, { segmenter: segmenters.word }),
[[-1, 'Hello'], [1, 'Goodbye'], [0, ', world! '], [-1, '💫'], [1, '💩']],
)

// pass in a custom `Intl.Segmenter` instance
assertDiffsEqual(
differ.diff('两只小蜜蜂', '两只老虎', { segmenter: new Intl.Segmenter('zh-CN', { granularity: 'word' }) }),
[[0, '两只'], [-1, '小蜜蜂'], [1, '老虎']],
differ.diff('两只小蜜蜂', '两只老虎', { segmenter: new Intl.Segmenter('zh-CN', { granularity: 'word' }) }),
[[0, '两只'], [-1, '小蜜蜂'], [1, '老虎']],
)

// line diff
assertDiffsEqual(
differ.diff(str1, str2, { segmenter: segmenters.line }),
[[-1, 'Hello, world! 💫'], [1, 'Goodbye, world! 💩']],
differ.diff(str1, str2, { segmenter: segmenters.line }),
[[-1, 'Hello, world! 💫'], [1, 'Goodbye, world! 💩']],
)

// custom UTF-16 code-unit diff (equivalent to using `diffCodeUnits` directly... but less performant)
assertDiffsEqual(
differ.diff(str1, str2, { segmenter: (str) => str.split('') }),
[[-1, 'Hell'], [1, 'G'], [0, 'o'], [1, 'odbye'], [0, ', world! \ud83d'], [-1, '\udcab'], [1, '\udca9']],
differ.diff(str1, str2, { segmenter: (str) => str.split('') }),
[[-1, 'Hell'], [1, 'G'], [0, 'o'], [1, 'odbye'], [0, ', world! \ud83d'], [-1, '\udcab'], [1, '\udca9']],
)
```

Expand Down
4 changes: 2 additions & 2 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"lock": false,
"name": "@clearlylocal/diff-match-patch-unicode",
"version": "0.0.3",
"version": "0.0.4",
"description": "Modern JS/TS and Unicode-friendly version of diff-match-patch",
"exports": {
".": "./src/mod.ts",
Expand All @@ -23,7 +23,7 @@
"indentWidth": 4,
"singleQuote": true,
"proseWrap": "preserve",
"exclude": ["docs"]
"exclude": ["README.md"]
},
"compilerOptions": { "strict": true },
"lint": { "rules": { "tags": ["recommended"] } },
Expand Down
11 changes: 8 additions & 3 deletions src/Differ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ import { SegmentCodec, StringIter } from './SegmentCodec.ts'
export type DiffOptions = {
/**
* The segmenter to use for the diff (e.g. chars, words, sentences, lines, graphemes, etc).
*
* Some suitable segmenters are available in the {@linkcode segmenters} object.
*
* @default {segmenters.char}
*/
segmenter: Segmenter
/**
* Whether to join adjacent diffs.
* @default {true}
*/
join: boolean
/**
* Optional speedup flag. If `true`, then run a line-level diff first to identify the changed areas.
* Defaults to `false`, which does a slower, slightly more optimal diff.
* Optional speedup flag:
* - If `true`, run a line-level diff first to identify the changed areas.
* - If `false`, do a slower, slightly more optimal diff.
*
* @default {false}
*/
checkLines: boolean
}
Expand Down

0 comments on commit 99f5a3b

Please sign in to comment.