Skip to content

Commit

Permalink
Merge pull request #163 from evert/has-link
Browse files Browse the repository at this point in the history
Adding a 'hasLink' method, for easy checking if a certain link exists.
  • Loading branch information
evert authored Nov 12, 2019
2 parents 584a18d + 5faba5a commit 6dd292f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/representor/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ export default abstract class Representation<T = string> {

}

/**
* Checks if the specified link exists on this representation.
*/
hasLink(rel: string): boolean {

return this.links.has(rel) && this.links.get(rel)!.length > 0;

}

getEmbedded(): { [uri: string]: T } {

return {};
Expand Down
10 changes: 10 additions & 0 deletions src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,16 @@ export default class Resource<TResource = any, TPatch = Partial<TResource>> {

}

/**
* Checks if the current resource has the specified link relationship.
*/
async hasLink(rel: string): Promise<boolean> {

const r = await this.representation();
return r.hasLink(rel);

}

/**
* Follows a relationship, based on its reltype. For example, this might be
* 'alternate', 'item', 'edit' or a custom url-based one.
Expand Down

0 comments on commit 6dd292f

Please sign in to comment.