@mark1russell7/text 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,6 +38,19 @@ countOf(1024, "site"); // "1,024 sites"
38
38
  countOf(3, "match", "matches"); // "3 matches"
39
39
  ```
40
40
 
41
+ `listOf(parts, options?)` joins the parts into an English list. A comma goes between the parts, and the conjunction goes before the last part. The option `conjunction` sets the word, and its default is "and". With the option `serialComma`, a comma also goes before the conjunction in a list of three parts or more.
42
+
43
+ The entry `@mark1russell7/text/english` has `listOf` and `countOf`. The root entry has only `countOf`, to keep its size.
44
+
45
+ ```ts
46
+ import { listOf } from "@mark1russell7/text/english";
47
+
48
+ listOf([]); // ""
49
+ listOf(["a", "b"]); // "a and b"
50
+ listOf(["a", "b", "c"]); // "a, b and c"
51
+ listOf(["a", "b", "c"], { conjunction: "or", serialComma: true }); // "a, b, or c"
52
+ ```
53
+
41
54
  ## A word search
42
55
 
43
56
  `wordSearch(query)` gives a test of a text. A text agrees when it has each word of the search, in any order and in any case. A word can be a part of a longer word.
@@ -245,6 +258,7 @@ The tests also examine 18 copies of a cut with a mark, from a later list of the
245
258
  - `escapeMarkdown` does not change spaces. Four spaces at the start of a line make a code block.
246
259
  - `wordSearch` keeps accents, so "cafe" does not find "café".
247
260
  - `countOf` knows no irregular plural. Give the plural noun for each noun that does not add "s".
261
+ - `listOf` does not change the parts. A part with a comma makes a list that a reader cannot split again.
248
262
  - `errorMessage` gives only the message. It does not add the name of the error, its `cause` or its stack.
249
263
  - `redactSecrets` removes only the forms in its table. A secret in a JSON string with escapes, or in a different encoding, stays.
250
264
  - `findSecretShapes` knows only the shapes in its table. A token directly after a letter or a digit is not a match. A token of a service that is not in the table stays.
@@ -0,0 +1,32 @@
1
+ /**
2
+ * This module has the English word forms: a count with a noun, and a list of parts. It is the entry
3
+ * `@mark1russell7/text/english`. The root entry has only `countOf`.
4
+ */
5
+ /**
6
+ * This function gives a count with a noun, for example "1 site" or "1,024 sites". Only the count 1 takes the singular
7
+ * noun. Each other count takes the plural noun, also 0 and -1. The count has the digit groups of English and at most
8
+ * three decimal places.
9
+ *
10
+ * @param count - The number of things.
11
+ * @param noun - The singular noun.
12
+ * @param plural - The plural noun. The default is the singular noun with the letter "s" at the end.
13
+ * @returns The count, a space and the noun.
14
+ */
15
+ export declare function countOf(count: number, noun: string, plural?: string): string;
16
+ /** The options of `listOf`. */
17
+ export interface ListOptions {
18
+ /** The word before the last part. The default is "and". */
19
+ readonly conjunction?: string;
20
+ /** With true, a comma also goes before the conjunction in a list of three parts or more. The default is false. */
21
+ readonly serialComma?: boolean;
22
+ }
23
+ /**
24
+ * This function joins the parts into an English list, for example "a", "a and b" or "a, b and c". A comma and a space go
25
+ * between the parts, and the conjunction goes before the last part. No part gives an empty text. The parts do not change.
26
+ *
27
+ * @param parts - The parts of the list, in their order.
28
+ * @param options - The conjunction and the serial comma.
29
+ * @returns The list as one text.
30
+ */
31
+ export declare function listOf(parts: readonly string[], options?: ListOptions): string;
32
+ //# sourceMappingURL=english.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"english.d.ts","names":[],"sources":["../src/english.ts"],"mappings":";;;;;;;;;;;;;;wBAegB,QAAQ,eAAe,cAAc;;iBAKpC;;WAEN;;WAEA;;;;;;;;;;wBAWK,OAAO,0BAA0B,UAAS"}
@@ -0,0 +1,35 @@
1
+ // src/english.ts
2
+ /**
3
+ * This module has the English word forms: a count with a noun, and a list of parts. It is the entry
4
+ * `@mark1russell7/text/english`. The root entry has only `countOf`.
5
+ */
6
+ /**
7
+ * This function gives a count with a noun, for example "1 site" or "1,024 sites". Only the count 1 takes the singular
8
+ * noun. Each other count takes the plural noun, also 0 and -1. The count has the digit groups of English and at most
9
+ * three decimal places.
10
+ *
11
+ * @param count - The number of things.
12
+ * @param noun - The singular noun.
13
+ * @param plural - The plural noun. The default is the singular noun with the letter "s" at the end.
14
+ * @returns The count, a space and the noun.
15
+ */
16
+ function countOf(count, noun, plural = `${noun}s`) {
17
+ return `${count.toLocaleString("en")} ${count === 1 ? noun : plural}`;
18
+ }
19
+ /**
20
+ * This function joins the parts into an English list, for example "a", "a and b" or "a, b and c". A comma and a space go
21
+ * between the parts, and the conjunction goes before the last part. No part gives an empty text. The parts do not change.
22
+ *
23
+ * @param parts - The parts of the list, in their order.
24
+ * @param options - The conjunction and the serial comma.
25
+ * @returns The list as one text.
26
+ */
27
+ function listOf(parts, options = {}) {
28
+ const { conjunction = "and", serialComma = false } = options;
29
+ if (parts.length < 2) return parts[0] ?? "";
30
+ const comma = serialComma && parts.length > 2 ? "," : "";
31
+ return `${parts.slice(0, -1).join(", ")}${comma} ${conjunction} ${parts[parts.length - 1]}`;
32
+ }
33
+ export { countOf, listOf };
34
+
35
+ //# sourceMappingURL=english.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"english.js","names":[],"sources":["../src/english.ts"],"sourcesContent":["/**\n * This module has the English word forms: a count with a noun, and a list of parts. It is the entry\n * `@mark1russell7/text/english`. The root entry has only `countOf`.\n */\n\n/**\n * This function gives a count with a noun, for example \"1 site\" or \"1,024 sites\". Only the count 1 takes the singular\n * noun. Each other count takes the plural noun, also 0 and -1. The count has the digit groups of English and at most\n * three decimal places.\n *\n * @param count - The number of things.\n * @param noun - The singular noun.\n * @param plural - The plural noun. The default is the singular noun with the letter \"s\" at the end.\n * @returns The count, a space and the noun.\n */\nexport function countOf(count: number, noun: string, plural = `${noun}s`): string {\n return `${count.toLocaleString(\"en\")} ${count === 1 ? noun : plural}`;\n}\n\n/** The options of `listOf`. */\nexport interface ListOptions {\n /** The word before the last part. The default is \"and\". */\n readonly conjunction?: string;\n /** With true, a comma also goes before the conjunction in a list of three parts or more. The default is false. */\n readonly serialComma?: boolean;\n}\n\n/**\n * This function joins the parts into an English list, for example \"a\", \"a and b\" or \"a, b and c\". A comma and a space go\n * between the parts, and the conjunction goes before the last part. No part gives an empty text. The parts do not change.\n *\n * @param parts - The parts of the list, in their order.\n * @param options - The conjunction and the serial comma.\n * @returns The list as one text.\n */\nexport function listOf(parts: readonly string[], options: ListOptions = {}): string {\n const { conjunction = \"and\", serialComma = false } = options;\n if (parts.length < 2) return parts[0] ?? \"\";\n const comma = serialComma && parts.length > 2 ? \",\" : \"\";\n return `${parts.slice(0, -1).join(\", \")}${comma} ${conjunction} ${parts[parts.length - 1]}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,SAAgB,QAAQ,OAAe,MAAc,SAAS,GAAG,KAAK,IAAY;CAChF,OAAO,GAAG,MAAM,eAAe,IAAI,EAAE,GAAG,UAAU,IAAI,OAAO;AAC/D;;;;;;;;;AAkBA,SAAgB,OAAO,OAA0B,UAAuB,CAAC,GAAW;CAClF,MAAM,EAAE,cAAc,OAAO,cAAc,UAAU;CACrD,IAAI,MAAM,SAAS,GAAG,OAAO,MAAM,MAAM;CACzC,MAAM,QAAQ,eAAe,MAAM,SAAS,IAAI,MAAM;CACtD,OAAO,GAAG,MAAM,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,MAAM,GAAG,YAAY,GAAG,MAAM,MAAM,SAAS;AACzF"}
package/build/index.d.ts CHANGED
@@ -2,22 +2,9 @@
2
2
  * The entry of `@mark1russell7/text`: plain text helpers. The first group is the escapes for HTML, attributes, regular
3
3
  * expressions, Markdown and GitHub Actions workflow commands. The other groups are the English word forms, a word
4
4
  * search and the text of a thrown value. The entry `@mark1russell7/text/redact` removes secrets from a text, and the entry
5
- * `@mark1russell7/text/order` has two orders of texts.
5
+ * `@mark1russell7/text/order` has two orders of texts. The entry `@mark1russell7/text/english` adds the list join `listOf`.
6
6
  */
7
- /**
8
- * This module has the English word forms.
9
- */
10
- /**
11
- * This function gives a count with a noun, for example "1 site" or "1,024 sites". Only the count 1 takes the singular
12
- * noun. Each other count takes the plural noun, also 0 and -1. The count has the digit groups of English and at most
13
- * three decimal places.
14
- *
15
- * @param count - The number of things.
16
- * @param noun - The singular noun.
17
- * @param plural - The plural noun. The default is the singular noun with the letter "s" at the end.
18
- * @returns The count, a space and the noun.
19
- */
20
- export declare function countOf(count: number, noun: string, plural?: string): string;
7
+ import { countOf } from "./english.js";
21
8
  /**
22
9
  * This module has the text of a thrown value.
23
10
  */
@@ -117,4 +104,5 @@ export declare function searchKey(text: string): string;
117
104
  * @returns The test of a text.
118
105
  */
119
106
  export declare function wordSearch(query: string): (text: string) => boolean;
107
+ export { countOf };
120
108
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/english.ts","../src/error.ts","../src/escape.ts","../src/search.ts"],"mappings":";;;;;;;;;;;;;;;;;;;wBAcgB,QAAQ,eAAe,cAAc;;;;;;;;;;;;;;;;;;wBCIrC,aAAa;;;;;;;;wBCHb,WAAW;;;;;;;;wBAWX,gBAAgB;;;;;;;;;wBAYhB,aAAa;;;;;;;;;;;;wBAeb,eAAe;;;;;;;;wBAWf,mBAAmB;;;;;;;;wBAWnB,uBAAuB;;;;;;;;;;;;;;;;;wBCnDvB,UAAU;;;;;;;;;;;wBAcV,WAAW,iBAAiB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/error.ts","../src/escape.ts","../src/search.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;wBAkBgB,aAAa;;;;;;;;wBCHb,WAAW;;;;;;;;wBAWX,gBAAgB;;;;;;;;;wBAYhB,aAAa;;;;;;;;;;;;wBAeb,eAAe;;;;;;;;wBAWf,mBAAmB;;;;;;;;wBAWnB,uBAAuB;;;;;;;;;;;;;;;;;wBCnDvB,UAAU;;;;;;;;;;;wBAcV,WAAW,iBAAiB"}
package/build/index.js CHANGED
@@ -1,21 +1,5 @@
1
+ import { countOf } from "./english.js";
1
2
  import { a as escapeWorkflowData, i as escapeRegExp, n as escapeHtml, o as escapeWorkflowProperty, r as escapeMarkdown, t as escapeAttribute } from "./escape-vfOeIxac.js";
2
- // src/english.ts
3
- /**
4
- * This module has the English word forms.
5
- */
6
- /**
7
- * This function gives a count with a noun, for example "1 site" or "1,024 sites". Only the count 1 takes the singular
8
- * noun. Each other count takes the plural noun, also 0 and -1. The count has the digit groups of English and at most
9
- * three decimal places.
10
- *
11
- * @param count - The number of things.
12
- * @param noun - The singular noun.
13
- * @param plural - The plural noun. The default is the singular noun with the letter "s" at the end.
14
- * @returns The count, a space and the noun.
15
- */
16
- function countOf(count, noun, plural = `${noun}s`) {
17
- return `${count.toLocaleString("en")} ${count === 1 ? noun : plural}`;
18
- }
19
3
  // src/error.ts
20
4
  /**
21
5
  * This module has the text of a thrown value.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/english.ts","../src/error.ts","../src/search.ts"],"sourcesContent":["/**\n * This module has the English word forms.\n */\n\n/**\n * This function gives a count with a noun, for example \"1 site\" or \"1,024 sites\". Only the count 1 takes the singular\n * noun. Each other count takes the plural noun, also 0 and -1. The count has the digit groups of English and at most\n * three decimal places.\n *\n * @param count - The number of things.\n * @param noun - The singular noun.\n * @param plural - The plural noun. The default is the singular noun with the letter \"s\" at the end.\n * @returns The count, a space and the noun.\n */\nexport function countOf(count: number, noun: string, plural = `${noun}s`): string {\n return `${count.toLocaleString(\"en\")} ${count === 1 ? noun : plural}`;\n}\n","/**\n * This module has the text of a thrown value.\n */\n\n/**\n * This function gives the text of a thrown value, for a log line or a message on a screen. It does not throw.\n *\n * - An object with a `message` text gives that text. The check reads the field, not `instanceof Error`, so an error\n * from another realm (a `vm` context or an `iframe`) also gives its message.\n * - An `Error` with a `message` that is not a text gives `String(message)`. The brand check of\n * `Object.prototype.toString` finds an `Error` of each realm.\n * - Each other value gives `String(value)`.\n * - When `String` throws, the function gives the tag of `Object.prototype.toString`, for example `[object Object]`.\n * - A revoked `Proxy` gives its `typeof` in brackets: `[object]`.\n *\n * @param error - The thrown value. It can be any value.\n * @returns The text of the value.\n */\nexport function errorMessage(error: unknown): string {\n try {\n if (typeof error === \"object\" && error !== null && \"message\" in error) {\n const message: unknown = error.message;\n if (typeof message === \"string\") return message;\n if (Object.prototype.toString.call(error) === \"[object Error]\") return String(message);\n }\n return String(error);\n } catch {\n // String() throws for an object with no prototype, for a toString that throws and for a message getter that throws.\n try {\n return Object.prototype.toString.call(error);\n } catch {\n // A revoked Proxy throws also here. The operator typeof never throws.\n return `[${typeof error}]`;\n }\n }\n}\n","/**\n * This module has a word search of plain text. A text agrees with a search when the text has each word of the search,\n * in any order. The case of the letters is not significant.\n */\n\n/** The small final sigma. Unicode case folding changes it to the small sigma, so a word agrees in each position. */\nconst FINAL_SIGMA = /ς/gu;\n\n/**\n * This function gives the search key of a text. `wordSearch` compares the keys of texts. The function does these steps:\n *\n * 1. It applies the Unicode normalization NFKC. Thus the ligature \"fi\" agrees with \"fi\", and full-width letters agree\n * with ASCII letters.\n * 2. It applies the full lower case, then the full upper case, then the full lower case. Thus \"ß\", \"ẞ\" and \"SS\" give\n * \"ss\".\n * 3. It changes the small final sigma \"ς\" to \"σ\", as Unicode case folding does.\n * 4. It applies NFKC again.\n *\n * The steps use no rules of a locale. Thus the Turkish \"İ\" gives \"i\" with a combining dot above (U+0307), and the\n * Turkish \"ı\" gives \"i\". The key of a key is the same key. Accents stay, so \"é\" does not agree with \"e\".\n *\n * @param text - The plain text.\n * @returns The search key of the text.\n */\nexport function searchKey(text: string): string {\n return text.normalize(\"NFKC\").toLowerCase().toUpperCase().toLowerCase().replace(FINAL_SIGMA, \"σ\").normalize(\"NFKC\");\n}\n\n/**\n * This function gives the test of a search. The function makes the key of the search with `searchKey`. Then it splits\n * the key into words at each run of white space, the class `\\s` of a regular expression.\n *\n * The test tells if the key of a text contains each word, in any order. A word can be a part of a longer word, so the\n * search \"art\" finds \"Party\". A search with no words agrees with each text.\n *\n * @param query - The search, as a person types it.\n * @returns The test of a text.\n */\nexport function wordSearch(query: string): (text: string) => boolean {\n const words = searchKey(query)\n .split(/\\s+/u)\n .filter((word) => word !== \"\");\n return (text) => words.length === 0 || words.every((word) => searchKey(text).includes(word));\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAgB,QAAQ,OAAe,MAAc,SAAS,GAAG,KAAK,IAAY;CAChF,OAAO,GAAG,MAAM,eAAe,IAAI,EAAE,GAAG,UAAU,IAAI,OAAO;AAC/D;;;;;;;;;;;;;;;;;;;ACEA,SAAgB,aAAa,OAAwB;CACnD,IAAI;EACF,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,aAAa,OAAO;GACrE,MAAM,UAAmB,MAAM;GAC/B,IAAI,OAAO,YAAY,UAAU,OAAO;GACxC,IAAI,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM,kBAAkB,OAAO,OAAO,OAAO;EACvF;EACA,OAAO,OAAO,KAAK;CACrB,QAAQ;EAEN,IAAI;GACF,OAAO,OAAO,UAAU,SAAS,KAAK,KAAK;EAC7C,QAAQ;GAEN,OAAO,IAAI,OAAO,MAAM;EAC1B;CACF;AACF;;;;;;;AC7BA,MAAM,cAAc;;;;;;;;;;;;;;;;;AAkBpB,SAAgB,UAAU,MAAsB;CAC9C,OAAO,KAAK,UAAU,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC,CAAC,QAAQ,aAAa,GAAG,CAAC,CAAC,UAAU,MAAM;AACpH;;;;;;;;;;;AAYA,SAAgB,WAAW,OAA0C;CACnE,MAAM,QAAQ,UAAU,KAAK,CAAC,CAC3B,MAAM,MAAM,CAAC,CACb,QAAQ,SAAS,SAAS,EAAE;CAC/B,QAAQ,SAAS,MAAM,WAAW,KAAK,MAAM,OAAO,SAAS,UAAU,IAAI,CAAC,CAAC,SAAS,IAAI,CAAC;AAC7F"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/error.ts","../src/search.ts"],"sourcesContent":["/**\n * This module has the text of a thrown value.\n */\n\n/**\n * This function gives the text of a thrown value, for a log line or a message on a screen. It does not throw.\n *\n * - An object with a `message` text gives that text. The check reads the field, not `instanceof Error`, so an error\n * from another realm (a `vm` context or an `iframe`) also gives its message.\n * - An `Error` with a `message` that is not a text gives `String(message)`. The brand check of\n * `Object.prototype.toString` finds an `Error` of each realm.\n * - Each other value gives `String(value)`.\n * - When `String` throws, the function gives the tag of `Object.prototype.toString`, for example `[object Object]`.\n * - A revoked `Proxy` gives its `typeof` in brackets: `[object]`.\n *\n * @param error - The thrown value. It can be any value.\n * @returns The text of the value.\n */\nexport function errorMessage(error: unknown): string {\n try {\n if (typeof error === \"object\" && error !== null && \"message\" in error) {\n const message: unknown = error.message;\n if (typeof message === \"string\") return message;\n if (Object.prototype.toString.call(error) === \"[object Error]\") return String(message);\n }\n return String(error);\n } catch {\n // String() throws for an object with no prototype, for a toString that throws and for a message getter that throws.\n try {\n return Object.prototype.toString.call(error);\n } catch {\n // A revoked Proxy throws also here. The operator typeof never throws.\n return `[${typeof error}]`;\n }\n }\n}\n","/**\n * This module has a word search of plain text. A text agrees with a search when the text has each word of the search,\n * in any order. The case of the letters is not significant.\n */\n\n/** The small final sigma. Unicode case folding changes it to the small sigma, so a word agrees in each position. */\nconst FINAL_SIGMA = /ς/gu;\n\n/**\n * This function gives the search key of a text. `wordSearch` compares the keys of texts. The function does these steps:\n *\n * 1. It applies the Unicode normalization NFKC. Thus the ligature \"fi\" agrees with \"fi\", and full-width letters agree\n * with ASCII letters.\n * 2. It applies the full lower case, then the full upper case, then the full lower case. Thus \"ß\", \"ẞ\" and \"SS\" give\n * \"ss\".\n * 3. It changes the small final sigma \"ς\" to \"σ\", as Unicode case folding does.\n * 4. It applies NFKC again.\n *\n * The steps use no rules of a locale. Thus the Turkish \"İ\" gives \"i\" with a combining dot above (U+0307), and the\n * Turkish \"ı\" gives \"i\". The key of a key is the same key. Accents stay, so \"é\" does not agree with \"e\".\n *\n * @param text - The plain text.\n * @returns The search key of the text.\n */\nexport function searchKey(text: string): string {\n return text.normalize(\"NFKC\").toLowerCase().toUpperCase().toLowerCase().replace(FINAL_SIGMA, \"σ\").normalize(\"NFKC\");\n}\n\n/**\n * This function gives the test of a search. The function makes the key of the search with `searchKey`. Then it splits\n * the key into words at each run of white space, the class `\\s` of a regular expression.\n *\n * The test tells if the key of a text contains each word, in any order. A word can be a part of a longer word, so the\n * search \"art\" finds \"Party\". A search with no words agrees with each text.\n *\n * @param query - The search, as a person types it.\n * @returns The test of a text.\n */\nexport function wordSearch(query: string): (text: string) => boolean {\n const words = searchKey(query)\n .split(/\\s+/u)\n .filter((word) => word !== \"\");\n return (text) => words.length === 0 || words.every((word) => searchKey(text).includes(word));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,aAAa,OAAwB;CACnD,IAAI;EACF,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,aAAa,OAAO;GACrE,MAAM,UAAmB,MAAM;GAC/B,IAAI,OAAO,YAAY,UAAU,OAAO;GACxC,IAAI,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM,kBAAkB,OAAO,OAAO,OAAO;EACvF;EACA,OAAO,OAAO,KAAK;CACrB,QAAQ;EAEN,IAAI;GACF,OAAO,OAAO,UAAU,SAAS,KAAK,KAAK;EAC7C,QAAQ;GAEN,OAAO,IAAI,OAAO,MAAM;EAC1B;CACF;AACF;;;;;;;AC7BA,MAAM,cAAc;;;;;;;;;;;;;;;;;AAkBpB,SAAgB,UAAU,MAAsB;CAC9C,OAAO,KAAK,UAAU,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC,CAAC,QAAQ,aAAa,GAAG,CAAC,CAAC,UAAU,MAAM;AACpH;;;;;;;;;;;AAYA,SAAgB,WAAW,OAA0C;CACnE,MAAM,QAAQ,UAAU,KAAK,CAAC,CAC3B,MAAM,MAAM,CAAC,CACb,QAAQ,SAAS,SAAS,EAAE;CAC/B,QAAQ,SAAS,MAAM,WAAW,KAAK,MAAM,OAAO,SAAS,UAAU,IAAI,CAAC,CAAC,SAAS,IAAI,CAAC;AAC7F"}
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/text",
4
- "version": "0.0.10",
5
- "description": "Plain text helpers: the escapes for HTML, attributes, patterns, Markdown and workflow commands, English word forms (countOf), a word search (wordSearch), the text of a thrown value (errorMessage), the orders of texts by code units and by code points (compareCodeUnits, compareCodePoints), the removal of secrets (redactSecrets) and the shapes of tokens (findSecretShapes, redactSecretShapes, findSecretShapesInValue), and lengths in code units, code points and graphemes with truncation and padding (textLength, truncate, pad), the marked parts of a text (partsAt, partsOf), and a scan of HTML for its text and its start tags (scanHtml).",
4
+ "version": "0.0.11",
5
+ "description": "Plain text helpers: the escapes for HTML, attributes, patterns, Markdown and workflow commands, English word forms (countOf, listOf), a word search (wordSearch), the text of a thrown value (errorMessage), the orders of texts by code units and by code points (compareCodeUnits, compareCodePoints), the removal of secrets (redactSecrets) and the shapes of tokens (findSecretShapes, redactSecretShapes, findSecretShapesInValue), and lengths in code units, code points and graphemes with truncation and padding (textLength, truncate, pad), the marked parts of a text (partsAt, partsOf), and a scan of HTML for its text and its start tags (scanHtml).",
6
6
  "keywords": [
7
7
  "text",
8
8
  "escape",
@@ -60,6 +60,10 @@
60
60
  "types": "./build/html.d.ts",
61
61
  "default": "./build/html.js"
62
62
  },
63
+ "./english": {
64
+ "types": "./build/english.d.ts",
65
+ "default": "./build/english.js"
66
+ },
63
67
  "./package.json": "./package.json"
64
68
  },
65
69
  "files": [
package/src/english.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /**
2
- * This module has the English word forms.
2
+ * This module has the English word forms: a count with a noun, and a list of parts. It is the entry
3
+ * `@mark1russell7/text/english`. The root entry has only `countOf`.
3
4
  */
4
5
 
5
6
  /**
@@ -15,3 +16,26 @@
15
16
  export function countOf(count: number, noun: string, plural = `${noun}s`): string {
16
17
  return `${count.toLocaleString("en")} ${count === 1 ? noun : plural}`;
17
18
  }
19
+
20
+ /** The options of `listOf`. */
21
+ export interface ListOptions {
22
+ /** The word before the last part. The default is "and". */
23
+ readonly conjunction?: string;
24
+ /** With true, a comma also goes before the conjunction in a list of three parts or more. The default is false. */
25
+ readonly serialComma?: boolean;
26
+ }
27
+
28
+ /**
29
+ * This function joins the parts into an English list, for example "a", "a and b" or "a, b and c". A comma and a space go
30
+ * between the parts, and the conjunction goes before the last part. No part gives an empty text. The parts do not change.
31
+ *
32
+ * @param parts - The parts of the list, in their order.
33
+ * @param options - The conjunction and the serial comma.
34
+ * @returns The list as one text.
35
+ */
36
+ export function listOf(parts: readonly string[], options: ListOptions = {}): string {
37
+ const { conjunction = "and", serialComma = false } = options;
38
+ if (parts.length < 2) return parts[0] ?? "";
39
+ const comma = serialComma && parts.length > 2 ? "," : "";
40
+ return `${parts.slice(0, -1).join(", ")}${comma} ${conjunction} ${parts[parts.length - 1]}`;
41
+ }
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * The entry of `@mark1russell7/text`: plain text helpers. The first group is the escapes for HTML, attributes, regular
3
3
  * expressions, Markdown and GitHub Actions workflow commands. The other groups are the English word forms, a word
4
4
  * search and the text of a thrown value. The entry `@mark1russell7/text/redact` removes secrets from a text, and the entry
5
- * `@mark1russell7/text/order` has two orders of texts.
5
+ * `@mark1russell7/text/order` has two orders of texts. The entry `@mark1russell7/text/english` adds the list join `listOf`.
6
6
  */
7
7
  export { countOf } from "./english.ts";
8
8
  export { errorMessage } from "./error.ts";