From 5cd69bb264f9de10ceab4e1dd5fe246e2a4aacb5 Mon Sep 17 00:00:00 2001 From: Olavo Neto Date: Sat, 4 Mar 2017 10:09:50 -0400 Subject: [PATCH] fix: Option usedefaults re-assign ```js var options = { reverse: true, usedefaults: false } var formatter = new StringMask('+00 (00) 0000-0000') ``` Old code; ```js usedefaults: this.options.usedefaults || this.options.reverse ``` OR operator (||) return false on left side and return true on right side. OR for defaults can be convenient because it is short and easy to write but to booleans parameters it was not good. --- src/string-mask.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/string-mask.js b/src/string-mask.js index a64d7c9..b8a8083 100644 --- a/src/string-mask.js +++ b/src/string-mask.js @@ -78,10 +78,15 @@ function StringMask(pattern, opt) { this.options = opt || {}; - this.options = { - reverse: this.options.reverse || false, - usedefaults: this.options.usedefaults || this.options.reverse - }; + + if (typeof this.options.reverse === 'undefined') { + this.options.reverse = false; + } + + if (typeof this.options.usedefaults === 'undefined') { + this.options.usedefaults = this.options.reverse; + } + this.pattern = pattern; }