Skip to content
Myr

Improve bruteforce UI

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Andrey Sitnik · committed by Andrey Sitnik · parent 8ebe396 · Browse files · 1 file+12 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+12 added−11 removed

  • tests:+12 added−11 removed

1 file+12 added−11 removed

modified:test/bruteforce+12 added-11 removed
1#!/usr/bin/env node23var fs = require('fs')3var spawnSync = require('child_process').spawnSync4var chalk = require('chalk')5var fs = require('fs')67var filePath = process.argv[2]7var bestResult = {8var best = {9 value: '',10 size: Infinity11}11var lastString = ''12var lastString1314function shuffle (a) {15 var j, x, i16 for (i = a.length - 1; i > 0; i--) {
25 unmodified lines
4243function checkSize () {44 var output = spawnSync('npx', ['size-limit', filePath]).output45 var size = output.toString('utf8').match(/Package size: ([0-9]+)/)45 if (size && size[1] !== 0 && size[1] < bestResult.size) {46 bestResult.value = lastString47 bestResult.size = size[1]4849 console.log(50 'New best string has been founded: ' + bestResult.value +51 ' | size: ' + bestResult.size52 )46 if (size && size[1] !== 0 && size[1] < best.size) {47 best.value = lastString48 best.size = size[1]49 process.stdout.write(chalk.green.bold(best.size) + 'B ' + best.value + '\n')50 }51}5253saveFirstString()54if (typeof lastString === 'undefined') {55 process.stderr.write(chalk.red('Alphabet was not found') + '\n')56 process.exit(1)57}58checkSize()5960while (true) {61 shuffleStringInFile()
2 unmodified lines