1.1.3 • Published 9 months ago

ohash v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

ohash

npm version npm downloads Github Actions Codecov bundle size

Super fast hashing library written in Vanilla JS

Usage

Install package:

# npm
npm install ohash

# yarn
yarn add ohash

# pnpm
pnpm install ohash

Import:

// ESM
import { hash, objectHash, murmurHash, sha256 } from "ohash";

// CommonJS
const { hash, objectHash, murmurHash, sha256 } = require("ohash");

hash(object, options?)

Converts object value into a string hash using objectHash and then applies sha256 with Base64 encoding (trimmed by length of 10).

Usage:

import { hash } from "ohash";

// "dZbtA7f0lK"
console.log(hash({ foo: "bar" }));

objectHash(object, options?)

Converts a nest object value into a stable and safe string for hashing.

Usage:

import { objectHash } from "ohash";

// "object:1:string:3:foo:string:3:bar,"
console.log(objectHash({ foo: "bar" }));

isEqual(obj1, obj2, options?)

Compare two objects using reference equality and stable object hashing.

Usage:

import { isEqual } from "ohash";

// true
console.log(isEqual({ a: 1, b: 2 }, { b: 2, a: 1 }));

diff(obj1, obj2, options?)

Compare two objects with nested hashing. Returns an array of changes.

Returned value is an array of diff entries with $key, $hash, $value and $props. When logging, a string version of changelog is displayed.

Usage:

import { diff } from "ohash";

const createObject = () => ({
  foo: "bar",
  nested: {
    y: 123,
    bar: {
      baz: "123",
    },
  },
});

const obj1 = createObject();
const obj2 = createObject();

obj2.nested.x = 123;
delete obj2.nested.y;
obj2.nested.bar.baz = 123;

const diff = diff(obj1, obj2);

// [-] Removed nested.y
// [~] Changed nested.bar.baz from "123" to 123
// [+] Added   nested.x
console.log(diff(obj1, obj2));

murmurHash(str)

Converts input string (of any length) into a 32-bit positive integer using MurmurHash3.

Usage:

import { murmurHash } from "ohash";

// "2708020327"
console.log(murmurHash("Hello World"));

sha256

Create a secure SHA 256 digest from input string.

import { sha256 } from "ohash";

// "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e"
console.log(sha256("Hello World"));

sha256base64

Create a secure SHA 256 digest in Base64 encoding from input string.

import { sha256base64 } from "ohash";

// "pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4"
console.log(sha256base64("Hello World"));

💻 Development

  • Clone this repository
  • Enable Corepack using corepack enable (use npm i -g corepack for Node.js < 16.10)
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

License

Made with 💛

Published under MIT License.

Based on puleos/object-hash by Scott Puleo, and implementations from perezd/node-murmurhash and garycourt/murmurhash-js by Gary Court and Austin Appleby and brix/crypto-js.

@outloud/nuxt@nuxtjs-alt/auth@danifoldi/nitropacknuxt-kirbyqlnuxt3-custom-authrxdbnuxt3@everything-registry/sub-chunk-2371@micheldever/storage@mihanik71/image@nuxt/fonts@nuxt/fonts-nightly@nuxt/image@nuxt/image-edge@nuxt/image-nightly@nuxt/scripts@morev/helpers@morev/utils@mrrhq/shadcn-pro-edge@nuxt/content-edge@nuxt/devtools@nuxt/webpack-builder-edge@nuxt/vite-builder-edge@nuxt/vite-builder-nightly@nuxt/ui@nuxt/ui-edge@nuxt/devtools-edge@nuxt/content@nuxt/vite-builder@nuxt/webpack-builder@nuxt-alt/auth@nuxt/bridge@nuxt/bridge-edge@nuxtjs/mdc@nuxtjs/mdc-edge@nuxt/webpack-builder-nightly@nuxtjs/apollo@nuxtjs/sanityanci-react@noyau/corethermal-fntehmusimhujanstrapi-plugin-local-image-sharpstellar-uistoryblok-nuxt-moduleshiki-magic-moveshmatul-imagesedanbosokschema-org-graph-jsshopify-bulk-exportunjs-rekitunplugin-oxlintunplugin-todosvitepress-payload-extractortrpc-nuxttrpc-nuxt-testingyajuuzona-xfile-computed@postgresql-typed/cache@privyid/nuauth@robinwongm/trpc-nuxt@rigo-m/nitropack@pi0/c12@pinceau/core@mikebellika/nitropack@teages/nuxt-urql-clientgerimismalamsenin@wattanx/page-metagassefals-2gassefals@so1ve/nitropack@toyopilgrim/nuxt-alt-authgiget@simonshiki/nitropack@skedulr/nebula-ui-library@toantranmei/mei-nuxt3-ui@tomw2w/my-nuxt-layergpds@remix-kit/vite@storipress/karbon@unrouted/core@zalastax/nolb-oh@tsgandalf/mini-dom@voraciousdev/nuxt3-contentholepackholepack-edge@una-ui/nuxt@una-ui/nuxt-edgeh3h3-nightly@angsanley/nuxt-uiiobroker.jarvis@axxy/nuxt@banjoanton/utilsc12@aabelmann/ui-layer@arque/kafka-stream-adapter@byjohann/vue-i18n@caiquecamargo/vite-plugin-i18n
1.1.3

9 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.2

1 year ago

1.0.0

1 year ago

0.1.2

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.5

2 years ago

0.1.0

2 years ago

0.0.0

2 years ago