Skip to content

Commit

Permalink
Merge pull request #4 from sogoagain/issue3_rename
Browse files Browse the repository at this point in the history
rename option parameter 'charactersToUseWhenScrambling' to 'characters'
  • Loading branch information
sogoagain authored Jan 15, 2022
2 parents 57b8928 + 077bb4a commit c25908a
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ scrambler.scramble('- Friedrich Nietzsche -', handleScramble);

// call scramble with the option to set the characters to use when scrambled.
scrambler.scramble(text, handleScramble, {
charactersToUseWhenScrambling: ['a', 'b', 'c'],
characters: ['a', 'b', 'c'],
});

// Scrambler provides several characters.
Expand Down
2 changes: 1 addition & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h1 id="text"></h1>
const targetText = TEXTS[i % TEXTS.length];
if (i == 2) {
scrambler.scramble(targetText, handleScramble, {
charactersToUseWhenScrambling: Scrambler.CHARACTERS.ALPHABET,
characters: Scrambler.CHARACTERS.ALPHABET,
});
} else {
scrambler.scramble(targetText, handleScramble);
Expand Down
2 changes: 1 addition & 1 deletion examples/scrambling-text.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scrambling-text",
"version": "1.1.0",
"version": "1.2.0",
"description": "A very simple JavaScript library written in vanilla js for scrambling text.",
"main": "dist/scrambling-text.js",
"scripts": {
Expand Down
16 changes: 8 additions & 8 deletions src/Scrambler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class Scrambler {
}

constructor() {
this.charactersToUseWhenScrambling = [...Scrambler.CHARACTERS.DEFAULT];
this.characters = [...Scrambler.CHARACTERS.DEFAULT];
this.maxCounter = 12;

this.targetText = '';
Expand All @@ -21,10 +21,10 @@ export default class Scrambler {
}

scramble(text, onScramble, option = null) {
if (option?.charactersToUseWhenScrambling) {
this.charactersToUseWhenScrambling = [...option.charactersToUseWhenScrambling];
if (option?.characters) {
this.characters = [...option.characters];
} else {
this.charactersToUseWhenScrambling = [...Scrambler.CHARACTERS.DEFAULT];
this.characters = [...Scrambler.CHARACTERS.DEFAULT];
}
this.targetText = text;
this.encodingCounters = this._generateCounters(this.scrambledText);
Expand All @@ -40,8 +40,8 @@ export default class Scrambler {
_randomText(length) {
let text = '';
for (let i = 0; i < length; i += 1) {
text += this.charactersToUseWhenScrambling[
Math.floor(Math.random() * this.charactersToUseWhenScrambling.length)
text += this.characters[
Math.floor(Math.random() * this.characters.length)
];
}
return text;
Expand Down Expand Up @@ -108,8 +108,8 @@ export default class Scrambler {
decodingText += this.targetText[i];
continue;
}
decodingText += this.charactersToUseWhenScrambling[Math.floor(
Math.random() * this.charactersToUseWhenScrambling.length,
decodingText += this.characters[Math.floor(
Math.random() * this.characters.length,
)];
this.decodingCounters[i] -= 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Scrambler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Scrambler', () => {

texts.forEach((text) => {
scrambler.scramble(text, handleScramble, {
charactersToUseWhenScrambling: ['a', 'b', 'c'],
characters: ['a', 'b', 'c'],
});
expect(handleScramble).toHaveBeenLastCalledWith(text);
});
Expand Down

0 comments on commit c25908a

Please sign in to comment.