@reintent/lib/keys
Keys and names, in user space on core's `keyOf` (0047 §2): a choice's key read back into its identity, and a short name for a value.
idOfKey(key) `keyOf`'s inverse: total, since core refuses a name with '#' in it
fingerprint(v) a short name for a value (a program's text), not a proof that two are equalNew, replacing #356's idOfKey and #357's fingerprint in core.
Functions
fingerprint()
function fingerprint(v): string;Defined in: packages/lib/src/keys.ts
A short name for a value (FNV-1a over its canonical JSON, base 36): the same data, whatever the order of its keys, gives the same name. A name to tell versions apart in a list, never a proof that two values are equal: compare the values (or their canonical JSON) for that.
Parameters
| Parameter | Type |
|---|---|
v | unknown |
Returns
string
Example
import { fingerprint } from '@reintent/lib/keys';
console.log(fingerprint({ a: 1, b: [2] }) === fingerprint({ b: [2], a: 1 })); // → true
console.log(fingerprint('a dream') === fingerprint('another dream')); // → falseidOfKey()
function idOfKey(key): Id;Defined in: packages/lib/src/keys.ts
The identity a key was made from (keyOf's inverse): split at its last #, since core refuses
a name that is empty or has # in it, and an empty entity. A key that is not one (no #, an
empty entity or name) throws: it never reads back as an empty name.
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
Example
import { keyOf } from '@reintent/core';
import { idOfKey } from '@reintent/lib/keys';
console.log(idOfKey('gallery/g0#fit')); // → { of: 'gallery/g0', name: 'fit' }
console.log(keyOf(idOfKey('deck#3#title')) === 'deck#3#title'); // → true
try {
idOfKey('man');
} catch (e) {
console.log((e as Error).message); // → "'man' is not a choice's key: it has no '#'"
}Last updated on
Edit on GitHub