New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

string-comparison

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-comparison - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

14

lib/main/interface/Similarity.js

@@ -1,13 +0,1 @@

"use strict";function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}module.exports=/*#__PURE__*/function(){function a(){_classCallCheck(this,a)}/**
*
* @param {String} thanos 灭霸,主字符串
* @param {String} rival 敌人,需要比较的字符串
* @description 比较两个字符串
*/return _createClass(a,[{key:"similarity",value:function similarity(){console.info(111)}/**
*
* @param {String} thanos
* @param {[...String]} avengers 复仇者,字符串数组
* @description 寻找最佳匹配结果
*/},{key:"sortMatch",value:function sortMatch(b,c){var d=this;return a.checkThanosType(b),a.checkAvengersType(c),c.map(function(a,c){return{member:a,index:c,rating:d.similarity(b,a)}}).sort(function(c,a){return c.rating-a.rating})}// distance
},{key:"distance",value:function distance(){// 计算 distance
}}],[{key:"checkThanosType",value:function checkThanosType(a){if("string"!=typeof a)throw new Error("first argument should be a string")}},{key:"checkRivalType",value:function checkRivalType(a){if("string"!=typeof a)throw new Error("second argument should be a string")}},{key:"checkAvengersType",value:function checkAvengersType(a){if(!Array.isArray(a))throw new Error("second argument should be an array of strings");if(a.find(function(a){return"string"!=typeof a}))throw new Error("second argument should be an array of strings")}},{key:"initParams",value:function initParams(a,b){return[a.replace(/\s+/g,"").toLowerCase(),b.replace(/\s+/g,"").toLowerCase()]}}]),a}();
"use strict";function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}module.exports=function(){function a(){_classCallCheck(this,a)}return _createClass(a,[{key:"similarity",value:function similarity(){console.info(111)}},{key:"sortMatch",value:function sortMatch(b,c){var d=this;return a.checkThanosType(b),a.checkAvengersType(c),c.map(function(a,c){return{member:a,index:c,rating:d.similarity(b,a)}}).sort(function(c,a){return c.rating-a.rating})}},{key:"distance",value:function distance(){}}],[{key:"checkThanosType",value:function checkThanosType(a){if("string"!=typeof a)throw new Error("first argument should be a string")}},{key:"checkRivalType",value:function checkRivalType(a){if("string"!=typeof a)throw new Error("second argument should be a string")}},{key:"checkAvengersType",value:function checkAvengersType(a){if(!Array.isArray(a))throw new Error("second argument should be an array of strings");if(a.find(function(a){return"string"!=typeof a}))throw new Error("second argument should be an array of strings")}},{key:"initParams",value:function initParams(a,b){return[a.replace(/\s+/g,"").toLowerCase(),b.replace(/\s+/g,"").toLowerCase()]}}]),a}();

4

lib/main/packages/Cosine.js

@@ -1,3 +0,1 @@

"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}var Similarity=require("../interface/Similarity");module.exports=/*#__PURE__*/function(a){function b(){return _classCallCheck(this,b),_possibleConstructorReturn(this,_getPrototypeOf(b).call(this))}return _inherits(b,a),_createClass(b,[{key:"similarity",value:function similarity(a,c){if(Similarity.checkThanosType(a),Similarity.checkRivalType(c),a=Similarity.initParams(a,c)[0],c=Similarity.initParams(a,c)[1],!a.length&&!c.length)return 1;if(!a.length||!c.length)return 0;if(a===c)return 1;// string vectorization
for(var d=Array.from(new Set(a.split("").concat(c.split("")))),e=b.stringVectorization(a.split(""),d),f=b.stringVectorization(c.split(""),d),g=0,h=0,j=0,k=0;k<e.length;++k)g+=e[k]*f[k],h+=e[k]*e[k],j+=f[k]*f[k];return h=Math.sqrt(h),j=Math.sqrt(j),1*g/(h*j)}},{key:"distance",value:function distance(a,b){return 1-this.similarity(a,b)}// string vectorization
}],[{key:"stringVectorization",value:function stringVectorization(a,b){return b.map(function(b){return a.includes(b)?1:0})}}]),b}(Similarity);
"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}var Similarity=require("../interface/Similarity");module.exports=function(a){function b(){return _classCallCheck(this,b),_possibleConstructorReturn(this,_getPrototypeOf(b).call(this))}return _inherits(b,a),_createClass(b,[{key:"similarity",value:function similarity(a,c){if(Similarity.checkThanosType(a),Similarity.checkRivalType(c),a=Similarity.initParams(a,c)[0],c=Similarity.initParams(a,c)[1],!a.length&&!c.length)return 1;if(!a.length||!c.length)return 0;if(a===c)return 1;for(var d=Array.from(new Set(a.split("").concat(c.split("")))),e=b.stringVectorization(a.split(""),d),f=b.stringVectorization(c.split(""),d),g=0,h=0,j=0,k=0;k<e.length;++k)g+=e[k]*f[k],h+=e[k]*e[k],j+=f[k]*f[k];return h=Math.sqrt(h),j=Math.sqrt(j),1*g/(h*j)}},{key:"distance",value:function distance(a,b){return 1-this.similarity(a,b)}}],[{key:"stringVectorization",value:function stringVectorization(a,b){return b.map(function(b){return a.includes(b)?1:0})}}]),b}(Similarity);

