Skip to content

Commit

Permalink
Deprecate replace method parameters
Browse files Browse the repository at this point in the history
Allow for deprecation notice for the old call for now, so it
does not break behavior.
  • Loading branch information
mooeypoo committed May 4, 2021
1 parent 64109e6 commit 7a66140
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Expand Up @@ -5,8 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Deprecated
- Deprecate using `baseUrl` and `useBothWays` as individual parameters in `DomWordReplacer.replace()` method. Use `options` object instead.

### Changed
- BREAKING: Replace `.replace(...)` method parameters with an `options` config object
- Replace `.replace(...)` method parameters with an `options` config object

### Added
- Add 'suggestionMode' config option
Expand Down
13 changes: 12 additions & 1 deletion src/DomWordReplacer.js
Expand Up @@ -35,9 +35,20 @@ class DomWordReplacer {
* @param {boolean} [options.replaceBothWays] If set to true, the
* replacement will happen twice -- once for the keyFrom,
* and once for the keyTo, producing a two-way translation.
* @param {boolean} deprecatedReplaceBothWays DEPRECATED as parameter
* @return {string} New html content
*/
replace(htmlString, dictKeyFrom, dictKeyTo, options = {}) {
replace(htmlString, dictKeyFrom, dictKeyTo, options = {}, deprecatedReplaceBothWays = false) {
// DEPRECATE using baseUrl and replaceBothWays as individual parameters
// Deprecated @ v0.9.9
if (options && typeof options !== 'object') {
console.warn('`DomWordReplaceer.replace`: The parameters baseUrl and replaceBothWays are deprecated. Use `options` object instead.');
options = {
baseUrl: options,
replaceBothWays: deprecatedReplaceBothWays
};
}

return this.manager.replace(
htmlString,
dictKeyFrom,
Expand Down

0 comments on commit 7a66140

Please sign in to comment.