Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fuzzyjs

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fuzzyjs - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

5

build/fuzzy.js

@@ -75,2 +75,5 @@ 'use strict';

// Keep original str for case
var originalStr = str;
opts = _extends({

@@ -104,3 +107,3 @@ caseSensitive: false,

if (c === q[pos]) {
result += opts.before + c + opts.after;
result += opts.before + originalStr[i] + opts.after;

@@ -107,0 +110,0 @@ // Move to the next pattern character

2

build/fuzzy.min.js

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

"use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj};var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};var isArray=function isArray(arr){return Object.prototype.toString.call(arr)==="[object Array]"};var fuzzy={test:function test(q,str){var caseSensitive=arguments.length<=2||arguments[2]===undefined?false:arguments[2];if(typeof q!=="string"||typeof str!=="string"){return-1}if(!str){return-1}if(!q){return true}if(!caseSensitive){q=q.toLowerCase();str=str.toLowerCase()}var pos=0;var i=0;while(i<str.length){if(str[i]===q[pos]){pos+=1}++i}return pos===q.length},match:function match(q,str,opts){if(typeof q!=="string"||typeof str!=="string"){return{score:0,result:str}}if(!str){return{score:0,result:str}}if(!q){return{score:1,result:str}}opts=_extends({caseSensitive:false,before:"",after:""},opts);if(!opts.caseSensitive){q=q.toLowerCase();str=str.toLowerCase()}var result="";var steps=0;var pos=0;var lastI=0;var i=0;while(i<str.length){var c=str[i];if(c===q[pos]){result+=opts.before+c+opts.after;pos+=1;steps+=i-lastI;lastI=i}else{result+=c}++i}if(pos===q.length){var score=q.length/(steps+1);return{score:score,result:result}}return{score:0,result:str}},filter:function filter(q,set,opts){if(!isArray(set)){return[]}if(typeof q!=="string"||!q){return set}opts=_extends({caseSensitive:false,before:"",after:""},opts);var results=[];var i=0;while(i<set.length){var str=set[i];var result=fuzzy.match(q,str,opts);if(result.score>0){results.push(result)}++i}return results.sort(function(a,b){return b.score-a.score}).map(function(elem){return elem.result})}};(function(root,factory){if(typeof define==="function"&&define.amd){define([],factory)}else if((typeof module==="undefined"?"undefined":_typeof(module))==="object"&&module.exports){module.exports=factory()}else{root.returnExports=factory()}})(undefined,function(){return fuzzy});
"use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj};var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};var isArray=function isArray(arr){return Object.prototype.toString.call(arr)==="[object Array]"};var fuzzy={test:function test(q,str){var caseSensitive=arguments.length<=2||arguments[2]===undefined?false:arguments[2];if(typeof q!=="string"||typeof str!=="string"){return-1}if(!str){return-1}if(!q){return true}if(!caseSensitive){q=q.toLowerCase();str=str.toLowerCase()}var pos=0;var i=0;while(i<str.length){if(str[i]===q[pos]){pos+=1}++i}return pos===q.length},match:function match(q,str,opts){if(typeof q!=="string"||typeof str!=="string"){return{score:0,result:str}}if(!str){return{score:0,result:str}}if(!q){return{score:1,result:str}}var originalStr=str;opts=_extends({caseSensitive:false,before:"",after:""},opts);if(!opts.caseSensitive){q=q.toLowerCase();str=str.toLowerCase()}var result="";var steps=0;var pos=0;var lastI=0;var i=0;while(i<str.length){var c=str[i];if(c===q[pos]){result+=opts.before+originalStr[i]+opts.after;pos+=1;steps+=i-lastI;lastI=i}else{result+=c}++i}if(pos===q.length){var score=q.length/(steps+1);return{score:score,result:result}}return{score:0,result:str}},filter:function filter(q,set,opts){if(!isArray(set)){return[]}if(typeof q!=="string"||!q){return set}opts=_extends({caseSensitive:false,before:"",after:""},opts);var results=[];var i=0;while(i<set.length){var str=set[i];var result=fuzzy.match(q,str,opts);if(result.score>0){results.push(result)}++i}return results.sort(function(a,b){return b.score-a.score}).map(function(elem){return elem.result})}};(function(root,factory){if(typeof define==="function"&&define.amd){define([],factory)}else if((typeof module==="undefined"?"undefined":_typeof(module))==="object"&&module.exports){module.exports=factory()}else{root.returnExports=factory()}})(undefined,function(){return fuzzy});
//# sourceMappingURL=build/fuzzy.min.js.map
{
"name": "fuzzyjs",
"version": "2.1.0",
"version": "2.1.1",
"description": "fuzzyjs is a fuzzy search algorithm in javascript",

@@ -5,0 +5,0 @@ "main": "build/fuzzy.js",

@@ -179,2 +179,15 @@ import assert from 'assert';

it('should keep case when using match (#6)', () => {
const str = 'Foo';
const q = 'fo';
const expectedScore = 1;
const expectedResult = '<strong>F</strong><strong>o</strong>o';
const result = fuzzy.match(q, str, { before: '<strong>', after: '</strong>' });
assert.equal(expectedScore, result.score);
assert.equal(expectedResult, result.result);
});
it('should match with caseSensitive set to true and pattern matching', () => {

@@ -181,0 +194,0 @@ const str = 'Lorem ipsum';

Sorry, the diff of this file is not supported yet

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