web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

  1. [![NPM](https://nodei.co/npm/damerau-levenshtein.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/damerau-levenshtein/)
  2. It provides a function that takes two string arguments and returns a hash like this:
  3. ``` javascript
  4. {
  5. steps: 5, // Levenstein demerau distance
  6. relative: 0.7, // steps / length of the longer string
  7. similarity: 0.3 // 1 - relative
  8. }
  9. ```
  10. ## Install
  11. ```sh
  12. npm install damerau-levenshtein
  13. ```
  14. ## Use with ES6 modules
  15. ```js
  16. import * as levenshtien from 'damerau-levenshtein';
  17. const lev = levenshtien('hello world', 'Hello World!');
  18. // { steps: 4, relative: 0.3076923076923077, similarity: 0.6923076923076923 }
  19. ```
  20. Please see [tests](./test/test.js) for more insights.
  21. ## Use with TypeScript
  22. ```ts
  23. import * as levenshtien from 'damerau-levenshtein';
  24. interface LevenshteinResponse {
  25. steps: number;
  26. relative: number;
  27. similarity: number;
  28. }
  29. const lev: LevenshteinResponse = levenshtien('hello world', 'Hello World!');
  30. console.log(lev.steps);
  31. // 2
  32. console.log(lev.foo);
  33. // TypeScript Error: Property 'foo' does not exist on type 'LevenshteinResponse'.
  34. ```