Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function prefixGenerator(a) {
const prefixes = new Set();
for (const x of a) {
const splitField = splitAccessPath(x);
// Wrap every element other than the first in `[]`
const wrappedWithAccessors = splitField.map((y, i) => (i === 0 ? y : `[${y}]`));
const computedPrefixes = wrappedWithAccessors.map((_, i) => wrappedWithAccessors.slice(0, i + 1).join(''));
computedPrefixes.forEach(y => prefixes.add(y));
}
return prefixes;
}
export function fieldIntersection(a, b) {
export function prefixGenerator(a: ReadonlySet): ReadonlySet {
const prefixes = new Set();
for (const x of a) {
const splitField = splitAccessPath(x);
// Wrap every element other than the first in `[]`
const wrappedWithAccessors = splitField.map((y, i) => (i === 0 ? y : `[${y}]`));
const computedPrefixes = wrappedWithAccessors.map((_, i) => wrappedWithAccessors.slice(0, i + 1).join(''));
computedPrefixes.forEach(y => prefixes.add(y));
}
return prefixes;
}
field = ref.parent;
object += '.datum';
} else {
field = ref.group;
}
} else if (ref.datum) {
object = 'datum';
field = ref.datum;
} else {
error('Invalid field reference: ' + stringValue(ref));
}
if (!ref.signal) {
if (isString(field)) {
fields[field] = 1; // TODO review field tracking?
field = splitAccessPath(field).map(stringValue).join('][');
} else {
field = resolve(field, scope, params, fields);
}
}
return object + '[' + field + ']';
}
export function accessPathWithDatum(path, datum = 'datum') {
const pieces = splitAccessPath(path);
const prefixes = [];
for (let i = 1; i <= pieces.length; i++) {
const prefix = `[${pieces
.slice(0, i)
.map(stringValue)
.join('][')}]`;
prefixes.push(`${datum}${prefix}`);
}
return prefixes.join(' && ');
}
/**
export function replacePathInField(path) {
return `${splitAccessPath(path)
.map(p => p.replace('.', '\\.'))
.join('\\.')}`;
}
/**
export function accessPathDepth(path) {
if (!path) {
return 0;
}
return splitAccessPath(path).length;
}
/**
export function accessPathWithDatum(path: string, datum = 'datum') {
const pieces = splitAccessPath(path);
const prefixes = [];
for (let i = 1; i <= pieces.length; i++) {
const prefix = `[${pieces
.slice(0, i)
.map(stringValue)
.join('][')}]`;
prefixes.push(`${datum}${prefix}`);
}
return prefixes.join(' && ');
}
export function removePathFromField(path) {
return `${splitAccessPath(path).join('.')}`;
}
/**
export function flatAccessWithDatum(path: string, datum: 'datum' | 'parent' | 'datum.datum' = 'datum') {
return `${datum}[${stringValue(splitAccessPath(path).join('.'))}]`;
}