Skip to content

Commit

Permalink
Merge pull request #10 from docknetwork/feat/title-sbj
Browse files Browse the repository at this point in the history
get title from subject too
  • Loading branch information
maycon-mello authored Jun 15, 2022
2 parents 8e4bd7e + 856b788 commit fbe0b52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@docknetwork/prettyvc",
"description": "Render pretty verifiable credentials",
"version": "1.2.0",
"version": "1.2.1",
"main": "lib/index.js",
"license": "MIT",
"repository": {
Expand Down
11 changes: 8 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ export function humanizeCamelCase(string) {
return capitalizeFirstLetter(result);
}

export function getTitle({ type, name }, cutTitle = true) {
let title = name;
export function getTitle({ type, name, credentialSubject }, cutTitle = true) {
const subjects = Array.isArray(credentialSubject) ? credentialSubject : [credentialSubject];
let title = name || (subjects[0] && subjects[0].title);

// Get title from type of credential
if (!title && type && type.length) {
Expand Down Expand Up @@ -137,6 +138,10 @@ function extractHumanNameFields(s) {
}

function extractNameFields(s) {
if (!s) {
return '';
}

// Try to extract based on most often used human readable fields for names
const humanNames = extractHumanNameFields(s);
if (humanNames) {
Expand All @@ -154,7 +159,7 @@ function extractNameFields(s) {

function getSubjectName({ credentialSubject }, didMap) {
const subjects = Array.isArray(credentialSubject) ? credentialSubject : [credentialSubject];
return subjects.map((s) => mapDIDIfKnown(getObjectName(s, extractNameFields)), didMap).join(' & ');
return subjects.map((s) => s && mapDIDIfKnown(getObjectName(s, extractNameFields)), didMap).join(' & ');
}

function getSubjectDocuments({ credentialSubject }) {
Expand Down

0 comments on commit fbe0b52

Please sign in to comment.