diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index a16608e..71d23d1 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -24,3 +24,4 @@ Raphael Pigulla [@pigulla](https://github.com/pigulla) rebeccapeltz [@rebeccapeltz](https://github.com/rebeccapeltz) Stefan Tingström [@stingstrom](https://github.com/stingstrom) Tim Gates [@timgates42](https://github.com/timgates42) +Maor Shlomo [@Maorshl](https://github.com/Maorshl) diff --git a/src/sprintf.js b/src/sprintf.js index 65d6324..c8050e4 100644 --- a/src/sprintf.js +++ b/src/sprintf.js @@ -3,7 +3,7 @@ !function() { 'use strict' - var re = { + const re = { not_string: /[^s]/, not_bool: /[^t]/, not_type: /[^T]/, @@ -31,7 +31,8 @@ } function sprintf_format(parse_tree, argv) { - var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign + const tree_length = parse_tree.length + let cursor = 1, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign for (i = 0; i < tree_length; i++) { if (typeof parse_tree[i] === 'string') { output += parse_tree[i] @@ -139,14 +140,14 @@ return output } - var sprintf_cache = Object.create(null) + let sprintf_cache = Object.create(null) function sprintf_parse(fmt) { if (sprintf_cache[fmt]) { return sprintf_cache[fmt] } - - var _fmt = fmt, match, parse_tree = [], arg_names = 0 + const parse_tree = [] + let _fmt = fmt, match, arg_names = 0 while (_fmt) { if ((match = re.text.exec(_fmt)) !== null) { parse_tree.push(match[0]) @@ -157,7 +158,8 @@ else if ((match = re.placeholder.exec(_fmt)) !== null) { if (match[2]) { arg_names |= 1 - var field_list = [], replacement_field = match[2], field_match = [] + const field_list = [] + let replacement_field = match[2], field_match = [] if ((field_match = re.key.exec(replacement_field)) !== null) { field_list.push(field_match[1]) while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {