topkat-utils 1.0.45 → 1.0.46

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/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ### v1.0.46
2
+ * FIX templater undefined no error anymore
3
+
1
4
  ### v1.0.42
2
5
  * type for date function
3
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topkat-utils",
3
- "version": "1.0.45",
3
+ "version": "1.0.46",
4
4
  "type": "commonjs",
5
5
  "private": false,
6
6
  "description": "UTILS BIG TIME",
package/utils.ts CHANGED
@@ -125,6 +125,7 @@ function sortUrlsByDeepnessInArrayOrObject(urlObjOrArr, propInObjectOrIndexInArr
125
125
  type MiniTemplaterOptions = {
126
126
  valueWhenNotSet?: string
127
127
  regexp?: RegExp
128
+ valueWhenContentUndefined?: string
128
129
  }
129
130
  /** Replace variables in a string like: `Hello {{userName}}!`
130
131
  * @param {String} content
@@ -133,13 +134,14 @@ type MiniTemplaterOptions = {
133
134
  * * valueWhenNotSet => replacer for undefined values. Default: ''
134
135
  * * regexp => must be 'g' and first capturing group matching the value to replace. Default: /{{\s*([^}]*)\s*}}/g
135
136
  */
136
- function miniTemplater(content: string, varz: ObjectGeneric, options: MiniTemplaterOptions = {}) {
137
+ function miniTemplater(content: string, varz: ObjectGeneric, options: MiniTemplaterOptions = {}): string {
137
138
  options = {
138
139
  valueWhenNotSet: '',
139
140
  regexp: /{{\s*([^}]*)\s*}}/g,
141
+ valueWhenContentUndefined: '',
140
142
  ...options,
141
143
  };
142
- return content.replace(options.regexp, (m, $1) => isset(varz[$1]) ? varz[$1] : options.valueWhenNotSet);
144
+ return isset(content) ? content.replace(options.regexp, (m, $1) => isset(varz[$1]) ? varz[$1] : options.valueWhenNotSet) : options.valueWhenContentUndefined
143
145
  }
144
146
 
145
147
  /**