js-solr-highlighter
Advanced tools
Comparing version 0.8.1 to 0.8.2
36
index.js
@@ -38,3 +38,3 @@ import TextAnnotator from 'text-annotator' | ||
'will', | ||
'with' | ||
'with', | ||
] | ||
@@ -56,3 +56,3 @@ | ||
highlightIdPattern, | ||
caseSensitive | ||
caseSensitive, | ||
} = options | ||
@@ -68,3 +68,3 @@ const searchFunc = | ||
const regex = new RegExp(c, 'g') | ||
return s.replace(regex, char => { | ||
return s.replace(regex, (char) => { | ||
return '\\' + char | ||
@@ -115,6 +115,6 @@ }) | ||
} | ||
fieldVals.forEach(fv => { | ||
fieldVals.forEach((fv) => { | ||
q = q.replace(fv[0], fv[1]) | ||
}) | ||
fieldVals2.forEach(fv => { | ||
fieldVals2.forEach((fv) => { | ||
q = q.replace(fv, esc(fv, ':')) | ||
@@ -139,3 +139,5 @@ }) | ||
.split(/\s/) | ||
.map(t => t.replace(/^[^a-zA-Z0-9]+/, '').replace(/[^a-zA-Z0-9]+$/, '')) | ||
.map((t) => | ||
t.replace(/^[^a-zA-Z0-9]+/, '').replace(/[^a-zA-Z0-9]+$/, '') | ||
) | ||
return words.concat(terms) | ||
@@ -150,5 +152,5 @@ } | ||
allOperators && | ||
allOperators.every(operator => operator === '"operator":"<implicit>"') && | ||
allOperators.every((operator) => operator === '"operator":"<implicit>"') && | ||
allFields && | ||
allFields.every(field => field === '"field":"<implicit>"') && | ||
allFields.every((field) => field === '"field":"<implicit>"') && | ||
!left.quoted | ||
@@ -165,3 +167,3 @@ ) { | ||
} | ||
const canHighlight = field => | ||
const canHighlight = (field) => | ||
highlightedFields === undefined | ||
@@ -214,3 +216,3 @@ ? field | ||
words = words.filter( | ||
word => | ||
(word) => | ||
word.length && !isStopWord(word) && !['AND', 'OR', 'NOT'].includes(word) | ||
@@ -221,16 +223,16 @@ ) | ||
const highlighter = new TextAnnotator({ | ||
content | ||
content, | ||
}) | ||
words.forEach(word => { | ||
words.forEach((word) => { | ||
let res = highlighter[searchFunc](word, { | ||
directSearchOptions: { | ||
caseSensitive: caseSensitive !== undefined && caseSensitive | ||
} | ||
caseSensitive: caseSensitive !== undefined && caseSensitive, | ||
}, | ||
}) | ||
res = searchFunc === 'search' ? [res] : res | ||
res.forEach(highlightIndex => { | ||
res.forEach((highlightIndex) => { | ||
const loc = highlighter.highlights[highlightIndex].loc | ||
const text = highlighter.stripedHTML | ||
const fixVaild = c => { | ||
const fixVaild = (c) => { | ||
const letters = /^[0-9a-zA-Z]+$/ | ||
@@ -247,3 +249,3 @@ return !c.match(letters) | ||
highlightIdPattern, | ||
highlightClass | ||
highlightClass, | ||
}) | ||
@@ -250,0 +252,0 @@ } |
@@ -153,5 +153,5 @@ import { isStopWord, highlightByQuery } from './index.js' | ||
'text_hl', | ||
'text_synonyms' | ||
'text_synonyms', | ||
], | ||
highlightedFields: ['TITLE', '<implicit>'] | ||
highlightedFields: ['TITLE', '<implicit>'], | ||
} | ||
@@ -339,3 +339,3 @@ | ||
// throw errors but work; improve later*** | ||
// test('PUBLISHER:"[Institute for Quality and Efficiency in Health Care (IQWiG)][Cologne (Germany)]"', () => { | ||
// ('PUBLISHER:"[Institute for Quality and Efficiency in Health Care (IQWiG)][Cologne (Germany)]"', () => { | ||
// const query = 'PUBLISHER:"[Institute for Quality and Efficiency in Health Care (IQWiG)][Cologne (Germany)]"' | ||
@@ -348,3 +348,3 @@ // const content = 'Relationship between volume of services and quality of treatment outcome for surgical treatment of lung carcinoma IQWiG Reports – Commission No. V18-03' | ||
// test('PUBLISHER:"[Canadian Agency for Drugs and Technologies in Health][Ottawa (ON)]', () => { | ||
// ('PUBLISHER:"[Canadian Agency for Drugs and Technologies in Health][Ottawa (ON)]', () => { | ||
// const query = 'PUBLISHER:"[Canadian Agency for Drugs and Technologies in Health][Ottawa (ON)]' | ||
@@ -500,3 +500,3 @@ // const content = 'Codeine for Acute Pain for Urological or General Surgery Patients: A Review of Clinical Effectiveness' | ||
describe('tests for the options argument', () => { | ||
test('test the validFields option', () => { | ||
test('the validFields option', () => { | ||
const query = 'TITLE:blood AND CONTENT:cell' | ||
@@ -506,3 +506,3 @@ const content = | ||
const received = highlightByQuery(query, content, { | ||
validFields: ['TITLE'] | ||
validFields: ['TITLE'], | ||
}) | ||
@@ -514,3 +514,3 @@ const expected = | ||
// test('test the validFields option', () => { | ||
// ('the validFields option', () => { | ||
// const query = 'TITLE:blood OR cell' | ||
@@ -527,3 +527,3 @@ // const content = | ||
test('test the highlightedFields option', () => { | ||
test('the highlightedFields option', () => { | ||
const query = 'TITLE:blood OR CONTENT:cell' | ||
@@ -534,3 +534,3 @@ const content = | ||
validFields: ['TITLE', 'CONTENT'], | ||
highlightedFields: ['CONTENT'] | ||
highlightedFields: ['CONTENT'], | ||
}) | ||
@@ -542,3 +542,3 @@ const expected = | ||
test('test the highlightAll option', () => { | ||
test('the highlightAll option', () => { | ||
const query = 'blood' | ||
@@ -548,3 +548,3 @@ const content = | ||
const received = highlightByQuery(query, content, { | ||
highlightAll: false | ||
highlightAll: false, | ||
}) | ||
@@ -556,3 +556,3 @@ const expected = | ||
test('test the highlightIdPattern option', () => { | ||
test('the highlightIdPattern option', () => { | ||
const query = 'breast cancer' | ||
@@ -562,3 +562,3 @@ const content = | ||
const received = highlightByQuery(query, content, { | ||
highlightIdPattern: 'new-highlight-' | ||
highlightIdPattern: 'new-highlight-', | ||
}) | ||
@@ -570,3 +570,3 @@ const expected = | ||
test('test the highlightClass option', () => { | ||
test('the highlightClass option', () => { | ||
const query = 'breast cancer' | ||
@@ -576,3 +576,3 @@ const content = | ||
const received = highlightByQuery(query, content, { | ||
highlightClass: 'new-highlight' | ||
highlightClass: 'new-highlight', | ||
}) | ||
@@ -584,7 +584,7 @@ const expected = | ||
test('test the caseSensitive option', () => { | ||
test('the caseSensitive option', () => { | ||
const query = 'covid-19' | ||
const content = 'Clinical observation and management of COVID-19 patients.' | ||
const received = highlightByQuery(query, content, { | ||
caseSensitive: true | ||
caseSensitive: true, | ||
}) | ||
@@ -591,0 +591,0 @@ const expected = 'Clinical observation and management of COVID-19 patients.' |
{ | ||
"name": "js-solr-highlighter", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"description": "A JavaScript library for highlighting HTML text based on the query in the lucene/solr query syntax", | ||
@@ -21,13 +21,13 @@ "main": "build/index.js", | ||
"devDependencies": { | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "^7.4.3", | ||
"@babel/preset-env": "^7.4.3", | ||
"babel-jest": "^24.7.1", | ||
"eslint": "^5.15.3", | ||
"eslint-config-prettier": "^4.3.0", | ||
"eslint-plugin-jest": "^22.4.1", | ||
"eslint-plugin-prettier": "^3.1.0", | ||
"jest": "^24.5.0", | ||
"@babel/cli": "^7.13.0", | ||
"@babel/core": "^7.13.8", | ||
"@babel/preset-env": "^7.13.9", | ||
"babel-jest": "^26.6.3", | ||
"eslint": "^7.21.0", | ||
"eslint-config-prettier": "^8.1.0", | ||
"eslint-plugin-jest": "^24.1.5", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"jest": "^26.6.3", | ||
"pre-commit": "^1.2.2", | ||
"prettier": "1.18.2" | ||
"prettier": "2.2.1" | ||
}, | ||
@@ -34,0 +34,0 @@ "babel": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
948
0
46961
6