Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
A flexible and easy-to-use text garbler, written in pure JS.
npm:
npm install waizatsu
// yourscript.js
const Waizatsu = require("waizatsu");
The following is the most simple use of Waizatsu:
const garbler = new Waizatsu("Hello World!");
console.log(garbler.value);
=> 'aMejW lSKwn@'
new Waizatsu(base [, options]);
base
String value that represents the original (base) value that will be garbled.
options
An options object that contains values that determine how Waizatsu operates. The possible options are:
caseSensitive
Boolean that signals whether to maintain the base
string's case when garbling. Defaults to false
.
characterSet
String value or Array that determines which characters to use when garbling. Defaults to 'alphabet'
.
If a string value is given, the correspoding character set will be used. For example, 'alphabet'
will use the ALPHABET character set, etc.
If an array is given, the corresponding character set at each index will be combined. For example, ['alphabet', 'numbers', 'symbols']
will use all three sets when garbling.
customCharacterSet
Array that provides a custom set of characters that can be used when garbling. To use a custom character set, characterSet
must also be set to or include 'custom'
. Defaults to []
(An empty array).
refreshEvery
Integer value that determines how often the interval used by the repetear method should tick. Defaults to 50
.
The Waizatsu.garble()
method takes the base
string and generates a string of random characters of the same length.
The way in which a string is garbled relies on two things:
When a string is garbled, each character within it will be replaced with a randomly selected character from a given set. The set used is determined by the characterSet
option. If this option is not present, the character set is defaulted to 'alphabet'
.
A custom set of characters can be provided by the customCharacterSet
option and can be selected by giving 'custom'
as the value for the characterSet
option.
let example = new Waizatsu("Hello World!", {
characterSet: 'custom',
customCharacterSet: ['A', 'c', '2', '91', '@', '}']
});
Waizatsu supports automatic detection of character types to replace characters with one of the same type. To use this feature, give 'auto'
as the value for the characterSet
option.
While this feature works great for whitespace, numbers, letters and symbols, it is severly limited when it comes to CJK and non-English characters. Better support for these character sets is planned but, unfortunately, is not of the highest priority.
If an array is given as the value for the characterSet
option, the referenced sets will be combined and used together as a single set.
If
'auto'
is included in the array of sets to combine, all other values will be ignored and the automatic character type detection feature will be used instead.
let example = new Waizatsu("Hello World!", {
characterSet: ['alphabet', 'numbers', 'symbols']
});
// Example of a garbled string using these combined sets
example.value => '7*Dn: k8Bn@f'
If desired, Waizatsu can maintain a character's case when generating a random new random character. To use this feature, give true
as the value for the caseSensitive
option.
Waizatsu.garble([returnValue] [, returnAs]);
returnValue
Boolean that signals whether to return the garbled value once it has been set to Waizatsu.value
. Defaults to false
. If no other parameters are provided, the garbled value will be return as a string by default.
returnAs
String value that determines what type to return the garbled value as. Defaults to 'string'
.
This parameter only supports 'string'
and 'array'
. The 'array'
value returns the garbled value split into an array.
Waizatsu emits events during operation that can be listened to via the Waizatsu.on()
method.
Waizatsu.on(event, callback);
event
String value that references the event that the callback
should be fired on. Possible values:
'garble'
- Emitted by the Waizatsu.garble()
method once the Waizatsu.value
property has been assigned the newly garbled string.'repeaterStart'
- Emitted by the Waizatsu.startRepeater()
method once the repeater interval has started.'repeaterStop'
- Emitted by the Waizatsu.stopRepeater()
method once the repeater interval has stopped.'transitionBegin'
- Emitted by the Waizatsu.repeater.transition()
method, which is called by the Waizatsu.stopRepeater()
method, once the garbled string begins to transition back to its base value.'transitionEnd'
- Emitted by the Waizatsu.repeater.transition()
method, which is called by the Waizatsu.stopRepeater()
method, once the garbled string finishes transitioning back to its base value.callback
Function that will be called once the event
is emitted.
// Create a new Waizatsu object
let example = new Waizatsu("Hello World!");
// Listen to the 'garble' event
example.on('garble', () => {
console.log('Garbled!');
});
// Call the `Waizatsu.garble()` method to trigger the event
example.garble();
// Console Output:
'Garbled!';
The Repeater feature is a built-in interval that (surprise) repeatedly garbles the text. This feature is functionally the same as creating an interval that calls the Waizatsu.garble()
method but supports the aforementioned events and a nice transition back to the string's base value once stopped.
To start the Repeater, call the Waizatsu.startRepeater()
method. This sets an interval that garbles the text every x milliseconds. The rate at which the interval executes is determined by the refreshEvery
option. If this option is not present, the rate is defaulted to 50
.
Once the interval is set, the repeaterStart
event is emitted.
If
Waizatsu.startRepeater()
is called while the Repeater is already active, the interval will be cleared and then set again. This clearing of the interval WILL NOT trigger thestopRepeater
event nor begin the transition to the base string.
// Create a new Waizatsu object with the refreshEvery option
let example = new Waizatsu("Hello World!", { refreshEvery: 35 });
// Start the Repeater
example.startRepeater();
To stop the Repeater, call the Waizatsu.stopRepeater()
method. This clears the interval that's set by the Waizatsu.startRepeater()
method and transitions the garbled value back to the base value provided when the object was initialised. If you wish to retain the garbled value, see the transition
parameter.
Once the interval has been cleared, the repeaterStop
event is emitted.
If
Waizatsu.stopRepeater()
is called while the Repeater is not active, it will return false.
transition
Boolean value that determines whether to transition the text back to its base
value once the interval has been cleared. Defaults to true
.
// Create a new Waizatsu object with options
let example = new Waizatsu("Hello World!", { refreshEvery: 35 });
// Start the Repeater
example.startRepeater();
// Stop the Repeater
example.stopRepeater();
base
When the Repeater is stopped, the object's value
will begin to transition back to the base
value that was given when the object was intiailised, one character at a time. In conjunction with the garble
event, this provides a smooth transition between the two and acts as a sort of reveal.
Once the transition begins, the transitionBegin
event is emitted. Once it completes, the transitionEnd
event is emitted.
This transition can be triggered independently via the Waizatsu.transition()
alias.
// Create a new Waizatsu object
let example = new Waizatsu("Hello World!");
// Log the object's value to see that it's garbled
console.log(example.value);
// Transition back to the `base` value
example.transition();
// Log the object's value again to see that's transitioned
console.log(example.value);
// Console Output:
'ld82N 9Und2&'
'Hello World!'
Due to its nature, the above example shows how to use the Waizatsu.transition()
method but not the effect it creates. To see this method in action, see this page.
So, what can we do with Waizatsu? All it does is garble text, right? Maybe so but you can implement it into your apps in interesting ways.
As soon as I think of some, I'll link them here
FAQs
Flexible and easy-to-use text garbler
The npm package waizatsu receives a total of 1 weekly downloads. As such, waizatsu popularity was classified as not popular.
We found that waizatsu demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.