Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed var variables to let/const #217

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 8 additions & 6 deletions src/sprintf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
!function() {
'use strict'

var re = {
const re = {
not_string: /[^s]/,
not_bool: /[^t]/,
not_type: /[^T]/,
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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])
Expand All @@ -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)) !== '') {
Expand Down