UNPKG

string-metric

Version:

Get string similarity in JavaScript or TypeScript

29 lines (28 loc) 1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MetricLCS = void 0; var LongestCommonSubsequence_1 = require("./LongestCommonSubsequence"); var utils_1 = require("./utils/utils"); var MetricLCS = /** @class */ (function () { function MetricLCS() { this.lcs = new LongestCommonSubsequence_1.LongestCommonSubsequence(); } MetricLCS.prototype.distance = function (s1, s2) { if (utils_1.isNullOrUndefined(s1)) { throw new Error('s1 must neither be null nor undefined'); } if (utils_1.isNullOrUndefined(s2)) { throw new Error('s2 must neither be null nor undefined'); } if (s1 === s2) { return 0; } var m_len = Math.max(s1.length, s2.length); if (m_len == 0) { return 0; } return 1.0 - (1.0 * this.lcs.length(s1, s2)) / m_len; }; return MetricLCS; }()); exports.MetricLCS = MetricLCS;