Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jaycetde committed Jan 22, 2014
0 parents commit 451838b
Show file tree
Hide file tree
Showing 7 changed files with 513 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitattributes
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
217 changes: 217 additions & 0 deletions .gitignore
@@ -0,0 +1,217 @@
#################
## Eclipse
#################

*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath


#################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml
*.pubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf

#############
## Windows detritus
#############

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac crap
.DS_Store


#############
## Python
#############

*.py[co]

# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

#Mr Developer
.mr.developer.cfg

node_modules
5 changes: 5 additions & 0 deletions Makefile
@@ -0,0 +1,5 @@

test:
@./node_modules/.bin/mocha --reporter spec

.PHONY: test
31 changes: 31 additions & 0 deletions README.md
@@ -0,0 +1,31 @@
# congruent

Deep comparison of two variables

This is different from [deep-equal](https://github.com/substack/node-deep-equal) in that it will compare
Buffers, Regular Expressions, and NaN (In my opinion, NaN should equal NaN)

```javascript

var congruent = require('congruent');

congruent([1, 2, 3], new Array(1, 2, 3));
// true;

congruent(NaN, NaN);
// true;

congruent({ a: [1, 2, 3] }, { a: [1, 3, 2] });
// false;

```

## congruent(a, b, strict)

* strict - Use strict comparison (===) between primitives (Boolean, String, Number) (default: false)

## Installation

```bash
npm install congruent
```
85 changes: 85 additions & 0 deletions index.js
@@ -0,0 +1,85 @@
var fastApply = require('fast-apply')
, isArgs = require('is-args')
;

module.exports = congruent;

function congruent(actual, expected, strict) {
if (actual === expected) return true;

// isNaN test
if (actual !== actual && expected !== expected) return true;

var actualType = typeof actual
, expectedType = typeof expected
, i
;

if (actualType !== 'object' && expectedType !== 'object') return strict ? actual === expected : actual == expected;

// null is an object, but cannot have properties; stop here
if (actual === null || expected === null) return false;

if (actualType !== expectedType) return false;

if (actual.prototype !== expected.prototype) return false;

if (actual instanceof Date) return actual.getTime() === expected.getTime();

if (actual instanceof RegExp) {
return actual.source === expected.source
&& actual.lastIndex === expected.lastIndex
&& actual.global === expected.global
&& actual.multiline === expected.multiline
&& actual.ignoreCase === expected.ignoreCase
;
}

if (Buffer && Buffer.isBuffer(actual)) {
if (actual.length !== expected.length) return false;

i = actual.length;

while (--i >= 0) {
if (actual[i] !== expected[i]) return false;
}

return true;
}

var actualArg = isArgs(actual)
, expectedArg = isArgs(expected)
;

if (actualArg || expectedArg) {
if (!actualArg || !expectedArg) return false;
actual = fastApply(Array, null, actual);
expected = fastApply(Array, null, expected);
}

var actualKeys = Object.keys(actual)
, expectedKeys = Object.keys(expected)
, key
;

if (actualKeys.length !== expectedKeys.length) return false;

actualKeys.sort();
expectedKeys.sort();

i = actualKeys.length;

while (--i >= 0) {
if (actualKeys[i] !== expectedKeys[i]) return false;
}

i = actualKeys.length;

while (--i >= 0) {
key = actualKeys[i];
if (!congruent(actual[key], expected[key], strict)) return false;
}

return true;

}

0 comments on commit 451838b

Please sign in to comment.