forked from trent_larson/crowd-funder-for-time-pwa
add sharing & copying instructions when asking contacts for help, and list all the visibleTo DIDs with an English description of their path
This commit is contained in:
@@ -99,13 +99,17 @@ export const canFulfillOffer = (veriClaim: GenericServerRecord) => {
|
||||
export function findAllVisibleToDids(
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
input: any,
|
||||
humanReadable = false,
|
||||
): Record<string, Array<string>> {
|
||||
if (Array.isArray(input)) {
|
||||
const result: Record<string, Array<string>> = {};
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
const inside = findAllVisibleToDids(input[i]);
|
||||
const inside = findAllVisibleToDids(input[i], humanReadable);
|
||||
for (const key in inside) {
|
||||
result["[" + i + "]" + key] = inside[key];
|
||||
const pathKey = humanReadable
|
||||
? "#" + (i + 1) + " " + key
|
||||
: "[" + i + "]" + key;
|
||||
result[pathKey] = inside[key];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -115,11 +119,15 @@ export function findAllVisibleToDids(
|
||||
for (const key in input) {
|
||||
if (key.endsWith("VisibleToDids")) {
|
||||
const newKey = key.slice(0, -"VisibleToDids".length);
|
||||
result["." + newKey] = input[key];
|
||||
const pathKey = humanReadable ? newKey : "." + newKey;
|
||||
result[pathKey] = input[key];
|
||||
} else {
|
||||
const inside = findAllVisibleToDids(input[key]);
|
||||
const inside = findAllVisibleToDids(input[key], humanReadable);
|
||||
for (const insideKey in inside) {
|
||||
result["." + key + insideKey] = inside[insideKey];
|
||||
const pathKey = humanReadable
|
||||
? key + "'s " + insideKey
|
||||
: "." + key + insideKey;
|
||||
result[pathKey] = inside[insideKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,7 +143,10 @@ export function findAllVisibleToDids(
|
||||
|
||||
pkgx +deno.land sh
|
||||
|
||||
deno
|
||||
|
||||
import * as R from 'ramda';
|
||||
//import { findAllVisibleToDids } from './src/libs/util'; // doesn't work because other dependencies fail so gotta copy-and-paste function
|
||||
|
||||
console.log(R.equals(findAllVisibleToDids(null), {}));
|
||||
console.log(R.equals(findAllVisibleToDids(9), {}));
|
||||
|
||||
Reference in New Issue
Block a user