-
Notifications
You must be signed in to change notification settings - Fork 1
map replace prefix
Subhajit Sahu edited this page May 5, 2020
·
1 revision
Replace prefix of string using map.
const mapReplacePrefix = require('@extra-string/map-replace-prefix');
// mapReplacePrefix(<string>, <map>, [max prefix length])
mapReplacePrefix('dishonoured', new Map([['dis', ''], ['un', ''], ['in', '']]));
// 'honoured'
mapReplacePrefix('dishonoured', new Map([['honour', 'respect'], ['flatter', 'mock']]));
// 'dishonoured' (only prefix)
mapReplacePrefix('dishonoured', new Map([['dis', 'redis'], ['redis', 'super']]), 5);
// 'redishonoured' (only once)