Socket
Socket
Sign inDemoInstall

autosuggest-highlight

Package Overview
Dependencies
1
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.2.1 to 3.3.0

46

match/index.js

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

var removeDiacritics = require('diacritic').clean;
const removeDiacritics = require('remove-accents').remove;
// https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions#Using_special_characters
var specialCharsRegex = /[.*+?^${}()|[\]\\]/g;
const specialCharsRegex = /[.*+?^${}()|[\]\\]/g;
// http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.2.6
var wordCharacterRegex = /[a-z0-9_]/i;
const wordCharacterRegex = /[a-z0-9_]/i;
var whitespacesRegex = /\s+/;
const whitespacesRegex = /\s+/;

@@ -17,3 +17,3 @@ function escapeRegexCharacters(str) {

subject = subject || {};
Object.keys(subject).forEach(function(key) {
Object.keys(subject).forEach((key) => {
baseObject[key] = !!subject[key];

@@ -31,6 +31,4 @@ });

var cleanedTextArray = Array.from(text).map(function(x) {
return removeDiacritics(x);
});
var cleanedText = cleanedTextArray.join('');
const cleanedTextArray = Array.from(text).map((x) => removeDiacritics(x));
let cleanedText = cleanedTextArray.join('');

@@ -44,11 +42,10 @@ query = removeDiacritics(query);

// If query is blank, we'll get empty string here, so let's filter it out.
.filter(function(word) {
return word.length > 0;
})
.reduce(function(result, word) {
var wordLen = word.length;
var prefix =
.filter((word) => word.length > 0)
.reduce((result, word) => {
const wordLen = word.length;
const prefix =
!options.insideWords && wordCharacterRegex.test(word[0]) ? '\\b' : '';
var regex = new RegExp(prefix + escapeRegexCharacters(word), 'i');
var occurrence, index;
const regex = new RegExp(prefix + escapeRegexCharacters(word), 'i');
let occurrence;
let index;

@@ -64,14 +61,13 @@ occurrence = regex.exec(cleanedText);

var cleanedLength = cleanedTextArray
const cleanedLength = cleanedTextArray
.slice(index, index + wordLen)
.join('').length;
var offset = wordLen - cleanedLength;
const offset = wordLen - cleanedLength;
var initialOffset =
const initialOffset =
index - cleanedTextArray.slice(0, index).join('').length;
var wordOffset = offset;
var indexes = [
const indexes = [
index + initialOffset,
index + wordLen + initialOffset + wordOffset
index + wordLen + initialOffset + offset
];

@@ -98,6 +94,4 @@

}, [])
.sort(function(match1, match2) {
return match1[0] - match2[0];
})
.sort((match1, match2) => match1[0] - match2[0])
);
};
{
"name": "autosuggest-highlight",
"version": "3.2.1",
"version": "3.3.0",
"description": "Utilities for highlighting text in autosuggest and autocomplete components",

@@ -23,14 +23,18 @@ "repository": {

"dependencies": {
"diacritic": "0.0.2"
"remove-accents": "^0.4.2"
},
"devDependencies": {
"chai": "^4.1.2",
"eslint": "^4.9.0",
"husky": "^0.14.3",
"lint-staged": "^4.3.0",
"mocha": "^4.0.1",
"nyc": "^11.2.1",
"prettier": "1.7.4",
"rimraf": "^2.6.2",
"webpack": "^3.8.1"
"chai": "^4.3.6",
"eslint": "^8.18.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"prettier": "2.7.1",
"rimraf": "^3.0.2",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0"
},

@@ -37,0 +41,0 @@ "files": [

module.exports = function parse(text, matches) {
var result = [];
const result = [];
if (matches.length === 0) {
result.push({
text: text,
text,
highlight: false
});
} else {
if (matches[0][0] > 0) {
result.push({
text: text.slice(0, matches[0][0]),
highlight: false
});
}
} else if (matches[0][0] > 0) {
result.push({
text: text.slice(0, matches[0][0]),
highlight: false
});
}
matches.forEach(function(match, i) {
var startIndex = match[0];
var endIndex = match[1];
matches.forEach((match, i) => {
const startIndex = match[0];
const endIndex = match[1];

@@ -22,0 +20,0 @@ result.push({

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc