Comparing version 1.1.1 to 1.2.0
42
index.js
@@ -5,3 +5,3 @@ /* eslint-env browser */ | ||
var FIRST_MULTILINE_COMMENT = /\/\*\s*([^]+?)\s*\*\//; | ||
/** @module automat */ | ||
@@ -24,4 +24,3 @@ var ENCODERS = /%\{(\d+)\}/g; // double $$ to encode | ||
* * A string primitive containing the template. | ||
* * A "template" function, which is a function consisting entirely of a single multi-line comment containing the template. The template is extracted from the comment. | ||
* * A (non-template) function to be called with `this` as the calling context. The template is the value returned from this call. | ||
* * A function to be called with `this` as the calling context. The template is the value returned from this call. | ||
* | ||
@@ -31,2 +30,4 @@ * @param {...*} [replacements] - Replacement values for numbered format patterns. | ||
* @return {string} The formatted text. | ||
* | ||
* @memberOf module:automat | ||
*/ | ||
@@ -38,6 +39,3 @@ function automat(template, replacements/*...*/) { | ||
if (typeof template === 'function') { | ||
var format = template.toString().match(FIRST_MULTILINE_COMMENT); | ||
template = format | ||
? format[1] // template function: extract text from comment | ||
: template.call(this); // non-template function: call it with context and use return value | ||
template = template.call(this); // non-template function: call it with context and use return value | ||
} | ||
@@ -78,3 +76,3 @@ | ||
* | ||
* @memberOf automat | ||
* @memberOf module:automat | ||
*/ | ||
@@ -108,5 +106,5 @@ function replace(template, el, replacements/*...*/) { | ||
* | ||
* @returns {Node[]} - array of the generated nodes (this is an actual Array instance; not an Array-like object) | ||
* @returns {Node[]} Array of the generated nodes (this is an actual Array instance; not an Array-like object). | ||
* | ||
* @memberOf automat | ||
* @memberOf module:automat | ||
*/ | ||
@@ -135,9 +133,9 @@ function append(template, el, referenceNode, replacements/*...*/) { | ||
/** | ||
* Use this convenience wrapper to return the first child described in `html`. | ||
* Use this convenience wrapper to return the first child node described in `template`. | ||
* | ||
* @param {string|function} template - If a function, extract template from comment within. | ||
* | ||
* @returns {HTMLElement} A new `<div>...</div>` element, its `innerHTML` set to the formatted text. | ||
* @returns {HTMLElement} The first `Node` in your template. | ||
* | ||
* @memberOf automat | ||
* @memberOf module:automat | ||
*/ | ||
@@ -149,2 +147,15 @@ function firstChild(template, replacements/*...*/) { | ||
/** | ||
* Use this convenience wrapper to return the first child element described in `template`. | ||
* | ||
* @param {string|function} template - If a function, extract template from comment within. | ||
* | ||
* @returns {HTMLElement} The first `HTMLElement` in your template. | ||
* | ||
* @memberOf module:automat | ||
*/ | ||
function firstElement(template, replacements/*...*/) { | ||
return replace.apply(null, arguments).firstElementChild; | ||
} | ||
/** | ||
* @summary Finds string substitution lexemes that require HTML encoding. | ||
@@ -154,3 +165,3 @@ * @desc Modify to suit. | ||
* @type {RegExp} | ||
* @memberOf automat | ||
* @memberOf module:automat | ||
*/ | ||
@@ -164,3 +175,3 @@ automat.encodersRegex = ENCODERS; | ||
* @type {RegExp} | ||
* @memberOf automat | ||
* @memberOf module:automat | ||
*/ | ||
@@ -173,3 +184,4 @@ automat.replacersRegex = REPLACERS; | ||
automat.firstChild = firstChild; | ||
automat.firstElement = firstElement; | ||
module.exports = automat; |
{ | ||
"name": "automat", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "String and markup formatter.", | ||
@@ -5,0 +5,0 @@ "repository": { |
# automat | ||
String and markup formatter. | ||
> Caveat: This 1.0 has breaking changes from 0.x, in particular the order of parameters for `automat.replace` and `automat.append` | ||
## Features | ||
@@ -14,6 +12,11 @@ | ||
* DOM node convenience methods convert your formatted markup to DOM nodes and: | ||
* Return them in a new `<div>...</div>` element | ||
* Return them in an existing `HTMLElement` you provide | ||
* Append/insert them into an existing `HTMLElement` you provide | ||
* Return them in a new `<div>...</div>` element; or | ||
* Return them in an existing `HTMLElement` you provide. | ||
* Append/insert them into an existing `HTMLElement` you provide. | ||
## Update history | ||
v1.2.0: | ||
* Removed ability to extract a template from a function body comment. Comment was elided on minification making this device unusable. | ||
* Fixed problem with .firstChild() and .firstElement() methods. | ||
## Examples | ||
@@ -20,0 +23,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8983
151
44