@@ -1,2 +0,1 @@

"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}var Similarity=require("../interface/Similarity");module.exports=/*#__PURE__*/function(a){function b(){return _classCallCheck(this,b),_possibleConstructorReturn(this,_getPrototypeOf(b).call(this))}return _inherits(b,a),_createClass(b,[{key:"similarity",value:function similarity(a,b){Similarity.checkThanosType(a),Similarity.checkRivalType(b),a=Similarity.initParams(a,b)[0],b=Similarity.initParams(a,b)[1];var c=[a.length,b.length],d=c[0],e=c[1];if(!a.length&&!b.length)return 1;if(a===b)return 1;if(2>d||2>e)return 0;// get the intersecting character, two strings as a group
for(var f=new Map,g=0;g<d-1;g++){var h=a.substr(g,2),j=f.has(h)?f.get(h)+1:1;f.set(h,j)}for(var k=0,l=0;l<e-1;l++){var m=b.substr(l,2),n=f.has(m)?f.get(m):0;0<n&&(f.set(m,n-1),++k)}return 2*k/(d+e-2)}},{key:"distance",value:function distance(a,b){return 1-this.similarity(a,b)}}]),b}(Similarity);
"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}var Similarity=require("../interface/Similarity");module.exports=function(a){function b(){return _classCallCheck(this,b),_possibleConstructorReturn(this,_getPrototypeOf(b).call(this))}return _inherits(b,a),_createClass(b,[{key:"similarity",value:function similarity(a,b){Similarity.checkThanosType(a),Similarity.checkRivalType(b),a=Similarity.initParams(a,b)[0],b=Similarity.initParams(a,b)[1];var c=[a.length,b.length],d=c[0],e=c[1];if(!a.length&&!b.length)return 1;if(a===b)return 1;if(2>d||2>e)return 0;for(var f=new Map,g=0;g<d-1;g++){var h=a.substr(g,2),j=f.has(h)?f.get(h)+1:1;f.set(h,j)}for(var k=0,l=0;l<e-1;l++){var m=b.substr(l,2),n=f.has(m)?f.get(m):0;0<n&&(f.set(m,n-1),++k)}return 2*k/(d+e-2)}},{key:"distance",value:function distance(a,b){return 1-this.similarity(a,b)}}]),b}(Similarity);

@@ -1,2 +0,1 @@

"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}var Similarity=require("../interface/Similarity");module.exports=/*#__PURE__*/function(a){function b(){return _classCallCheck(this,b),_possibleConstructorReturn(this,_getPrototypeOf(b).call(this))}return _inherits(b,a),_createClass(b,[{key:"similarity",value:function similarity(a,b){if(Similarity.checkThanosType(a),Similarity.checkRivalType(b),a=Similarity.initParams(a,b)[0],b=Similarity.initParams(a,b)[1],!a.length&&!b.length)return 1;if(a===b)return 1;// split and Set
var c=new Set(a.split("").concat(b.split(""))),d=new Set(a.split("").filter(function(a){return new Set(b).has(a)}));return 1*d.size/c.size}},{key:"distance",value:function distance(a,b){return 1-this.similarity(a,b)}}]),b}(Similarity);
"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}var Similarity=require("../interface/Similarity");module.exports=function(a){function b(){return _classCallCheck(this,b),_possibleConstructorReturn(this,_getPrototypeOf(b).call(this))}return _inherits(b,a),_createClass(b,[{key:"similarity",value:function similarity(a,b){if(Similarity.checkThanosType(a),Similarity.checkRivalType(b),a=Similarity.initParams(a,b)[0],b=Similarity.initParams(a,b)[1],!a.length&&!b.length)return 1;if(a===b)return 1;var c=new Set(a.split("").concat(b.split(""))),d=new Set(a.split("").filter(function(a){return new Set(b).has(a)}));return 1*d.size/c.size}},{key:"distance",value:function distance(a,b){return 1-this.similarity(a,b)}}]),b}(Similarity);

