https://github.com/virtualstate/composite-key
https://github.com/virtualstate/composite-key
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/virtualstate/composite-key
- Owner: virtualstate
- License: mit
- Created: 2022-08-14T09:07:26.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-14T09:29:10.000Z (almost 4 years ago)
- Last Synced: 2025-07-04T11:56:22.036Z (12 months ago)
- Language: JavaScript
- Size: 253 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE-OF-CONDUCT.md
Awesome Lists containing this project
README
# `@virtualstate/composite-key`
[compositeKey & compositeSymbol](https://github.com/tc39/proposal-richer-keys/tree/master/compositeKey) implementation
[//]: # (badges)
### Support
  
### Test Coverage
   
[//]: # (badges)
## Usage
Allows for multiple values to be "joined" together and used as a single key.
## `compositeKey`
Returns a frozen object that can be used as a reference in place of the original arguments
The object can be used as a key in a WeakMap, or Map. The object can also be used in a WeakSet.
```typescript
import { compositeKey } from "@virtualstate/composite-key";
const map = new WeakMap();
const array = [1, 2, 3];
map.set(compositeKey(array, 1), "Value");
map.get(compositeKey(array, 1)); // "Value"
map.get(compositeKey(array, 2)); // undefined
```
## `compositeSymbol`
Returns a symbol that can be used as a reference in place of the original arguments.
The symbol can be used in most places, including keys of objects, and Maps. The symbol can also be used in a Set.
```typescript
import { compositeSymbol } from "@virtualstate/composite-key";
const map = new Map();
const array = [1, 2, 3];
map.set(compositeSymbol(array, 1), "Value");
map.get(compositeSymbol(array, 1)); // "Value"
map.get(compositeSymbol(array, 2)); // undefined
```
## `createCompositeKey`
Creates an isolated version of `compositeKey`
```typescript
import { createCompositeKey } from "@virtualstate/composite-key";
const compositeKey = createCompositeKey();
const array = [1, 2, 3];
compositeKey(array, 1); // An object
```
## `createCompositeSymbol`
Creates an isolated version of `compositeSymbol`
```typescript
import { createCompositeSymbol } from "@virtualstate/composite-key";
const compositeSymbol = createCompositeSymbol();
const array = [1, 2, 3];
compositeSymbol(array, 1); // A symbol
```