From 8d66cd0b9e4e49d6b3c1a97e5ce7c50407d569d5 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 22 Dec 2023 16:25:49 +0100 Subject: [PATCH] refactor to avoid var renames --- index.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 0350c76..116ee95 100644 --- a/index.js +++ b/index.js @@ -223,32 +223,29 @@ function diff(a, b) { return a - b; } -function formatPart(part, v) { - const ip = normalize(stringifyIp({ - number: BigInt(part.start.toString()), - version: v, - })); +function formatPart(part, version) { + const ip = normalize(stringifyIp({number: BigInt(part.start.toString()), version})); const zeroes = diff(part.end, part.start).toString(2); - const prefix = bits[v] - (zeroes.match(/0/g) || []).length; + const prefix = bits[version] - (zeroes.match(/0/g) || []).length; return `${ip}/${prefix}`; } function mapNets(nets) { const maps = {4: {}, 6: {}}; - for (const {start, end, version: v} of nets) { - if (!maps[v][start]) maps[v][start] = {}; - if (!maps[v][end]) maps[v][end] = {}; + for (const {start, end, version} of nets) { + if (!maps[version][start]) maps[version][start] = {}; + if (!maps[version][end]) maps[version][end] = {}; - if (maps[v][start].start) { - maps[v][start].start += 1; + if (maps[version][start].start) { + maps[version][start].start += 1; } else { - maps[v][start].start = 1; + maps[version][start].start = 1; } - if (maps[v][end].end) { - maps[v][end].end += 1; + if (maps[version][end].end) { + maps[version][end].end += 1; } else { - maps[v][end].end = 1; + maps[version][end].end = 1; } } return maps;