@@ -1,4 +0,1 @@

"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}var Similarity=require("../interface/Similarity");module.exports=/*#__PURE__*/function(a){function b(){return _classCallCheck(this,b),_possibleConstructorReturn(this,_getPrototypeOf(b).call(this))}return _inherits(b,a),_createClass(b,[{key:"similarity",value:function similarity(a,b){return Similarity.checkThanosType(a),Similarity.checkRivalType(b),a=Similarity.initParams(a,b)[0],b=Similarity.initParams(a,b)[1],a.length||b.length?1-1*this.distance(a,b)/Math.max(a.length,b.length):1}// edit distance
},{key:"distance",value:function distance(a,b){if(Similarity.checkThanosType(a),Similarity.checkRivalType(b),a=Similarity.initParams(a,b)[0],b=Similarity.initParams(a,b)[1],a===b)return 0;var c=[a.length,b.length],d=c[0],e=c[1];if(!d)return e;if(!e)return d;// init array
for(var f=_toConsumableArray(Array(d+1)).map(function(){return Array(e+1).fill(0)}),g=0;g<=d;++g)f[g][0]=g;for(var l=0;l<=e;++l)f[0][l]=l;for(var h,k=1;k<=d;++k)for(var j=1;j<=e;++j)// delete insert replace
h=a[k-1]===b[j-1]?0:1,f[k][j]=Math.min(f[k-1][j]+1,f[k][j-1]+1,f[k-1][j-1]+h);return f[d][e]}}]),b}(Similarity);
"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}var Similarity=require("../interface/Similarity");module.exports=function(a){function b(){return _classCallCheck(this,b),_possibleConstructorReturn(this,_getPrototypeOf(b).call(this))}return _inherits(b,a),_createClass(b,[{key:"similarity",value:function similarity(a,b){return Similarity.checkThanosType(a),Similarity.checkRivalType(b),a=Similarity.initParams(a,b)[0],b=Similarity.initParams(a,b)[1],a.length||b.length?1-1*this.distance(a,b)/Math.max(a.length,b.length):1}},{key:"distance",value:function distance(a,b){if(Similarity.checkThanosType(a),Similarity.checkRivalType(b),a=Similarity.initParams(a,b)[0],b=Similarity.initParams(a,b)[1],a===b)return 0;var c=[a.length,b.length],d=c[0],e=c[1];if(!d)return e;if(!e)return d;for(var f=_toConsumableArray(Array(d+1)).map(function(){return Array(e+1).fill(0)}),g=0;g<=d;++g)f[g][0]=g;for(var l=0;l<=e;++l)f[0][l]=l;for(var h,k=1;k<=d;++k)for(var j=1;j<=e;++j)h=a[k-1]===b[j-1]?0:1,f[k][j]=Math.min(f[k-1][j]+1,f[k][j-1]+1,f[k-1][j-1]+h);return f[d][e]}}]),b}(Similarity);

@@ -1,2 +0,1 @@

