
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
similar-object
Advanced tools
A utility to compare objects with numeric fields and get back a score of how close they are.
A utility to compare objects with numeric fields and get back a score of how close they are.
Can then be used together with .sort() to get the most similar objects.
Useful for getting related objects that don't match fully.
npm install similar-object
# or
yarn add similar-object
import { similarObject } from 'similar-object'
// we are looking at this
const current = { price: 800, rooms: 3, area: 80 }
// which one of these is closest to current?
const unit1 = { price: 1000, rooms: 3, area: 100 }
const unit2 = { price: 1000, rooms: 5, area: 50 }
const unit3 = { price: 1500, rooms: 5, area: 50 }
const units = [unit1, unit2, unit3]
const similarConfig = {
price: 1, // weight 1
rooms: 2, // it's more important so we boost the score of rooms by 2
area: 3, // area is most important, so we boost it by 3
}
units.sort(
(a, b) => similarObject(current, a, similarConfig) - similarObject(current, b, similarConfig),
)
// units are now sorted according to how similar they are
FAQs
A utility to compare objects with numeric fields and get back a score of how close they are.
We found that similar-object demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.

Product
Bringing supply chain security to the next generation of JavaScript package managers