resources-tsk
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -104,1 +104,7 @@ # Changelog | ||
- Types was refactoring | ||
## [2.1.0] — 2022-01-18 | ||
### Added | ||
- Function for replace key params into text was added. |
@@ -12,2 +12,4 @@ export declare class Resources { | ||
getWithParams(resourceName: string, params: Record<string, string>, language?: string): string; | ||
static replaceParams(text: string, params: Record<string, string>): string; | ||
private static applyPattern; | ||
} |
@@ -83,2 +83,10 @@ "use strict"; | ||
} | ||
return Resources.applyPattern(resource, params); | ||
} | ||
static replaceParams(text, params) { | ||
if (!text || !params) | ||
return null; | ||
return Resources.applyPattern(text, params); | ||
} | ||
static applyPattern(text, params) { | ||
const keys = Object.keys(params); | ||
@@ -88,9 +96,9 @@ keys.forEach((key) => { | ||
const regex = RegExp(pattern); | ||
while (regex.test(resource)) { | ||
resource = resource.replace(`{{${key}}}`, params[key]); | ||
while (regex.test(text)) { | ||
text = text.replace(`{{${key}}}`, params[key]); | ||
} | ||
}); | ||
return resource; | ||
return text; | ||
} | ||
} | ||
exports.Resources = Resources; |
{ | ||
"name": "resources-tsk", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "resource tool for use with or without NodeTskeleton template project", | ||
@@ -5,0 +5,0 @@ "repository": { |
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
15525
183