Linkifier. Linkifier

The class providing the link rendering functionality. Instances of this class capture the settings for generating links, and, generate links using these settings.

Constructor

new Linkifier()

Members

defaultTemplate :LinkTemplate

The default link template.

Type:
  • LinkTemplate

defaultTemplateName

defaultTemplateName

speciallyCapitalisedWords

speciallyCapitalisedWords

templateNames :Array.<string>

A list of the names of the registered link templates.

Type:
  • Array.<string>

util

See
  • Linfifier.utilities

utilities :Object.<string, function()>

Type:
  • Object.<string, function()>

Methods

(async) fetchPageData(url) → {PageData}

Fetch the page data for a given URL.

Parameters:
NameTypeDescription
urlURL
Throws:

A validation error is thrown unless a valid URL is passed.

Type
ValidationError
Returns:
Type: 
PageData

Generate a link given a URL. By default the registered template for the URL's domain will be used, or, if none is registered, the overall default will be used (html).

Parameters:
NameTypeAttributesDefaultDescription
urlURL
templateNametemplateName<optional>
'html'
Throws:

A validation error is thrown unless a valid URL is passed.

Type
ValidationError
Returns:
Type: 
string

getTemplate(templateName) → {LinkTemplate}

Get a registered link template by name.

Parameters:
NameTypeDescription
templateNamestring
Throws:

A validation error is thrown unless a valid name is passed and corresponds to a registered template.

Type
ValidationError
Returns:
Type: 
LinkTemplate

getTemplateNameForDomain(domain) → {dataTransformer}

Get the data transformer function for a given domain.

Note that domains are searched from the subdomain up. For example, if passed the domain www.bartificer.net the function will first look for a transformer for the domain www.bartificer.net, if there's no transformer registered for that domain it will look for a transformer for the domain bartificer.net, if there's no transformer for that domain either it will return the default transformer.

Parameters:
NameTypeDescription
domaindomainName

The domain to get the data transformer for.

Throws:

A validation error is thrown unless a valid domain name is passed.

Type
ValidationError
Returns:
Type: 
dataTransformer

getTransformerForDomain(domain) → {dataTransformer}

Get the data transformer function for a given domain.

Note that domains are searched from the subdomain up. For example, if passed the domain www.bartificer.net the function will first look for a transformer for the domain www.bartificer.net, if there's no transformer registered for that domain it will look for a transformer for the domain bartificer.net, if there's no transformer for that domain either it will return the default transformer.

Parameters:
NameTypeDescription
domaindomainName

The domain to get the data transformer for.

Throws:

A validation error is thrown unless a valid domain name is passed.

Type
ValidationError
Returns:
Type: 
dataTransformer

registerDefaultTemplateMapping(domain, templateName)

Register a default template for use with a given domain. This template will override the overall default for this domain and all its subdomains.

Parameters:
NameTypeDescription
domaindomainName

The domain for which this template should be used by default.

templateNametemplateName

The name of the template to use.

Throws:

A validation error is thrown if either parameter is missing or invalid.

Type
ValidationError

registerTemplate(name, template)

Register a link template.

Parameters:
NameTypeDescription
nametemplateName
templatemodule:@bartificer/linkify.LinkTemplate
Throws:

A validation error is thrown unless both a valid name and template object are passed.

Type
ValidationError

registerTransformer(domain, transformerFn)

Register a data transformer function for a given domain.

Parameters:
NameTypeDescription
domaindomainName

The domain for which this transformer should be used.

transformerFndataTransformer

The data transformer callback.

Throws:

A validation error is thrown if either parameter is missing or invalid.

Type
ValidationError