sigmund

WebJar for sigmund

License

License

ISC
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

sigmund
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

sigmund
WebJar for sigmund
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/isaacs/sigmund

Download sigmund

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/sigmund/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>sigmund</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/sigmund/
implementation 'org.webjars.npm:sigmund:1.0.1'
// https://jarcasting.com/artifacts/org.webjars.npm/sigmund/
implementation ("org.webjars.npm:sigmund:1.0.1")
'org.webjars.npm:sigmund:jar:1.0.1'
<dependency org="org.webjars.npm" name="sigmund" rev="1.0.1">
  <artifact name="sigmund" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='sigmund', version='1.0.1')
)
libraryDependencies += "org.webjars.npm" % "sigmund" % "1.0.1"
[org.webjars.npm/sigmund "1.0.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

sigmund

Quick and dirty signatures for Objects.

This is like a much faster deepEquals comparison, which returns a string key suitable for caches and the like.

Usage

function doSomething (someObj) {
  var key = sigmund(someObj, maxDepth) // max depth defaults to 10
  var cached = cache.get(key)
  if (cached) return cached

  var result = expensiveCalculation(someObj)
  cache.set(key, result)
  return result
}

The resulting key will be as unique and reproducible as calling JSON.stringify or util.inspect on the object, but is much faster. In order to achieve this speed, some differences are glossed over. For example, the object {0:'foo'} will be treated identically to the array ['foo'].

Also, just as there is no way to summon the soul from the scribblings of a cocaine-addled psychoanalyst, there is no way to revive the object from the signature string that sigmund gives you. In fact, it's barely even readable.

As with util.inspect and JSON.stringify, larger objects will produce larger signature strings.

Because sigmund is a bit less strict than the more thorough alternatives, the strings will be shorter, and also there is a slightly higher chance for collisions. For example, these objects have the same signature:

var obj1 = {a:'b',c:/def/,g:['h','i',{j:'',k:'l'}]}
var obj2 = {a:'b',c:'/def/',g:['h','i','{jkl']}

Like a good Freudian, sigmund is most effective when you already have some understanding of what you're looking for. It can help you help yourself, but you must be willing to do some work as well.

Cycles are handled, and cyclical objects are silently omitted (though the key is included in the signature output.)

The second argument is the maximum depth, which defaults to 10, because that is the maximum object traversal depth covered by most insurance carriers.

Versions

Version
1.0.1