@zodash/format
Advanced tools
Comparing version 1.1.0-alpha.0 to 1.1.1
@@ -6,2 +6,10 @@ # Change Log | ||
## [1.1.1](https://github.com/zcorky/zodash/compare/@zodash/format@1.1.0-alpha.0...@zodash/format@1.1.1) (2020-07-31) | ||
**Note:** Version bump only for package @zodash/format | ||
# 1.1.0-alpha.0 (2020-07-31) | ||
@@ -8,0 +16,0 @@ |
@@ -5,2 +5,2 @@ export interface Seperator { | ||
} | ||
export declare function format(text: string, map: Record<string, any>, seperator?: Seperator): string; | ||
export declare function format(text: string, mapOrFn: Record<string, any> | ((key: string, text: string) => any), seperator?: Seperator): string; |
@@ -8,8 +8,13 @@ "use strict"; | ||
}; | ||
function format(text, map, seperator = DEFAULT_SEPERATOR) { | ||
function format(text, mapOrFn, seperator = DEFAULT_SEPERATOR) { | ||
const seperatorStart = seperator.start; | ||
const SeperatorEnd = seperator.end; | ||
const pattern = new RegExp(`${seperatorStart}([^${SeperatorEnd}]+)${SeperatorEnd}`, 'g'); | ||
if (typeof mapOrFn === 'function') { | ||
return text.replace(pattern, (_, key) => { | ||
return mapOrFn(key, text); | ||
}); | ||
} | ||
return text.replace(pattern, (_, key) => { | ||
return typeof map[key] !== 'undefined' ? map[key] : ''; | ||
return typeof mapOrFn[key] !== 'undefined' ? mapOrFn[key] : ''; | ||
}); | ||
@@ -16,0 +21,0 @@ } |
{ | ||
"name": "@zodash/format", | ||
"version": "1.1.0-alpha.0", | ||
"version": "1.1.1", | ||
"description": "format string with object values", | ||
@@ -68,3 +68,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "64874eb0f5ed4a0b664bbdf64e5e1ca6430b14c9", | ||
"gitHead": "101a6993addba080c1e000a510853db38a18566c", | ||
"devDependencies": { | ||
@@ -71,0 +71,0 @@ "@zodash/get": "^1.0.22" |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6935
26
0