@xassist/xassist-main

1.0.4 • Public • Published

@xassist/xassist-main

This module provides some helperfunctions like onready, id-generator and templating engine

Installation

If you use NPM, you can install the module via npm install xassist-main. Otherwise, you can download the latest minified file. Be aware any dependencies are not installed by default; you should consider downloading them yourself. If you want, you can install the complete library from github xassist, this includes all dependencies you may need.

The module uses UMD and supports AMD, CommonJS and vanilla environments. Using vanilla: the xaglobal is exported:

<script>
xa.id()
</script>

API

id()

The function id() returns a unique identifier

xa.id() \\returns an unique identifier
xa.id("prefix") \\returns "prefix_"+unique identifier

Parameters for id()

id() takes 1 parameters:

  • prefix [String,defaults to: ""]:This parameter will be used as a prefix for the id.

Result for id()

The value it returns is a String-formatted Number

ready()

The function adds a callback to the DOMContentLoaded-event, it get's executed when this event is triggered. or immediatly, when the DOM was allready ready.

ready(callBack::function [,thisArg])

ready() returns nothing.

Parameters for ready()

ready() takes 2 parameters:

  • callBack [Function]:The listener to be attached to the DOMContentLoaded-event
  • thisArg [any datatype,defaults to: document]:the execution-context of the function

Example for ready()

xa.ready(cb)    \\executes cb(eventDetails) (this inside cb references the document)
xa.ready(cb,thisArg)  \\executes cb(eventDetails) (this inside cb references thisArg)

template()

A basic templating engine, which replaces substrings in a String based on a given object and his keys.

xa.template(txt,obj,strNotFound)

Parameters for template()

template() takes 3 parameters:

  • txt [String]:the base tekst where the templating-engine needs to change certain substrings (it replaces all ${objKey})
  • obj [Object]:the lookup-object to find the defined key's in txt
  • strNotFound [String,defaults to: ""]:when the respective key is not found in the lookupObject, the template get's replaced by this string

Result for template()

the string with all its replaced substrings

Example for template()

xa.template('start${a}${b.c.d}${b.c.d.e}',{a:"OK",b:{c:{d:"VERYDEEP"}}},"notfound") \\returns 'startOKVERYDEEPnotfound'

DevDependencies

  • csv2readme: read csv file with fixed format and parse a readme markdown file
  • jsdom: A JavaScript implementation of many web standards
  • rimraf: A deep deletion module for node (like rm -rf)
  • rollup: Next-generation ES6 module bundler
  • tape: tap-producing test harness for node and browsers

License

This module is licensed under the terms of GPL-3.0.

Package Sidebar

Install

npm i @xassist/xassist-main

Weekly Downloads

0

Version

1.0.4

License

GPL-3.0

Unpacked Size

96.6 kB

Total Files

20

Last publish

Collaborators

  • beirens