"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}var Similarity=require("../interface/Similarity");module.exports=/*#__PURE__*/function(a){function b(){return _classCallCheck(this,b),_possibleConstructorReturn(this,_getPrototypeOf(b).call(this))}return _inherits(b,a),_createClass(b,[{key:"similarity",value:function similarity(a,c){return Similarity.checkThanosType(a),Similarity.checkRivalType(c),a=Similarity.initParams(a,c)[0],c=Similarity.initParams(a,c)[1],a.length||c.length?a===c?1:2*b.lcsLength(a,c)/(a.length+c.length):1}},{key:"distance",value:function distance(a,c){return a.length+c.length-2*b.lcsLength(a,c)}// Return the length of Longest Common Subsequence (LCS) between strings thanos and rival
}],[{key:"lcsLength",value:function lcsLength(a,b){Similarity.checkThanosType(a),Similarity.checkRivalType(b),a=Similarity.initParams(a,b)[0],b=Similarity.initParams(a,b)[1];for(var c=[a.length,b.length],d=c[0],e=c[1],f=_toConsumableArray(Array(d+1)).map(function(){return Array(e+1).fill(0)}),g=1;g<=d;++g)for(var h=1;h<=e;++h)f[g][h]=a[g-1]===b[h-1]?f[g-1][h-1]+1:Math.max(f[g][h-1],f[g-1][h]);return f[d][e]}}]),b}(Similarity);
"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}var Similarity=require("../interface/Similarity");module.exports=function(a){function b(){return _classCallCheck(this,b),_possibleConstructorReturn(this,_getPrototypeOf(b).call(this))}return _inherits(b,a),_createClass(b,[{key:"similarity",value:function similarity(a,c){return Similarity.checkThanosType(a),Similarity.checkRivalType(c),a=Similarity.initParams(a,c)[0],c=Similarity.initParams(a,c)[1],a.length||c.length?a===c?1:2*b.lcsLength(a,c)/(a.length+c.length):1}},{key:"distance",value:function distance(a,c){return a.length+c.length-2*b.lcsLength(a,c)}}],[{key:"lcsLength",value:function lcsLength(a,b){Similarity.checkThanosType(a),Similarity.checkRivalType(b),a=Similarity.initParams(a,b)[0],b=Similarity.initParams(a,b)[1];for(var c=[a.length,b.length],d=c[0],e=c[1],f=_toConsumableArray(Array(d+1)).map(function(){return Array(e+1).fill(0)}),g=1;g<=d;++g)for(var h=1;h<=e;++h)f[g][h]=a[g-1]===b[h-1]?f[g-1][h-1]+1:Math.max(f[g][h-1],f[g-1][h]);return f[d][e]}}]),b}(Similarity);

@@ -1,1 +0,1 @@

"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}var Similarity=require("../interface/Similarity");module.exports=/*#__PURE__*/function(a){function b(){return _classCallCheck(this,b),_possibleConstructorReturn(this,_getPrototypeOf(b).call(this))}return _inherits(b,a),_createClass(b,[{key:"similarity",value:function similarity(a,c){return Similarity.checkThanosType(a),Similarity.checkRivalType(c),a=Similarity.initParams(a,c)[0],c=Similarity.initParams(a,c)[1],a.length||c.length?a===c?1:1*b.lcsLength(a,c)/Math.max(a.length,c.length):1}},{key:"distance",value:function distance(a,b){return Similarity.checkThanosType(a),Similarity.checkRivalType(b),a===b?0:1-this.similarity(a,b)}}],[{key:"lcsLength",value:function lcsLength(a,b){Similarity.checkThanosType(a),Similarity.checkRivalType(b),a=Similarity.initParams(a,b)[0],b=Similarity.initParams(a,b)[1];for(var c=[a.length,b.length],d=c[0],e=c[1],f=_toConsumableArray(Array(d+1)).map(function(){return Array(e+1).fill(0)}),g=1;g<=d;++g)for(var h=1;h<=e;++h)f[g][h]=a[g-1]===b[h-1]?f[g-1][h-1]+1:Math.max(f[g][h-1],f[g-1][h]);return f[d][e]}}]),b}(Similarity);
"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}var Similarity=require("../interface/Similarity");module.exports=function(a){function b(){return _classCallCheck(this,b),_possibleConstructorReturn(this,_getPrototypeOf(b).call(this))}return _inherits(b,a),_createClass(b,[{key:"similarity",value:function similarity(a,c){return Similarity.checkThanosType(a),Similarity.checkRivalType(c),a=Similarity.initParams(a,c)[0],c=Similarity.initParams(a,c)[1],a.length||c.length?a===c?1:1*b.lcsLength(a,c)/Math.max(a.length,c.length):1}},{key:"distance",value:function distance(a,b){return Similarity.checkThanosType(a),Similarity.checkRivalType(b),a===b?0:1-this.similarity(a,b)}}],[{key:"lcsLength",value:function lcsLength(a,b){Similarity.checkThanosType(a),Similarity.checkRivalType(b),a=Similarity.initParams(a,b)[0],b=Similarity.initParams(a,b)[1];for(var c=[a.length,b.length],d=c[0],e=c[1],f=_toConsumableArray(Array(d+1)).map(function(){return Array(e+1).fill(0)}),g=1;g<=d;++g)for(var h=1;h<=e;++h)f[g][h]=a[g-1]===b[h-1]?f[g-1][h-1]+1:Math.max(f[g][h-1],f[g-1][h]);return f[d][e]}}]),b}(Similarity);
{
"name": "string-comparison",
"version": "1.0.8",
"version": "1.0.9",
"description": "A library implementing different string similarity",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc