Product
Introducing Java Support in Socket
We're excited to announce that Socket now supports the Java programming language.
The sigmund npm package is used to generate unique fingerprints for objects. It is particularly useful for caching and memoization purposes, where you need a consistent and unique identifier for complex objects.
Generate Fingerprint
This feature allows you to generate a unique fingerprint for a given object. The fingerprint can be used to identify the object uniquely, which is useful in caching and memoization.
const sigmund = require('sigmund');
const obj = { a: 1, b: { c: 2 } };
const fingerprint = sigmund(obj);
console.log(fingerprint);
The object-hash package generates a hash value for an object. It offers more customization options compared to sigmund, such as different hashing algorithms and encoding formats.
The json-stable-stringify package provides a way to stringify objects in a consistent order, which can then be hashed or used as a unique identifier. It is more focused on producing a consistent JSON string representation of an object.
Similar to json-stable-stringify, this package offers a faster implementation for producing a consistent JSON string representation of an object. It is optimized for performance.
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.
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.
FAQs
Quick and dirty signatures for Objects.
The npm package sigmund receives a total of 1,132,043 weekly downloads. As such, sigmund popularity was classified as popular.
We found that sigmund demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Product
We're excited to announce that Socket now supports the Java programming language.
Security News
Socket detected a malicious Python package impersonating a popular browser cookie library to steal passwords, screenshots, webcam images, and Discord tokens.
Security News
Deno 2.0 is now available with enhanced package management, full Node.js and npm compatibility, improved performance, and support for major JavaScript frameworks.