Release 0.0.9
This commit is contained in:
@@ -5,23 +5,23 @@ const ATTRIBUTE_PATTERNS = [
|
||||
/url\(\s*["']?([^"')]+)["']?\s*\)/gi
|
||||
];
|
||||
|
||||
export function collectStringCandidates(value, visit) {
|
||||
export function collectStringCandidates(value, visit, path = []) {
|
||||
if (typeof value === "string") {
|
||||
visit(value);
|
||||
visit(value, path);
|
||||
return;
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
for (const entry of value) collectStringCandidates(entry, visit);
|
||||
for (const [index, entry] of value.entries()) collectStringCandidates(entry, visit, [...path, index]);
|
||||
return;
|
||||
}
|
||||
if ((value !== null) && (typeof value === "object")) {
|
||||
for (const entry of Object.values(value)) collectStringCandidates(entry, visit);
|
||||
for (const [key, entry] of Object.entries(value)) collectStringCandidates(entry, visit, [...path, key]);
|
||||
}
|
||||
}
|
||||
|
||||
export function extractReferencesFromValue(value, source) {
|
||||
const references = [];
|
||||
collectStringCandidates(value, candidate => {
|
||||
collectStringCandidates(value, (candidate, candidatePath) => {
|
||||
const direct = resolveReference(candidate, source);
|
||||
if (direct && isMediaPath(direct.path)) {
|
||||
references.push({
|
||||
@@ -30,6 +30,7 @@ export function extractReferencesFromValue(value, source) {
|
||||
sourceLabel: source.sourceLabel,
|
||||
sourceName: source.sourceName,
|
||||
sourceUuid: source.sourceUuid,
|
||||
sourceTrail: source.resolveSourceTrail?.(candidatePath) ?? null,
|
||||
rawValue: candidate,
|
||||
normalized: {
|
||||
...direct,
|
||||
@@ -50,6 +51,7 @@ export function extractReferencesFromValue(value, source) {
|
||||
sourceLabel: source.sourceLabel,
|
||||
sourceName: source.sourceName,
|
||||
sourceUuid: source.sourceUuid,
|
||||
sourceTrail: source.resolveSourceTrail?.(candidatePath) ?? null,
|
||||
rawValue: match[1],
|
||||
normalized: {
|
||||
...nested,
|
||||
|
||||
Reference in New Issue
Block a user