map replace prefix - nodef/extra-string GitHub Wiki

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)

extra-string

⚠️ **GitHub.com Fallback** ⚠️