From 077bb4a8d502119ec1373b9b8f46dfe547ed210c Mon Sep 17 00:00:00 2001 From: sogoagain Date: Sat, 15 Jan 2022 20:24:43 +0900 Subject: [PATCH] rename option parameter 'charactersToUseWhenScrambling' to 'characters' (https://github.com/sogoagain/scrambling-text-js/issues/3) --- README.md | 2 +- examples/index.html | 2 +- examples/scrambling-text.js | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/Scrambler.js | 16 ++++++++-------- src/Scrambler.test.js | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4441410..616e781 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/examples/index.html b/examples/index.html index 9006190..28c7ab2 100644 --- a/examples/index.html +++ b/examples/index.html @@ -43,7 +43,7 @@

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); diff --git a/examples/scrambling-text.js b/examples/scrambling-text.js index 966aabd..1f4fd0c 100644 --- a/examples/scrambling-text.js +++ b/examples/scrambling-text.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Scrambler=t():e.Scrambler=t()}(self,(function(){return(()=>{"use strict";var e={d:(t,r)=>{for(var s in r)e.o(r,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:r[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>s});class r{static get CHARACTERS(){return{DEFAULT:["@","#","$","%","£","&","*","§","+","_"],ALPHABET:["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]}}constructor(){this.charactersToUseWhenScrambling=[...r.CHARACTERS.DEFAULT],this.maxCounter=12,this.targetText="",this.scrambledText="",this.encodingCounters=[],this.decodingCounters=[],this.onScramble=null,this.frameId=null,this.frameIndex=0}scramble(e,t,s=null){this.charactersToUseWhenScrambling=s?.charactersToUseWhenScrambling?[...s.charactersToUseWhenScrambling]:[...r.CHARACTERS.DEFAULT],this.targetText=e,this.encodingCounters=this._generateCounters(this.scrambledText),this.decodingCounters=this._generateCounters(this.targetText),this.onScramble=t,this.frameId=null,this.frameIndex=0,this.frameId=requestAnimationFrame((()=>this._encode()))}_randomText(e){let t="";for(let r=0;rMath.floor(Math.random()*this.maxCounter)+1))}_encode(){if(0===this.frameIndex){if(0===this.encodingCounters.reduce(((e,t)=>e+t),0))return void(this.frameId=requestAnimationFrame((()=>this._fill())));for(let e=0;ethis._encode()))}_fill(){if(0===this.frameIndex){if(this.scrambledText.length===this.targetText.length)return void(this.frameId=requestAnimationFrame((()=>this._decode())));const e=this.scrambledText.lengththis._fill()))}_decode(){if(this.scrambledText===this.targetText)cancelAnimationFrame(this.frameId);else{if(0===this.frameIndex){let e="";for(let t=0;tthis._decode()))}}}const s=r;return t.default})()})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Scrambler=t():e.Scrambler=t()}(self,(function(){return(()=>{"use strict";var e={d:(t,r)=>{for(var s in r)e.o(r,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:r[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>s});class r{static get CHARACTERS(){return{DEFAULT:["@","#","$","%","£","&","*","§","+","_"],ALPHABET:["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]}}constructor(){this.characters=[...r.CHARACTERS.DEFAULT],this.maxCounter=12,this.targetText="",this.scrambledText="",this.encodingCounters=[],this.decodingCounters=[],this.onScramble=null,this.frameId=null,this.frameIndex=0}scramble(e,t,s=null){this.characters=s?.characters?[...s.characters]:[...r.CHARACTERS.DEFAULT],this.targetText=e,this.encodingCounters=this._generateCounters(this.scrambledText),this.decodingCounters=this._generateCounters(this.targetText),this.onScramble=t,this.frameId=null,this.frameIndex=0,this.frameId=requestAnimationFrame((()=>this._encode()))}_randomText(e){let t="";for(let r=0;rMath.floor(Math.random()*this.maxCounter)+1))}_encode(){if(0===this.frameIndex){if(0===this.encodingCounters.reduce(((e,t)=>e+t),0))return void(this.frameId=requestAnimationFrame((()=>this._fill())));for(let e=0;ethis._encode()))}_fill(){if(0===this.frameIndex){if(this.scrambledText.length===this.targetText.length)return void(this.frameId=requestAnimationFrame((()=>this._decode())));const e=this.scrambledText.lengththis._fill()))}_decode(){if(this.scrambledText===this.targetText)cancelAnimationFrame(this.frameId);else{if(0===this.frameIndex){let e="";for(let t=0;tthis._decode()))}}}const s=r;return t.default})()})); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index fd032eb..9c64e1f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "scrambling-text", - "version": "1.1.0", + "version": "1.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "scrambling-text", - "version": "1.1.0", + "version": "1.2.0", "license": "MIT", "dependencies": { "@babel/polyfill": "^7.10.4" diff --git a/package.json b/package.json index b92e7a9..2245cfc 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/Scrambler.js b/src/Scrambler.js index 6b6afcd..294ebd9 100644 --- a/src/Scrambler.js +++ b/src/Scrambler.js @@ -7,7 +7,7 @@ export default class Scrambler { } constructor() { - this.charactersToUseWhenScrambling = [...Scrambler.CHARACTERS.DEFAULT]; + this.characters = [...Scrambler.CHARACTERS.DEFAULT]; this.maxCounter = 12; this.targetText = ''; @@ -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); @@ -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; @@ -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; } diff --git a/src/Scrambler.test.js b/src/Scrambler.test.js index ebc3895..63be78d 100644 --- a/src/Scrambler.test.js +++ b/src/Scrambler.test.js @@ -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); });