Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
cos-similarity
Advanced tools
Computes the cosine similarity between two vectors
npm install cos-similarity
cosSimilarity(vectorA, vectorB)
Returns the cosine similarity between the given vectorA
and vectorB
. Returns 0
when given a zero vector, []
, undefined
or nothing.
import cosSimilarity from "cos-similarity";
cosSimilarity([1, 2, 4], [1, 0, 2]); // -> 0.8783100656536799
cosSimilarity([1, 2, 0], [1, 2, 0]); // -> 1
cosSimilarity([2, 0, 0], [0, 2, 0]); // -> 0
cosSimilarity([-1, -2, 0], [1, 2, 0]); // -> -1
To run the benchmark, clone the repositry and run the bench script:
npm run bench
benchmark time (avg) (min … max)
-------------------------------------------------------------------
• cosine similarity modules
-------------------------------------------------------------------
cos-similarity 249 ns/iter (247 ns … 319 ns)
compute-cosine-similarity 854 ns/iter (829 ns … 428 µs)
cosine-similarity 14'251 ns/iter (13'680 ns … 229 µs)
cosine-similarity-threshold 879 ns/iter (802 ns … 310 µs)
summary for cosine similarity modules
cos-similarity
3.43x faster than compute-cosine-similarity
3.53x faster than cosine-similarity-threshold
57.25x faster than cosine-similarity
FAQs
Computes the cosine similarity between two vectors
The npm package cos-similarity receives a total of 190 weekly downloads. As such, cos-similarity popularity was classified as not popular.
We found that cos-similarity demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.