Comparing version 1.0.2 to 1.0.3
@@ -77,6 +77,7 @@ 'use strict'; | ||
* Similar to template, but will render an iterable (such as array) of items together instead | ||
* of rendering each item individually. It improves efficiency in these scenarios. | ||
* of rendering each item individually. It improves efficiency in these scenarios because only 1 rendering | ||
* function is called. | ||
* | ||
* @example | ||
* const t = arrayTemplate('I will render this ${it}/${other} immediately!!!', ['other'], 'it', ' & ')([1, 2, 3, 4, 5], '(shared)'); | ||
* const t = arrayTemplate('I will render this ${it}/${other} immediately!!!', ['other'], 'it')([1, 2, 3, 4, 5], '(shared)').join(' & '); | ||
* // t === 'I will render this 1/(shared) immediately!!! & I will render this 2/(shared) immediately!!! & I will render this 3/(shared) immediately!!! & I will render this 4/(shared) immediately!!! & I will render this 5/(shared) immediately!!!' | ||
@@ -88,7 +89,6 @@ * | ||
* to 'item' | ||
* @param {string} itemSep The text that goes between the rendered items. | ||
* Defaults to the empty string. | ||
* @returns {ArrayTemplate} | ||
*/ | ||
function arrayTemplate(templateStr, argNames, itemName, itemSep) { | ||
function arrayTemplate(templateStr, argNames, itemName) { | ||
if (!argNames) | ||
@@ -98,4 +98,2 @@ argNames = []; | ||
itemName = "item"; | ||
if (!itemSep) | ||
itemSep = ""; | ||
return Function("arr", ...argNames, ` | ||
@@ -106,3 +104,3 @@ const result = []; | ||
} | ||
return result.join('${itemSep}'); | ||
return result; | ||
`); | ||
@@ -118,4 +116,4 @@ } | ||
* console.log(t instanceof Promise); // true | ||
* t = await t | ||
* // t === 'I will async render this 1I will async render this 2I will async render this 3I will async render this 4I will async render this 5' | ||
* t = (await t).join(' ') | ||
* // t === 'I will async render this 1 I will async render this 2 I will async render this 3 I will async render this 4 I will async render this 5' | ||
* | ||
@@ -126,4 +124,2 @@ * @param {string} templateStr The template string | ||
* to 'item' | ||
* @param {string} itemSep The text that goes between the rendered items. | ||
* Defaults to the empty string. | ||
* @param {string} tagName Supply a tagName argument to change the name of the tag function inside the template string if | ||
@@ -133,3 +129,3 @@ * the default name (T) is present in argNames. | ||
*/ | ||
function asyncArrayTemplate(templateStr, argNames, itemName, itemSep, tagName) { | ||
function asyncArrayTemplate(templateStr, argNames, itemName, tagName) { | ||
if (!argNames) | ||
@@ -139,4 +135,2 @@ argNames = []; | ||
itemName = "item"; | ||
if (!itemSep) | ||
itemSep = ""; | ||
if (!tagName) | ||
@@ -157,3 +151,3 @@ tagName = "T"; | ||
} | ||
return Promise.all(result).then(resolved => resolved.join('${itemSep}')); | ||
return Promise.all(result).then(resolved => resolved); | ||
`); | ||
@@ -160,0 +154,0 @@ return (arr, ...args) => f(tag, arr, ...args); |
@@ -256,3 +256,3 @@ /** | ||
interface ArrayTemplate { | ||
(arr: Iterable<any>, ...args: any[]): string; | ||
(arr: Iterable<any>, ...args: any[]): string[]; | ||
} | ||
@@ -263,10 +263,11 @@ /** | ||
interface AsyncArrayTemplate { | ||
(arr: Iterable<any>, ...args: any[]): Promise<string>; | ||
(arr: Iterable<any>, ...args: any[]): Promise<string[]>; | ||
} | ||
/** | ||
* Similar to template, but will render an iterable (such as array) of items together instead | ||
* of rendering each item individually. It improves efficiency in these scenarios. | ||
* of rendering each item individually. It improves efficiency in these scenarios because only 1 rendering | ||
* function is called. | ||
* | ||
* @example | ||
* const t = arrayTemplate('I will render this ${it}/${other} immediately!!!', ['other'], 'it', ' & ')([1, 2, 3, 4, 5], '(shared)'); | ||
* const t = arrayTemplate('I will render this ${it}/${other} immediately!!!', ['other'], 'it')([1, 2, 3, 4, 5], '(shared)').join(' & '); | ||
* // t === 'I will render this 1/(shared) immediately!!! & I will render this 2/(shared) immediately!!! & I will render this 3/(shared) immediately!!! & I will render this 4/(shared) immediately!!! & I will render this 5/(shared) immediately!!!' | ||
@@ -278,7 +279,6 @@ * | ||
* to 'item' | ||
* @param {string} itemSep The text that goes between the rendered items. | ||
* Defaults to the empty string. | ||
* @returns {ArrayTemplate} | ||
*/ | ||
declare function arrayTemplate(templateStr: string, argNames: Array<string>, itemName: string, itemSep: string): ArrayTemplate; | ||
declare function arrayTemplate(templateStr: string, argNames: Array<string>, itemName: string): ArrayTemplate; | ||
/** | ||
@@ -292,4 +292,4 @@ * Async equivalent of arrayTemplate. The async template tag ('T' by default) | ||
* console.log(t instanceof Promise); // true | ||
* t = await t | ||
* // t === 'I will async render this 1I will async render this 2I will async render this 3I will async render this 4I will async render this 5' | ||
* t = (await t).join(' ') | ||
* // t === 'I will async render this 1 I will async render this 2 I will async render this 3 I will async render this 4 I will async render this 5' | ||
* | ||
@@ -300,4 +300,2 @@ * @param {string} templateStr The template string | ||
* to 'item' | ||
* @param {string} itemSep The text that goes between the rendered items. | ||
* Defaults to the empty string. | ||
* @param {string} tagName Supply a tagName argument to change the name of the tag function inside the template string if | ||
@@ -307,3 +305,3 @@ * the default name (T) is present in argNames. | ||
*/ | ||
declare function asyncArrayTemplate(templateStr: string, argNames: Array<string>, itemName: string, itemSep: string, tagName: string): AsyncArrayTemplate; | ||
declare function asyncArrayTemplate(templateStr: string, argNames: Array<string>, itemName: string, tagName: string): AsyncArrayTemplate; | ||
/** | ||
@@ -310,0 +308,0 @@ * Fetches text (typically markup) from the url. This is only a shorthand |
@@ -75,6 +75,7 @@ /** | ||
* Similar to template, but will render an iterable (such as array) of items together instead | ||
* of rendering each item individually. It improves efficiency in these scenarios. | ||
* of rendering each item individually. It improves efficiency in these scenarios because only 1 rendering | ||
* function is called. | ||
* | ||
* @example | ||
* const t = arrayTemplate('I will render this ${it}/${other} immediately!!!', ['other'], 'it', ' & ')([1, 2, 3, 4, 5], '(shared)'); | ||
* const t = arrayTemplate('I will render this ${it}/${other} immediately!!!', ['other'], 'it')([1, 2, 3, 4, 5], '(shared)').join(' & '); | ||
* // t === 'I will render this 1/(shared) immediately!!! & I will render this 2/(shared) immediately!!! & I will render this 3/(shared) immediately!!! & I will render this 4/(shared) immediately!!! & I will render this 5/(shared) immediately!!!' | ||
@@ -86,7 +87,6 @@ * | ||
* to 'item' | ||
* @param {string} itemSep The text that goes between the rendered items. | ||
* Defaults to the empty string. | ||
* @returns {ArrayTemplate} | ||
*/ | ||
function arrayTemplate(templateStr, argNames, itemName, itemSep) { | ||
function arrayTemplate(templateStr, argNames, itemName) { | ||
if (!argNames) | ||
@@ -96,4 +96,2 @@ argNames = []; | ||
itemName = "item"; | ||
if (!itemSep) | ||
itemSep = ""; | ||
return Function("arr", ...argNames, ` | ||
@@ -104,3 +102,3 @@ const result = []; | ||
} | ||
return result.join('${itemSep}'); | ||
return result; | ||
`); | ||
@@ -116,4 +114,4 @@ } | ||
* console.log(t instanceof Promise); // true | ||
* t = await t | ||
* // t === 'I will async render this 1I will async render this 2I will async render this 3I will async render this 4I will async render this 5' | ||
* t = (await t).join(' ') | ||
* // t === 'I will async render this 1 I will async render this 2 I will async render this 3 I will async render this 4 I will async render this 5' | ||
* | ||
@@ -124,4 +122,2 @@ * @param {string} templateStr The template string | ||
* to 'item' | ||
* @param {string} itemSep The text that goes between the rendered items. | ||
* Defaults to the empty string. | ||
* @param {string} tagName Supply a tagName argument to change the name of the tag function inside the template string if | ||
@@ -131,3 +127,3 @@ * the default name (T) is present in argNames. | ||
*/ | ||
function asyncArrayTemplate(templateStr, argNames, itemName, itemSep, tagName) { | ||
function asyncArrayTemplate(templateStr, argNames, itemName, tagName) { | ||
if (!argNames) | ||
@@ -137,4 +133,2 @@ argNames = []; | ||
itemName = "item"; | ||
if (!itemSep) | ||
itemSep = ""; | ||
if (!tagName) | ||
@@ -155,3 +149,3 @@ tagName = "T"; | ||
} | ||
return Promise.all(result).then(resolved => resolved.join('${itemSep}')); | ||
return Promise.all(result).then(resolved => resolved); | ||
`); | ||
@@ -158,0 +152,0 @@ return (arr, ...args) => f(tag, arr, ...args); |
{ | ||
"name": "deleight", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A group of 8 libraries for writing accessible and joyfully interactive web applications with traditional HTML, CSS and JavaScript.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
{ | ||
"name": "deleight", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A group of 8 libraries for writing accessible and joyfully interactive web applications with traditional HTML, CSS and JavaScript.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
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
167018
4311