@doars/doars-alias

Doars plugin for creating aliases or renaming any context or directive.

Usage no npm install needed!

<script type="module">
  import doarsDoarsAlias from 'https://cdn.skypack.dev/@doars/doars-alias';
</script>

README

npm @latest version minzipped size


@doars/doars-alias

Plugin for creating aliases or renaming any context or directive.

Install

From NPM

Install the package from NPM, then import and enable the library in your build.

npm i @doars/doars @doars/doars-alias
// Import library.
import Doars from "@doars/doars";
import DoarsAlias from "@doars/doars-alias";

// Setup a library instance.
const doars = new Doars();

// Setup the plugin.
const doarsAlias = new DoarsAlias(doars /*, options */);

// Enable library.
doars.enable();

UMD build from jsDelivr

Add the UMD build to the page from for example the jsDelivr CDN and enable the library.

<!-- Import library. -->
<script src="https://cdn.jsdelivr.net/npm/@doars/doars@1/dst/doars.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@doars/doars-alias@1/dst/doars-alias.umd.js"></script>
<script>
  document.addEventListener('DOMContentLoaded', () => {
    // Setup a library instance.
    const doars = new window.Doars()

    // Setup the plugin.
    const doarsAlias = new window.DoarsAlias(doars /*, options */)

    // Enable library.
    doars.enable()
  })
</script>

ESM and IIFE builds are also available via the jsDelivr CDN.

Examples

// Setup a library instance.
const doars = new Doars();

// Setup the plugin.
const doarsAlias = new DoarsAlias(doars, {
  aliasContexts: {
    component: "root",
  },
  renameContexts: {
    references: "refs",
  },
  aliasDirective: {
    attribute: "attr",
    initialized: "init",
  },
  renameDirective: {
    reference: "ref",
  },
});

// Enable library.
doars.enable();

API

DoarsAlias

  • constructor Create plugin instance.
    • @param {Doars} library A doars library instance.
    • @param {Object} options = null See options.
    • @returns {DoarsAlias}

DoarsAlias options

  • {Object} aliasContexts The contexts to alias.
    • {Array<String>|String} [name] The alias or aliases of the context.
  • {Object} aliasDirectives The directives to alias.
    • {Array<String>|String} [name] The alias or aliases of the directive.
  • {Object} renameContexts The contexts to rename.
    • {String} [name] The new name of the context.
  • {Object} renameDirectives The directives to rename.
    • {String} [name] The new name of the directive.

Where [name] is the current name of the context or directive that should be aliased or renamed.