Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
comparejs implements JavaScript's comparison operators the way you would expect them to be.
comparejs implements JavaScript's comparison operators the way you would expect them to be.
Category | Status |
---|---|
Version | |
Dependencies | |
Dev dependencies | |
Build | |
License |
$ npm install comparejs
To use comparejs you need to reference it from your application by adding the following line:
const { compare } = require('comparejs');
If you use TypeScript, use the following code instead:
import { compare } from 'comparejs';
array
, boolean
, function
, null
, number
, object
, string
and undefined
.number
and new Number()
.<
, <=
, >
and >=
by handling them as subsets.undefined
correctly, as <=
and >=
are problematic in plain JavaScript.Now you are able to use the various comparison operators. All you need to do is access the compare
object and use its functions:
Operator | Alias | Description |
---|---|---|
equal(left, right) | eq(left, right) | equal |
notEqual(left, right) | ne(left, right) | not equal |
lessThan(left, right) | lt(left, right) | less than |
lessThanOrEqual(left, right) | lte(left, right) | less than or equal |
greaterThan(left, right) | gt(left, right) | greater than |
greaterThanOrEqual(left, right) | gte(left, right) | greater than or equal |
identity(left, right) | id(left, right) | identity |
Please note that each comparison operator works on each combination of types and does what you would expect it to do.
For objects, there are special operators that compare by structure. Among other things, they can be used to verify objects against interfaces:
Operator | Alias | Description |
---|---|---|
equalByStructure(left, right) | eqs(left, right) | equal by structure |
notEqualByStructure(left, right) | nes(left, right) | not equal by structure |
lessThanByStructure(left, right) | lts(left, right) | less than by structure |
lessThanOrEqualByStructure(left, right) | ltes(left, right) | less than or equal by structure |
greaterThanByStructure(left, right) | gts(left, right) | greater than by structure |
greaterThanOrEqualByStructure(left, right) | gtes(left, right) | greater than or equal by structure |
Please note that these operators only work for objects. For any other type, they return false
.
To run quality assurance for this module use roboter:
$ npx roboter
FAQs
comparejs implements JavaScript's comparison operators the way you would expect them to be.
The npm package comparejs receives a total of 22,140 weekly downloads. As such, comparejs popularity was classified as popular.
We found that comparejs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers 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.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.