Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-code

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-code

Blazing fast hash code generator that supports every possible javascript value.

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
56K
decreased by-54.04%
Maintainers
1
Weekly downloads
 
Created
Source

  

⛓️ Object Code




Stars License Size Downloads NPM Coverage



object-code is a blazing fast hash code generator that supports every possible javascript value.



Table of contents


Installing

Node
npm install --save object-code
# or
yarn add object-code
const { hashCode } = require('object-code');
// or
import { hashCode } from 'object-code';
Browser

Npm

<!-- Replace latest with the desired version -->

<script
  crossorigin
  src="https://cdn.jsdelivr.net/npm/object-code@latest/index.min.js"
></script>
<!-- or -->
<script crossorigin src="https://unpkg.com/object-code@latest/index.min.js"></script>
const { hashCode } = window.objectCode;

Getting Started

Fast hash is an blazing fast object hash code generator. It generates unique hashes for objects, arrays, functions, symbols and etc.

You can use it to index objects in a object/array/map/set, to compare objects or to just generate unique ids.

import { hashCode } from 'object-code';

const myWeirdObject = {
  name: 'Arthur',
  age: 20,
  address: {
    private: true
  },
  sayHello: function () {
    console.log('Hello!');
  },
  id: Symbol('arthur'),
  birth: new Date(1990, 1, 1),
  tags: ['person', 'male', 'programmer']
  // etc
};

const hash = hashCode(myWeirdObject);
// 1230491235

Types compatibility

See all unique values at test/values.ts

Version compatibility

This library is always seeking an faster implementation, doesn't matter if the hash code will change.

You shouldn't rely on cross version compatibility, and even if so, run some tests before upgrading.

I'll make an note on hash generation changes.

Benchmark

Simple benchmark with object-hash and this package.

# node dist/benchmark.js

Number of generated hashes per second
Total of 100000 runs

Object tests:

0: object-code -> 35,984 runs/s
1: object-hash -> 11,307 runs/s


Json tests:

0: object-code -> 571,429 runs/s
1: object-hash -> 218,341 runs/s


Raw string tests:

0: object-code -> 3,448,276 runs/s
1: object-hash -> 251,192 runs/s

License

Licensed under the MIT. See LICENSE for more informations.


Contact

See my contact information on my github profile or open a new issue.


FAQs

Package last updated on 21 Feb 2022

Did you know?

Socket

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.

Install

Related posts

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