-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,392 additions
and
518 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
charset = utf-8 | ||
|
||
[*.js] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[{package.json,*.yml,*.cjson}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
node_modules |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
.vscode | ||
node_modules | ||
*.log* | ||
.DS_Store | ||
coverage | ||
dist | ||
types | ||
.conf* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 - UnJS | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,117 @@ | ||
# ohash | ||
|
||
# murmurhash-es | ||
[![npm version][npm-version-src]][npm-version-href] | ||
[![npm downloads][npm-downloads-src]][npm-downloads-href] | ||
[![Github Actions][github-actions-src]][github-actions-href] | ||
[![Codecov][codecov-src]][codecov-href] | ||
|
||
[![bundle size](https://flat.badgen.net/bundlephobia/minzip/murmurhash-es)](https://bundlephobia.com/package/murmurhash-es) | ||
> Super fast hashing library based on murmurhash3 written in Vanilla JS | ||
> ESM version of murmurhash v2 and v3 | ||
## Usage | ||
|
||
## What is MurmurHash | ||
Install package: | ||
|
||
MurmurHash is a non-cryptographic hash function created by Austin Appleby. | ||
```sh | ||
# npm | ||
npm install ohash | ||
|
||
According to [official website](https://sites.google.com/site/murmurhash/): | ||
# yarn | ||
yarn install ohash | ||
|
||
- Extremely simple - compiles down to ~52 instructions on x86. | ||
# pnpm | ||
pnpm install ohash | ||
``` | ||
|
||
- Excellent distribution - Passes chi-squared tests for practically all keysets & bucket sizes. | ||
Import: | ||
|
||
- Excellent avalanche behavior - Maximum bias is under 0.5%. | ||
```js | ||
// ESM | ||
import { hash, objectHash, murmurHash } from 'ohash' | ||
|
||
- Excellent collision resistance - Passes Bob Jenkin's frog.c torture-test. No collisions possible for 4-byte keys, no small (1- to 7-bit) differentials. | ||
// CommonJS | ||
const { hash, objectHash, murmurHash } = require('ohash') | ||
``` | ||
|
||
- Excellent performance | ||
### `hash(object, options?)` | ||
|
||
## Install | ||
Converts object value into a string hash using `objectHash` and then applies `murmurHash`. | ||
|
||
```sh | ||
# yarn | ||
yarn add murmurhash-es | ||
Usage: | ||
|
||
# npm | ||
npm i murmurhash-es | ||
```js | ||
import { hash } from 'ohash' | ||
|
||
# pnpm | ||
pnpm i murmurhash-es | ||
// "2736179692" | ||
console.log(hash({ foo: 'bar'})) | ||
``` | ||
|
||
### `objectHash(object, options?)` | ||
|
||
Converts a nest object value into a stable and safe string for hashing. | ||
|
||
Usage: | ||
|
||
```js | ||
// ESM | ||
import { murmurHashV2, murmurHashV3 } from 'murmurhash-es' | ||
import { objectHash } from 'ohash' | ||
|
||
// CommonJS | ||
const { murmurHashV2, murmurHashV3 } = require('murmurhash-es') | ||
// "object:1:string:3:foo:string:3:bar," | ||
console.log(objectHash({ foo: 'bar'})) | ||
``` | ||
|
||
## Compatiblity | ||
### `murmurHash(str)` | ||
|
||
Converts input string (of any length) into a 32-bit positive integer using MurmurHash3. | ||
|
||
Implementation is pure Javascript and using `TextEncoder`. Check [compatibility](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder#browser_compatibility). | ||
Usage: | ||
|
||
```js | ||
import { murmurHash } from 'ohash' | ||
|
||
// "2708020327" | ||
console.log(murmurHash('Hello World')) | ||
``` | ||
|
||
## What is MurmurHash | ||
|
||
[MurmurHash](https://en.wikipedia.org/wiki/MurmurHash) is a non-cryptographic hash function created by Austin Appleby. | ||
|
||
According to [murmurhash website](https://sites.google.com/site/murmurhash): | ||
|
||
✅ Extremely simple - compiles down to ~52 instructions on x86. | ||
|
||
✅ Excellent distribution - Passes chi-squared tests for practically all keysets & bucket sizes. | ||
|
||
✅ Excellent avalanche behavior - Maximum bias is under 0.5%. | ||
|
||
✅ Excellent collision resistance - Passes Bob Jenkin's frog.c torture-test. No collisions possible for 4-byte keys, no small (1- to 7-bit) differentials. | ||
|
||
✅ Excellent performance | ||
|
||
## 💻 Development | ||
|
||
- Clone this repository | ||
- Enable [Corepack](https://github.com/nodejs/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 | ||
|
||
[MIT](./LICENSE.md) | ||
Made with 💛 | ||
|
||
Published under [MIT License](./LICENSE). | ||
|
||
Based on [puleos/object-hash](https://github.com/puleos/object-hash) by [Scott Puleo](https://github.com/puleos/), and implementations from [perezd/node-murmurhash](perezd/node-murmurhash) and | ||
[garycourt/murmurhash-js](https://github.com/garycourt/murmurhash-js) by [Gary Court](mailto:gary.court@gmail.com) and [Austin Appleby](mailto:aappleby@gmail.com). | ||
|
||
<!-- Badges --> | ||
[npm-version-src]: https://img.shields.io/npm/v/ohash?style=flat-square | ||
[npm-version-href]: https://npmjs.com/package/ohash | ||
|
||
[npm-downloads-src]: https://img.shields.io/npm/dm/ohash?style=flat-square | ||
[npm-downloads-href]: https://npmjs.com/package/ohash | ||
|
||
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/ohash/ci/main?style=flat-square | ||
[github-actions-href]: https://github.com/unjs/ohash/actions?query=workflow%3Aci | ||
|
||
Based on implementation from [perezd/node-murmurhash](perezd/node-murmurhash) and | ||
[garycourt/murmurhash-js](https://github.com/garycourt/murmurhash-js) | ||
by [Gary Court](mailto:gary.court@gmail.com) and [Austin Appleby](mailto:aappleby@gmail.com). | ||
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/ohash/main?style=flat-square | ||
[codecov-href]: https://codecov.io/gh/unjs/ohash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
# murmurhash-es | ||
|
||
[![bundle size](https://flat.badgen.net/bundlephobia/minzip/murmurhash-es)](https://bundlephobia.com/package/murmurhash-es) | ||
|
||
> ESM version of murmurhash v2 and v3 | ||
## What is MurmurHash | ||
|
||
MurmurHash is a non-cryptographic hash function created by Austin Appleby. | ||
|
||
According to [official website](https://sites.google.com/site/murmurhash/): | ||
|
||
- Extremely simple - compiles down to ~52 instructions on x86. | ||
|
||
- Excellent distribution - Passes chi-squared tests for practically all keysets & bucket sizes. | ||
|
||
- Excellent avalanche behavior - Maximum bias is under 0.5%. | ||
|
||
- Excellent collision resistance - Passes Bob Jenkin's frog.c torture-test. No collisions possible for 4-byte keys, no small (1- to 7-bit) differentials. | ||
|
||
- Excellent performance | ||
|
||
## Install | ||
|
||
```sh | ||
# yarn | ||
yarn add murmurhash-es | ||
|
||
# npm | ||
npm i murmurhash-es | ||
|
||
# pnpm | ||
pnpm i murmurhash-es | ||
``` | ||
|
||
```js | ||
// ESM | ||
import { murmurHashV2, murmurHashV3 } from 'murmurhash-es' | ||
|
||
// CommonJS | ||
const { murmurHashV2, murmurHashV3 } = require('murmurhash-es') | ||
``` | ||
|
||
## Compatiblity | ||
|
||
Implementation is pure Javascript and using `TextEncoder`. Check [compatibility](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder#browser_compatibility). | ||
|
||
## License | ||
|
||
[MIT](./LICENSE.md) | ||
|
||
Based on implementation from [perezd/node-murmurhash](perezd/node-murmurhash) and | ||
[garycourt/murmurhash-js](https://github.com/garycourt/murmurhash-js) | ||
by [Gary Court](mailto:gary.court@gmail.com) and [Austin Appleby](mailto:aappleby@gmail.com). |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,40 @@ | ||
{ | ||
"name": "murmurhash-es", | ||
"version": "0.1.1", | ||
"repository": "unjs/murmurhash-es", | ||
"name": "ohash", | ||
"version": "0.1.0", | ||
"description": "Super fast hashing library based on murmurhash3 written in Vanilla JS", | ||
"repository": "unjs/ohash", | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"type": "module", | ||
"exports": { | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.mjs" | ||
".": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.cjs" | ||
} | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.mjs", | ||
"browser": "./dist/index.min.mjs", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "unbuild && pnpm build:minify", | ||
"build:minify": "pnpm esbuild dist/index.mjs --minify --outfile=dist/index.min.mjs", | ||
"lint": "eslint --ext .ts,.mjs,.js .", | ||
"release": "pnpm build && standard-version && git push --follow-tags && pnpm publish", | ||
"test": "jiti ./test/index.ts" | ||
"build": "unbuild", | ||
"dev": "vitest dev", | ||
"lint": "eslint --ext .ts,.js,.mjs,.cjs .", | ||
"prepack": "unbuild", | ||
"release": "pnpm test && standard-version && git push --follow-tags && pnpm publish", | ||
"test": "pnpm lint && vitest run" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@nuxtjs/eslint-config-typescript": "^9.0.0", | ||
"esbuild": "^0.13.8", | ||
"eslint": "^8.11.0", | ||
"jiti": "^1.12.9", | ||
"standard-version": "^9.3.2", | ||
"unbuild": "^0.5.7" | ||
"@nuxtjs/eslint-config-typescript": "latest", | ||
"c8": "latest", | ||
"eslint": "latest", | ||
"standard-version": "latest", | ||
"typescript": "latest", | ||
"unbuild": "latest", | ||
"vitest": "latest" | ||
}, | ||
"packageManager": "pnpm@6.32.3" | ||
"packageManager": "pnpm@6.32.2" | ||
} |
Oops, something went wrong.