New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nanoutils

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nanoutils - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3-dev.0

lib/apply/apply.test.js

72

lib/eq/eq.test.js
var eq = require('.')
test('confirms variables are equal', () => {
test('confirms that strings are equal', () => {
expect(eq('1', '1')).toBeTruthy()
expect(eq('1', 'a')).toBeFalsy()
})
test('confirms that numbers are equal', () => {
expect(eq(1, 1)).toBeTruthy()
expect(eq(1, -1)).toBeFalsy()
})
test('confirms that variables are not equal', () => {
expect(eq(1, 'lol')).toBeFalsy()
describe('confirms that arrays are equal', () => {
test('default arrays', () => {
expect(eq([1, 2, 3], [1, 2, 3])).toBeTruthy()
expect(eq([1, 2, 3], [1, 2, 'aasdf'])).toBeFalsy()
})
test('nested arrays', () => {
expect(eq([1, 2, [3, [4]]], [1, 2, [3, [4]]])).toBeTruthy()
expect(eq([1, 2, [3, [4]]], [1, 2, [3, [5]]])).toBeFalsy()
})
test('circular arrays', () => {
var a = [1, 2, 3]
var b = [1, 2, 3]
a.push(b, [b], [[b]])
b.push(b, [b], [[b]])
expect(eq(a, b)).toBeTruthy()
})
test('mirror arrays', () => {
var a = [1, 2, 3]
var b = [1, 2, 3]
a.push(a)
b.push(b)
expect(eq(a, b)).toBeTruthy()
})
})
describe('confirms that objects are equal', () => {
test('default objects', () => {
expect(eq({ a: 1, b: 'test' }, { a: 1, b: 'test' })).toBeTruthy()
expect(eq({ a: 2, b: 'test' }, { a: 1, b: 'test' })).toBeFalsy()
})
test('nested objects', () => {
var a = { a: 1, b: { c: { d: 'test', lol: null } } }
var b = { a: 1, b: { c: { d: 'test', lol: null } } }
var c = { a: 1, b: { c: null } }
expect(eq(a, b)).toBeTruthy()
expect(eq(a, c)).toBeFalsy()
})
test('circular objects', () => {
var a = { a: 1, b: 2, c: 3 }
var b = { a: 1, b: 2, c: 3 }
a.d = a
b.d = a
expect(eq(a, b)).toBeTruthy()
})
test('mirror objects', () => {
var a = { a: 1, b: 2, c: 3 }
var b = { a: 1, b: 2, c: 3 }
a.d = a
b.d = b
expect(eq(a, b)).toBeTruthy()
})
})
test('confirms that functions are equal', () => {
var a = function a() {}
expect(eq(a, a)).toBeTruthy()
})

@@ -1,5 +0,47 @@

var curry = require('../curry')
var curryN = require('../curryN')
module.exports = curry(function eq(a, b) {
return a === b
})
var map
try {
map = Map
} catch (_) {}
var set
try {
set = Set
} catch (_) {}
function eq(a, b, circulars) {
var circ = (circulars || []).concat([a, b])
if (a === b) return true
if (a === null || b == null) return a === b
if (a === undefined || b == undefined) return a === b
if (typeof a !== typeof b) return false
if (a instanceof Date) {
return a.getTime() === b.getTime()
}
if (a instanceof RegExp) {
return a.toString() === b.toString()
}
if (set && a instanceof set) {
return eq(a.values(), b.values(), circ)
}
if (map && a instanceof map) {
return eq(a.entries(), b.entries(), circ)
}
if (typeof a === 'object' && typeof b === 'object') {
var keys = Object.keys(a)
return (
keys.length === Object.keys(b).length &&
keys.every(function(key) {
return circ.some(function(c) {
return c === a[key]
})
? a[key] === b[key]
: eq(a[key], b[key], circ)
})
)
}
return false
}
module.exports = curryN(2, eq)

3

lib/eqBy/index.js

@@ -0,5 +1,6 @@

var eq = require('../eq')
var curry = require('../curry')
module.exports = curry(function eqBy(cb, a, b) {
return cb(a) === cb(b)
return eq(cb(a), cb(b))
})
{
"name": "nanoutils",
"version": "0.0.2",
"version": "0.0.3-dev.0",
"description": "Tiniest JavaScript utils library",
"main": "index.js",
"module": "index.js",
"repository": "https://github.com/kelin2025/nanoutils",

@@ -7,0 +8,0 @@ "author": "Kelin2025 <kelin2025@yandex.ru>",

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