Socket
Socket
Sign inDemoInstall

lunr

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lunr - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

28

lib/match_data.js

@@ -7,9 +7,25 @@ /**

* @constructor
* @property {object} metadata - A collection of metadata associated with this document.
* @param {string} term - The term this match data is associated with
* @param {string} field - The field in which the term was found
* @param {object} metadata - The metadata recorded about this term in this field
* @property {object} metadata - A cloned collection of metadata associated with this document.
* @see {@link lunr.Index~Result}
*/
lunr.MatchData = function (term, field, metadata) {
this.metadata = {}
this.metadata[term] = {}
this.metadata[term][field] = metadata
var clonedMetadata = Object.create(null),
metadataKeys = Object.keys(metadata)
// Cloning the metadata to prevent the original
// being mutated during match data combination.
// Metadata is kept in an array within the inverted
// index so cloning the data can be done with
// Array#slice
for (var i = 0; i < metadataKeys.length; i++) {
var key = metadataKeys[i]
clonedMetadata[key] = metadata[key].slice()
}
this.metadata = Object.create(null)
this.metadata[term] = Object.create(null)
this.metadata[term][field] = clonedMetadata
}

@@ -34,3 +50,3 @@

if (this.metadata[term] == undefined) {
this.metadata[term] = {}
this.metadata[term] = Object.create(null)
}

@@ -43,3 +59,3 @@

if (this.metadata[term][field] == undefined) {
this.metadata[term][field] = {}
this.metadata[term][field] = Object.create(null)
}

@@ -46,0 +62,0 @@

{
"name": "lunr",
"description": "Simple full-text search in your browser.",
"version": "2.1.1",
"version": "2.1.2",
"author": "Oliver Nightingale",

@@ -6,0 +6,0 @@ "keywords": [

@@ -30,3 +30,13 @@ suite('lunr.MatchData', function () {

})
test('does not mutate source data', function () {
var metadata = { foo: [1] },
matchData1 = new lunr.MatchData('foo', 'title', metadata),
matchData2 = new lunr.MatchData('foo', 'title', metadata)
matchData1.combine(matchData2)
assert.deepEqual(metadata.foo, [1])
})
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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