Skip to content

Commit

Permalink
remove unused util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Oct 31, 2023
1 parent 3a96ae6 commit 29362f3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 69 deletions.
34 changes: 0 additions & 34 deletions src/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,38 +328,4 @@ describe('Util', () => {
]);
});
});

describe('generateLoadingText', () => {
it('generates properly', () => {
const spin = util.createTextSpinner(3, '-', '*');
expect(spin()).to.eql('--*');
expect(spin()).to.eql('-*-');
expect(spin()).to.eql('*--');
expect(spin()).to.eql('--*');
expect(spin()).to.eql('-*-');
expect(spin()).to.eql('*--');
});

it('returns same value when passed false', () => {
const spin = util.createTextSpinner(3, '-', '*');
expect(spin()).to.eql('--*');
expect(spin(false)).to.eql('--*');

expect(spin()).to.eql('-*-');
expect(spin(false)).to.eql('-*-');

expect(spin()).to.eql('*--');
expect(spin(false)).to.eql('*--');

expect(spin()).to.eql('--*');
expect(spin(false)).to.eql('--*');

expect(spin()).to.eql('-*-');
expect(spin(false)).to.eql('-*-');

expect(spin()).to.eql('*--');
expect(spin(false)).to.eql('*--');

});
});
});
35 changes: 0 additions & 35 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,41 +381,6 @@ class Util {
public escapeRegex(text: string) {
return text?.toString().replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}

/**
* Returns a function that generates a string of off+on chars for showing "animated" loading in text-based locations
* @param max the total number of chars to show
* @param offChar the char to show when that index is "off"
* @param onChar the char to show when that index is "on"
* @returns function that generates loading strings
*/
public createTextSpinner(max: number, offChar = '◦', onChar = '•') {
let current = 2;
const fullText = offChar.repeat(max).split('');
/**
* Generate the next text
* @param increment if false, will return the same value as last time
*/
return function spinner(increment = true) {
const text = [...fullText];
if (increment) {
current++;
}
text[current % max] = onChar;
return text.reverse().join('');
};
}

/**
* Set an interval
* @returns a function that can be called to clear the interval
*/
public setInterval(callback: () => any, duration: number) {
const handle = setInterval(callback, duration);
return () => {
clearInterval(handle);
};
}
}

const util = new Util();
Expand Down

0 comments on commit 29362f3

Please sign in to comment.