{"id":11122,"library":"jaro-winkler-typescript","title":"Jaro-Winkler for TypeScript","description":"jaro-winkler-typescript provides a pure TypeScript implementation of the Jaro and Jaro-Winkler string similarity algorithms. These algorithms are widely used to measure the edit distance or similarity between two strings, returning a score typically ranging from 0 (completely dissimilar) to 1 (identical). The current stable version is 1.0.1. As a utility library for a well-defined algorithm, its release cadence is expected to be slow, with new versions primarily addressing bug fixes, performance improvements, or minor enhancements. A key differentiator is its explicit TypeScript implementation, offering strong type safety and an improved developer experience in modern TypeScript projects. It serves as a direct, unopinionated implementation focused solely on accurately calculating these specific string similarity scores.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/kwunshing123/jaro-winkler-typescript","tags":["javascript","Jaro","Jaro Winkler","typescript","string similarity","string"],"install":[{"cmd":"npm install jaro-winkler-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add jaro-winkler-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add jaro-winkler-typescript","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is designed for ESM/TypeScript; CommonJS require() syntax for named exports is not directly supported and can lead to runtime errors.","wrong":"const { jaro } = require('jaro-winkler-typescript');","symbol":"jaro","correct":"import { jaro } from 'jaro-winkler-typescript';"},{"note":"Both `jaro` and `jaroWinkler` are named exports. Attempting a default import will result in 'undefined' or a 'TypeError'.","wrong":"import jaroWinkler from 'jaro-winkler-typescript';","symbol":"jaroWinkler","correct":"import { jaroWinkler } from 'jaro-winkler-typescript';"},{"note":"When only importing types for type annotations, use `import type` for clarity and to ensure it's removed during compilation if not needed at runtime.","symbol":"JaroWinklerOptions","correct":"import type { JaroWinklerOptions } from 'jaro-winkler-typescript';"}],"quickstart":{"code":"import { jaro, jaroWinkler } from \"jaro-winkler-typescript\";\n\n// Example 1: Basic comparison for Jaro similarity\nconst stringA = \"MARTHA\";\nconst stringB = \"MARHTA\";\nconst similarityJaro = jaro(stringA, stringB);\nconsole.log(`Jaro similarity between \"${stringA}\" and \"${stringB}\": ${similarityJaro.toFixed(4)}`);\n// Expected output: Jaro similarity between \"MARTHA\" and \"MARHTA\": 0.9444\n\n// Example 2: Basic comparison for Jaro-Winkler similarity\nconst stringC = \"DWAYNE\";\nconst stringD = \"DUANE\";\nconst similarityJaroWinkler = jaroWinkler(stringC, stringD);\nconsole.log(`Jaro-Winkler similarity between \"${stringC}\" and \"${stringD}\": ${similarityJaroWinkler.toFixed(4)}`);\n// Expected output: Jaro-Winkler similarity between \"DWAYNE\" and \"DUANE\": 0.8400\n\n// Example 3: Case-insensitive comparison\nconst name1 = \"JavaScript\";\nconst name2 = \"javascript\";\nconst insensitiveJaro = jaro(name1, name2, { caseSensitive: false });\nconsole.log(`Case-insensitive Jaro similarity between \"${name1}\" and \"${name2}\": ${insensitiveJaro.toFixed(4)}`);\n// Expected output: Case-insensitive Jaro similarity between \"JavaScript\" and \"javascript\": 1.0000\n\n// Example 4: Comparing strings with significant differences\nconst word1 = \"hello\";\nconst word2 = \"world\";\nconst jaroScore = jaro(word1, word2);\nconst jaroWinklerScore = jaroWinkler(word1, word2);\nconsole.log(`Jaro score for \"${word1}\" and \"${word2}\": ${jaroScore.toFixed(4)}`);\nconsole.log(`Jaro-Winkler score for \"${word1}\" and \"${word2}\": ${jaroWinklerScore.toFixed(4)}`);\n// Expected output: Jaro score for \"hello\" and \"world\": 0.4444, Jaro-Winkler score for \"hello\" and \"world\": 0.4444","lang":"typescript","description":"Demonstrates basic usage of Jaro and Jaro-Winkler algorithms, including case-sensitive and case-insensitive comparisons, and interpretation of similarity scores."},"warnings":[{"fix":"Pass `{ caseSensitive: false }` as the third argument to the `jaro` or `jaroWinkler` function for case-insensitive comparisons.","message":"By default, both `jaro` and `jaroWinkler` functions are case-sensitive. 'Apple' and 'apple' will yield a similarity score of 0 (or close to 0) unless `caseSensitive: false` is explicitly set in the options.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Understand the characteristics of different string similarity algorithms and choose the one best suited for your specific data and use case. Jaro-Winkler is often preferred for human names or dictionary words.","message":"The Jaro-Winkler algorithm, while generally effective, tends to perform better with shorter strings, especially proper nouns, due to its prefix scaling feature. For very long strings or different types of string comparison needs, other algorithms like Levenshtein distance might be more suitable.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"When comparing scores, use a small epsilon for tolerance (e.g., `Math.abs(score1 - score2) < EPSILON`). For displaying results, use `toFixed()` or `Math.round()`.","message":"The similarity scores returned are floating-point numbers between 0 and 1. Direct equality checks on these values might fail due to floating-point precision issues. For display, consider rounding the results.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure your project is configured for ESM and use `import { jaro } from 'jaro-winkler-typescript';`. If using CommonJS, it may require transpilation or a different package.","cause":"Attempting to import `jaro` or `jaroWinkler` using CommonJS `require()` syntax in an environment that expects ESM, or incorrect destructuring.","error":"TypeError: (0 , jaro_winkler_typescript__WEBPACK_IMPORTED_MODULE_0__.jaro) is not a function"},{"fix":"Use named imports: `import { jaro, jaroWinkler } from 'jaro-winkler-typescript';`","cause":"This typically occurs when trying to access `jaro` or `jaroWinkler` after using a default import (`import jaro from '...'`) for a package that only provides named exports, or attempting `const jaro = require(...)` without destructuring.","error":"TypeError: jaro is not a function"},{"fix":"Ensure both arguments passed to `jaro` and `jaroWinkler` are strings. Validate input types before calling the functions.","cause":"Passing a non-string value (e.g., a number or null) to the `jaro` or `jaroWinkler` function, which expects two string arguments.","error":"Argument of type 'number' is not assignable to parameter of type 'string'."}],"ecosystem":"npm"}