You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
620 B
JavaScript
21 lines
620 B
JavaScript
"use strict";
|
|
|
|
// This generates stable (for the lifetime of the process) identifiers for individual values, by identity - it's useful for correlating together eg. debug logs where pretty-printing the full values is impractical
|
|
// FIXME: Move this out into its own dedicated package
|
|
|
|
const nanoid = require("nanoid/non-secure").customAlphabet("1234567890abcdefghklmpqrsvxyz", 6);
|
|
|
|
let knownValues = new WeakMap();
|
|
|
|
module.exports = function valueID(value) {
|
|
if (value == null) {
|
|
return value;
|
|
} else {
|
|
if (!knownValues.has(value)) {
|
|
knownValues.set(value, nanoid());
|
|
}
|
|
|
|
return knownValues.get(value);
|
|
}
|
|
};
|