npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

is-something-equal

v0.1.3

Published

This module is designed to conceptually compare values.

Downloads

4

Readme

Intro

This module is designed to conceptually compare values. For example, if we try to compare objects with each other we always get false. But with this utility you can compare objects or other values and get true if they are conceptually same.

Module was developed because the author is faced with the problem of comparing objects in his project and the functionality is for the most part implemented precisely for these purposes.

Usage

Presently, module consists of one function: isEqual. First two arguments its values for comparison. Then you can pass object with settings for this comparison.

Settings:

  • fieldsToSkipInObjects [default: none] - an option where you can list the fields that should be skipped when comparing objects (array of strings). For example, you have different fields createdAt or updatedAt, but otherwise the objects are the same.

  • deepSkipping [default: true] - an option that is relevant only if you specify fieldsToSkipInObjects. By using it, you can specify whether to skip options only at the first level of nesting, or at all. By default it will skip all fields from first option on all levels.

  • isArrayOrderImportant [default: true] - an option, that shows is important the order of the elements in the array or not. If false, [1, 2, 3] will be equal to [3, 2, 1]. By default - not.

  • limitArrayCompare [default: unlimited] - an option that you can use if you need to slice each array from 0 element to to the specified value.

  • nullEqualsToUndefined [default: false] - all comparisons that uses in module are strict, so by default null is not equal to undefined.

  • stringsToFixedCase [default: false] - if you need to make all strings to the same register.

  • regExpToString [default: false] - an option, that you can use if you wanna compare some RegExp as string.

  • compareNot [default: none] - list of types that you don't want to compare in objects (array of strings). Available types are:

    • number,
    • string,
    • boolean,
    • object,
    • undefined,
    • function,
    • array,
    • regexp,
    • null,
    • symbol,
    • date.

    If you will not use option strongCompareNot, module will compare values just by their types. So, if compareNot = ['array'] and strongCompareNot is not defined, arrays [1, 2, 3] and [ {first: 'field'} ] will be equal. But if the array and object will be compared, it will be false.

  • strongCompareNot [default: false] - if you set it true, when module find in the same field array and object or null and number, etc, (in different objects that you are comparing), it will return true. It will skip all unavailable types as true.

  • objectToValue [default: false] - an option< that can be used if you need to get from String object, Number object or Boolean object their values and only after compare it.

Ok, if it wasn't too strange and you still wanna use it, lets see example.

Example

'use strict';  
const isEqual = require('is-something-equal');  
  
const test1 = {  
  test: null,  
  toSkip: 'str1',  
  first: {width: 320, params: ['-thumbnail', [1, 3, 2], `320x320^`]},  
  second: [3, [null, {first: [{second: 'sss'}], date: Date.now()}]],  
  reg: 'some text',  
};  
const test2 = {  
  test: undefined,  
  toSkip: 'str2',  
  first: {width: 320, params: [`320x320^`, [1, 2, 3], '-thumbnail']},  
  second: [3, [null, {first: [{second: 'sss'}], date: Date.now()}]],  
  reg: new RegExp('some text'),  
};  
  
console.log(isEqual(5, 5)); // true  
console.log(isEqual({first: 1, second: 2}, {second: 2, first: 1})); // true  
console.log(isEqual(test1, test2)); // false  
console.log(isEqual(test1, test2, {  
  fieldsToSkipInObjects: ['toSkip'],  
  isArrayOrderImportant: false,  
  regExpToString: true,  
  nullEqualsToUndefined: true  
})); // true  
  
const test3 = {  
  first: [1, 2, 3],  
  second: new Number(5)  
};  
const test4 = {  
  first: { field: 'some field' },  
  second: new Number(5)  
};  
  
console.log(isEqual(test3, test4)); // false  
console.log(isEqual(test3, test4, {  
  objectToValue: true,  
  compareNot: ['array']  
})); // false  
console.log(isEqual(test3, test4, {  
  objectToValue: true,  
  strongCompareNot: true,  
  compareNot: ['array']  
})); // true

Finally

If you have some ideas how to improve my code, some advice's or features to add, please, contact me [email protected].

P.S. While module is in development, I do not guarantee full version compatibility.