Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tomeraberbach/keyalesce
🔑 Get the same key for the same sequence of values!
https://github.com/tomeraberbach/keyalesce
finalizationregistry hashing idempotent key-value map set weakmap weakref
Last synced: 9 days ago
JSON representation
🔑 Get the same key for the same sequence of values!
- Host: GitHub
- URL: https://github.com/tomeraberbach/keyalesce
- Owner: TomerAberbach
- License: apache-2.0
- Created: 2023-07-02T19:26:36.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-23T02:59:35.000Z (5 months ago)
- Last Synced: 2024-10-12T01:23:30.318Z (25 days ago)
- Topics: finalizationregistry, hashing, idempotent, key-value, map, set, weakmap, weakref
- Language: TypeScript
- Homepage: https://npm.im/keyalesce
- Size: 403 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Contributing: contributing.md
- License: license
Awesome Lists containing this project
README
keyalesce
Get the same key for the same sequence of values!## Features
- **Simple:** a single function that takes an array and returns a key
- **Tiny:** 580 bytes gzipped!
- **Performant:** maintains a regularly pruned internal
[trie](https://en.wikipedia.org/wiki/Trie) of the value sequences## When would I use this and how does it work?
[Read my post!](https://tomeraberba.ch/the-making-of-keyalesce)
## Install
```sh
$ npm i keyalesce
```## Usage
```js
import keyalesce from 'keyalesce'const hangouts = new Set()
const createHangoutKey = (person1, person2) =>
keyalesce([person1, person2].sort())
const hangOut = (person1, person2) =>
hangouts.add(createHangoutKey(person1, person2))
const didTheyHangOut = (person1, person2) =>
hangouts.has(createHangoutKey(person1, person2))hangOut(`Tomer`, `Samuel`)
hangOut(`Tomer`, `Amanda`)console.log(didTheyHangOut(`Tomer`, `Samuel`))
console.log(didTheyHangOut(`Samuel`, `Tomer`))
//=> true
//=> trueconsole.log(didTheyHangOut(`Tomer`, `Amanda`))
console.log(didTheyHangOut(`Amanda`, `Tomer`))
//=> true
//=> trueconsole.log(didTheyHangOut(`Samuel`, `Amanda`))
console.log(didTheyHangOut(`Amanda`, `Samuel`))
//=> false
//=> false
```## Contributing
Stars are always welcome!
For bugs and feature requests,
[please create an issue](https://github.com/TomerAberbach/keyalesce/issues/new).For pull requests, please read the
[contributing guidelines](https://github.com/TomerAberbach/keyalesce/blob/main/contributing.md).## License
[Apache License 2.0](https://github.com/TomerAberbach/keyalesce/blob/main/license)
This is not an official Google product.