@followupus/common 0.10.1 → 0.10.2

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.
@@ -1,3 +1,4 @@
1
1
  export declare function filterHtmlTags(htmlSource: string): string;
2
2
  export declare function getTextValue(variable: Record<string, string>): string;
3
- export declare function formatTemplate(text: string, rawVariables: Record<string, Record<string, string> | string>): string;
3
+ export declare function truncateString(str: string, maxLength: number): string;
4
+ export declare function formatTemplate(text: string, rawVariables: Record<string, Record<string, string> | string>, maxLength?: number): string;
@@ -1,6 +1,5 @@
1
1
  export function filterHtmlTags(htmlSource) {
2
2
  return htmlSource.replace(/<[^>]*>/g, "").replace(/&nbsp;/g, " ");
3
- ;
4
3
  }
5
4
  export function getTextValue(variable) {
6
5
  if (typeof variable !== "object") {
@@ -33,9 +32,17 @@ function keysToLowerCase(obj) {
33
32
  }
34
33
  return newObj;
35
34
  }
35
+ export function truncateString(str, maxLength) {
36
+ if (str?.length > maxLength) {
37
+ return str.slice(0, maxLength) + "...";
38
+ }
39
+ else {
40
+ return str;
41
+ }
42
+ }
36
43
  //** case insensitive
37
44
  //** {Who} can be replaced by variable {who:{name:ttt}}
38
- export function formatTemplate(text, rawVariables) {
45
+ export function formatTemplate(text, rawVariables, maxLength = Number.MAX_SAFE_INTEGER) {
39
46
  const matches = text?.match(/{([^}]+)}/g);
40
47
  if (matches) {
41
48
  const formatVariables = keysToLowerCase(rawVariables);
@@ -47,7 +54,7 @@ export function formatTemplate(text, rawVariables) {
47
54
  finalStr = finalStr.replace(match, typeof variable === "string" ? variable : getTextValue(variable));
48
55
  }
49
56
  });
50
- return finalStr;
57
+ return truncateString(finalStr, maxLength);
51
58
  }
52
- return text;
59
+ return truncateString(text, maxLength);
53
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@followupus/common",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "followup common utils npm package with TypeScript and VSCode",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",