Skip to content
composite-key / 1.0.0

composite-key 1.0.0

Install from the command line:
Learn more about npm packages
$ npm install @virtualstate/composite-key@1.0.0
Install via package.json:
"@virtualstate/composite-key": "1.0.0"

About this version

@virtualstate/composite-key

compositeKey & compositeSymbol implementation

Support

Node.js supported Deno supported Bun supported

Test Coverage

100%25 lines covered 100%25 statements covered 100%25 functions covered 100%25 branches covered

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.

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.

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

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

import { createCompositeSymbol } from "@virtualstate/composite-key";

const compositeSymbol = createCompositeSymbol();

const array = [1, 2, 3];
compositeSymbol(array, 1); // A symbol

Details


Assets

  • composite-key-1.0.0.tgz

Download activity

  • Total downloads 0
  • Last 30 days 0
  • Last week 0
  • Today 0

Recent versions

View all