Package Exports
- scrambling-text
- scrambling-text/dist/scrambling-text.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (scrambling-text) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Scrambling Text
A very simple JavaScript library written in vanilla js for scrambling text.
Demo PageTable of Contents
Installation
This module is distributed via npm which is bundled with node
npm i scrambling-text
Examples
Basic Example
// load 'scrambling-text' module.
import Scrambler from 'scrambling-text';
// create an instance of Scrambler.
const scrambler = new Scrambler();
// define a handler that is called whenever text is scrambled.
const handleScramble = (text) => {
console.log(text);
}
// call scramble function with the text to be scrambled and handler.
scrambler.scramble('- Friedrich Nietzsche -', handleScramble);
// call scramble with the option to set the characters to use when scrambled.
scrambler.scramble(text, handleScramble, {
characters: ['a', 'b', 'c'],
});
// Scrambler provides several characters.
console.log(Scrambler.CHARACTERS.DEFAULT);
console.log(Scrambler.CHARACTERS.ALPHABET);
React Example
import React, { useRef, useState, useEffect } from 'react';
// load 'scrambling-text' module.
import Scrambler from 'scrambling-text';
export default function ScramblingText() {
// define the text to be scrambled as state.
const [text, setText] = useState('- Friedrich Nietzsche -');
// create an instance of Scrambler using useRef.
const scramblerRef = useRef(new Scrambler());
useEffect(() => {
// call scramble function with the text to be scrambled and handler.
scramblerRef.current.scramble(text, setText);
}, []);
return (
<h1>
{text}
</h1>
);
}