Skip to content

Commit 39b247e

Browse files
committed
Prepare 2.0.0-alpha.5. Improve JSDoc and types.
1 parent f5ee071 commit 39b247e

File tree

22 files changed

+190
-44
lines changed

22 files changed

+190
-44
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "proper-tags",
33
"description": "A few common utility template tags for ES2015",
4-
"version": "2.0.0-alpha.3",
4+
"version": "2.0.0-alpha.5",
55
"author": "Hexagon <https://github.com/hexagon>",
66
"bugs": {
77
"url": "http://github.com/declandewet/common-tags/issues"

src/commaLists/commaLists.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { inlineArrayTransformer } from '../inlineArrayTransformer/index.js';
44

55
/**
66
* Allows you to inline an array substitution as a comma-separated list.
7-
* @type {TemplateTag}
7+
* @implements {TemplateTag}
88
*/
99
const commaLists = createTag(
1010
inlineArrayTransformer({ separator: ',' }),

src/commaListsAnd/commaListsAnd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { inlineArrayTransformer } from '../inlineArrayTransformer/index.js';
44

55
/**
66
* Allows you to inline an array substitution as a comma-separated list, the last of which is preceded by the word "and".
7-
* @type {TemplateTag}
7+
* @implements {TemplateTag}
88
*/
99
const commaListsAnd = createTag(
1010
inlineArrayTransformer({ separator: ',', conjunction: 'and' }),

src/commaListsOr/commaListsOr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { inlineArrayTransformer } from '../inlineArrayTransformer/index.js';
44

55
/**
66
* Allows you to inline an array substitution as a comma-separated list, the last of which is preceded by the word "or".
7-
* @type {TemplateTag}
7+
* @implements {TemplateTag}
88
*/
99
const commaListsOr = createTag(
1010
inlineArrayTransformer({ separator: ',', conjunction: 'or' }),

src/html/html.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { splitStringTransformer } from '../splitStringTransformer/index.js';
55
import { removeNonPrintingValuesTransformer } from '../removeNonPrintingValuesTransformer/index.js';
66

77
/**
8-
* An HTML tag function that processes a template literal and returns an HTML string.
9-
* @type {TemplateTag}
10-
*/
8+
* A function that returns an HTML string by processing a template literal or a JSTag function.
9+
* @function
10+
* @implements {TemplateTag}
11+
*/
1112
const html = createTag(
1213
splitStringTransformer('\n'),
1314
removeNonPrintingValuesTransformer(),

src/id/id.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createTag } from '../createTag/index.js';
22

33
/**
44
* A no-op tag that might come in useful in some scenarios, e.g. mocking.
5-
* @type {TemplateTag}
5+
* @implements {TemplateTag}
66
*/
77
const id = createTag();
88

src/index.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
2-
/**
3-
* JSTag
4-
* A function that takes a template literal and returns a string.
5-
* @typedef {function} JSTag
6-
* @param {TemplateStringsArray} literals - The template literal containing placeholders.
7-
* @param {...*} placeholders - The values to replace the placeholders in the template literal.
8-
* @returns {string} - The result string after processing the template literal.
9-
*/
10-
111
// core
122
export { createTag } from "./createTag/index.js";
133

src/inlineLists/inlineLists.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { createTag } from '../createTag/index.js';
22
import { stripIndent } from '../stripIndent/index.js';
33
import { inlineArrayTransformer } from '../inlineArrayTransformer/index.js';
44

5+
/**
6+
* Allows you to inline an array substitution as a list.
7+
* @implements {TemplateTag}
8+
*/
59
const inlineLists = createTag(inlineArrayTransformer(), stripIndent);
610

711
export { inlineLists };

src/oneLine/oneLine.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { createTag } from '../createTag/index.js';
22
import { trimResultTransformer } from '../trimResultTransformer/index.js';
33
import { replaceResultTransformer } from '../replaceResultTransformer/index.js';
44

5+
/**
6+
* Allows you to keep your single-line strings under 80 characters without resorting to crazy string concatenation.
7+
* @implements {TemplateTag}
8+
*/
59
const oneLine = createTag(
610
replaceResultTransformer(/(?:\n(?:\s*))+/g, ' '),
711
trimResultTransformer(),

src/oneLineCommaLists/oneLineCommaLists.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { inlineArrayTransformer } from '../inlineArrayTransformer/index.js';
33
import { trimResultTransformer } from '../trimResultTransformer/index.js';
44
import { replaceResultTransformer } from '../replaceResultTransformer/index.js';
55

6+
/**
7+
* Allows you to inline an array substitution as a comma-separated list, and is rendered out on to a single line.
8+
* @implements {TemplateTag}
9+
*/
610
const oneLineCommaLists = createTag(
711
inlineArrayTransformer({ separator: ',' }),
812
replaceResultTransformer(/(?:\s+)/g, ' '),

src/oneLineCommaListsAnd/oneLineCommaListsAnd.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { inlineArrayTransformer } from '../inlineArrayTransformer/index.js';
33
import { trimResultTransformer } from '../trimResultTransformer/index.js';
44
import { replaceResultTransformer } from '../replaceResultTransformer/index.js';
55

6+
/**
7+
* Allows you to inline an array substitution as a comma-separated list, the last of which is preceded by the word "and", and is rendered out on to a single line.
8+
* @implements {TemplateTag}
9+
*/
610
const oneLineCommaListsAnd = createTag(
711
inlineArrayTransformer({ separator: ',', conjunction: 'and' }),
812
replaceResultTransformer(/(?:\s+)/g, ' '),

src/oneLineCommaListsOr/oneLineCommaListsOr.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { inlineArrayTransformer } from '../inlineArrayTransformer/index.js';
33
import { trimResultTransformer } from '../trimResultTransformer/index.js';
44
import { replaceResultTransformer } from '../replaceResultTransformer/index.js';
55

6+
/**
7+
* Allows you to inline an array substitution as a comma-separated list, the last of which is preceded by the word "or", and is rendered out on to a single line.
8+
* @implements {TemplateTag}
9+
*/
610
const oneLineCommaListsOr = createTag(
711
inlineArrayTransformer({ separator: ',', conjunction: 'or' }),
812
replaceResultTransformer(/(?:\s+)/g, ' '),

src/oneLineInlineLists/oneLineInlineLists.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { inlineArrayTransformer } from '../inlineArrayTransformer/index.js';
33
import { trimResultTransformer } from '../trimResultTransformer/index.js';
44
import { replaceResultTransformer } from '../replaceResultTransformer/index.js';
55

6+
/**
7+
* Allows you to inline an array substitution as a list, rendered out on a single line.
8+
* @implements {TemplateTag}
9+
*/
610
const oneLineInlineLists = createTag(
711
inlineArrayTransformer(),
812
replaceResultTransformer(/(?:\s+)/g, ' '),

src/oneLineTrim/oneLineTrim.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { createTag } from '../createTag/index.js';
22
import { trimResultTransformer } from '../trimResultTransformer/index.js';
33
import { replaceResultTransformer } from '../replaceResultTransformer/index.js';
44

5+
/**
6+
* Allows you to keep your single-line strings under 80 characters while trimming the new lines.
7+
* @implements {TemplateTag}
8+
*/
59
const oneLineTrim = createTag(
610
replaceResultTransformer(/(?:\n\s*)/g, ''),
711
trimResultTransformer(),

src/replaceSubstitutionTransformer/replaceSubstitutionTransformer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Replaces the result of all substitutions (results of calling ${ ... }) with a new value.
3+
* Same as for `replaceResultTransformer`, replaceWhat can be a string or regular expression and replaceWith is the new value.
4+
*/
15
const replaceSubstitutionTransformer = (replaceWhat, replaceWith) => {
26
if (replaceWhat == null || replaceWith == null) {
37
throw new Error(

src/safeHtml/safeHtml.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import { inlineArrayTransformer } from '../inlineArrayTransformer/index.js';
44
import { splitStringTransformer } from '../splitStringTransformer/index.js';
55
import { replaceSubstitutionTransformer } from '../replaceSubstitutionTransformer/index.js';
66

7+
/**
8+
* A tag very similar to `html` but it does safe HTML escaping for strings coming from substitutions.
9+
* When combined with regular `html` tag, you can do basic HTML templating that is safe from
10+
* XSS (Cross-Site Scripting) attacks.
11+
* @implements {TemplateTag}
12+
*/
713
const safeHtml = createTag(
814
splitStringTransformer('\n'),
915
inlineArrayTransformer(),

src/splitStringTransformer/splitStringTransformer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* Splits a string substitution into an array by the provided splitBy substring, only if the string contains the splitBy substring.
3+
*/
14
const splitStringTransformer = (splitBy) => {
25
if (typeof splitBy !== 'string') {
36
throw new Error('You need to specify a string character to split by.');

src/stripIndent/stripIndent.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import { createTag } from '../createTag/index.js';
22
import { stripIndentTransformer } from '../stripIndentTransformer/index.js';
33
import { trimResultTransformer } from '../trimResultTransformer/index.js';
44

5+
/**
6+
* If you want to strip the initial indentation from the beginning of each line in a multiline string.
7+
* Important note: this tag will not indent multiline strings coming from the substitutions.
8+
* If you want that behavior, use the `html` tag (aliases: `source`, `codeBlock`).
9+
* @implements {TemplateTag}
10+
*/
511
const stripIndent = createTag(
612
stripIndentTransformer(),
713
trimResultTransformer('smart'),

src/stripIndents/stripIndents.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { createTag } from '../createTag/index.js';
22
import { stripIndentTransformer } from '../stripIndentTransformer/index.js';
33
import { trimResultTransformer } from '../trimResultTransformer/index.js';
44

5+
/**
6+
* If you want to strip *all* of the indentation from the beginning of each line in a multiline string.
7+
* @implements {TemplateTag}
8+
*/
59
const stripIndents = createTag(
610
stripIndentTransformer('all'),
711
trimResultTransformer('smart'),

types/proper-tags.d.cts

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,26 @@ export class TemplateTag {
1313
constructor(...transformers: any[]);
1414
}
1515
/**
16-
* An HTML tag function that processes a template literal and returns an HTML string.
17-
* @type {TemplateTag}
18-
*/
19-
export const html: TemplateTag;
16+
* A function that returns an HTML string by processing a template literal or a JSTag function.
17+
* @function
18+
* @implements {TemplateTag}
19+
*/
20+
export const html: Function;
2021
/**
2122
* Allows you to inline an array substitution as a comma-separated list.
22-
* @type {TemplateTag}
23+
* @implements {TemplateTag}
2324
*/
24-
export const commaLists: TemplateTag;
25+
export const commaLists: Function;
2526
/**
2627
* Allows you to inline an array substitution as a comma-separated list, the last of which is preceded by the word "and".
27-
* @type {TemplateTag}
28+
* @implements {TemplateTag}
2829
*/
29-
export const commaListsAnd: TemplateTag;
30+
export const commaListsAnd: Function;
3031
/**
3132
* Allows you to inline an array substitution as a comma-separated list, the last of which is preceded by the word "or".
32-
* @type {TemplateTag}
33+
* @implements {TemplateTag}
3334
*/
34-
export const commaListsOr: TemplateTag;
35+
export const commaListsOr: Function;
3536
/**
3637
* Consumes a pipeline of composable transformer plugins and produces a template tag.
3738
* @param {...Object} [...rawTransformers] - An array or arguments list of transformers
@@ -40,9 +41,9 @@ export const commaListsOr: TemplateTag;
4041
export function createTag(...rawTransformers: any[]): Function;
4142
/**
4243
* A no-op tag that might come in useful in some scenarios, e.g. mocking.
43-
* @type {TemplateTag}
44+
* @implements {TemplateTag}
4445
*/
45-
export const id: TemplateTag;
46+
export const id: Function;
4647
/**
4748
* Converts an array substitution to a string containing a list
4849
* @param {String} [opts.separator = ''] - The character that separates each item
@@ -52,12 +53,40 @@ export const id: TemplateTag;
5253
* @return {Object} - A transformer
5354
*/
5455
export function inlineArrayTransformer({ conjunction, separator, serial, }?: string): any;
56+
/**
57+
* Allows you to inline an array substitution as a list.
58+
* @implements {TemplateTag}
59+
*/
5560
export const inlineLists: Function;
61+
/**
62+
* Allows you to keep your single-line strings under 80 characters without resorting to crazy string concatenation.
63+
* @implements {TemplateTag}
64+
*/
5665
export const oneLine: Function;
66+
/**
67+
* Allows you to inline an array substitution as a comma-separated list, and is rendered out on to a single line.
68+
* @implements {TemplateTag}
69+
*/
5770
export const oneLineCommaLists: Function;
71+
/**
72+
* Allows you to inline an array substitution as a comma-separated list, the last of which is preceded by the word "and", and is rendered out on to a single line.
73+
* @implements {TemplateTag}
74+
*/
5875
export const oneLineCommaListsAnd: Function;
76+
/**
77+
* Allows you to inline an array substitution as a comma-separated list, the last of which is preceded by the word "or", and is rendered out on to a single line.
78+
* @implements {TemplateTag}
79+
*/
5980
export const oneLineCommaListsOr: Function;
81+
/**
82+
* Allows you to inline an array substitution as a list, rendered out on a single line.
83+
* @implements {TemplateTag}
84+
*/
6085
export const oneLineInlineLists: Function;
86+
/**
87+
* Allows you to keep your single-line strings under 80 characters while trimming the new lines.
88+
* @implements {TemplateTag}
89+
*/
6190
export const oneLineTrim: Function;
6291
export function removeNonPrintingValuesTransformer(): {
6392
onSubstitution(substitution: any): any;
@@ -72,20 +101,43 @@ export function replaceResultTransformer(replaceWhat: (string | RegExp), replace
72101
export function replaceStringTransformer(replaceWhat: any, replaceWith: any): {
73102
onString(str: any): any;
74103
};
104+
/**
105+
* Replaces the result of all substitutions (results of calling ${ ... }) with a new value.
106+
* Same as for `replaceResultTransformer`, replaceWhat can be a string or regular expression and replaceWith is the new value.
107+
*/
75108
export function replaceSubstitutionTransformer(replaceWhat: any, replaceWith: any): {
76109
onSubstitution(substitution: any): any;
77110
};
111+
/**
112+
* A tag very similar to `html` but it does safe HTML escaping for strings coming from substitutions.
113+
* When combined with regular `html` tag, you can do basic HTML templating that is safe from
114+
* XSS (Cross-Site Scripting) attacks.
115+
* @implements {TemplateTag}
116+
*/
78117
export const safeHtml: Function;
118+
/**
119+
* Splits a string substitution into an array by the provided splitBy substring, only if the string contains the splitBy substring.
120+
*/
79121
export function splitStringTransformer(splitBy: any): {
80122
onSubstitution(substitution: any): any;
81123
};
124+
/**
125+
* If you want to strip the initial indentation from the beginning of each line in a multiline string.
126+
* Important note: this tag will not indent multiline strings coming from the substitutions.
127+
* If you want that behavior, use the `html` tag (aliases: `source`, `codeBlock`).
128+
* @implements {TemplateTag}
129+
*/
82130
export const stripIndent: Function;
83131
/**
84132
* strips indentation from a template literal
85133
* @param {String} type = 'initial' - whether to remove all indentation or just leading indentation. can be 'all' or 'initial'
86134
* @return {Object} - a TemplateTag transformer
87135
*/
88136
export function stripIndentTransformer(type?: string): any;
137+
/**
138+
* If you want to strip *all* of the indentation from the beginning of each line in a multiline string.
139+
* @implements {TemplateTag}
140+
*/
89141
export const stripIndents: Function;
90142
/**
91143
* TemplateTag transformer that trims whitespace on the end result of a tagged template

0 commit comments

Comments
 (0)