npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

baffle

v0.3.6

Published

A tiny javascript library for obfuscating and revealing text in DOM elements.

Downloads

790

Readme

baffle.js

A tiny javascript library for obfuscating and revealing text in DOM elements.

camwiegert.github.io/baffle

  • ~1.8kb gzipped :zap:
  • Dependency-free :tada:
  • IE9+ :heavy_check_mark:
// Select elements and start.
let b = baffle('.someSelector').start();

// Do something else.
someAsyncFunction(result => {
    // Change the text and reveal over 1500ms.
    b.text(text => result.text).reveal(1500);
});

Getting Started

Step 0: Install

Download the latest release or install with npm.

npm install --save baffle

Step 1: Reference

If you linked baffle directly in your HTML, you can use window.baffle. If you're using a module bundler, you'll need to import baffle.

// CommonJS
let baffle = require('baffle');

// ES6
import baffle from 'baffle';

Step 2: Initialize

To initialize baffle, all you need to do is call it with some elements. You can pass a NodeList, Node, or CSS selector.

// With a selector.
let b = baffle('.baffle');

// With a NodeList
let b = baffle(document.querySelectorAll('.baffle'));

// With a Node
let b = baffle(document.querySelector('.baffle'));

Step 3: Use It

Once you have a baffle instance, you have access to all of the baffle methods. Usually, you'll want to b.start() and, eventually, b.reveal().

// Start obfuscating...
b.start();

// Or stop obfuscating...
b.stop();

// Obfuscate once...
b.once();

// You can set options after initializing...
b.set({...options});

// Or change the text at any time...
b.text(text => 'Hi Mom!');

// Eventually, you'll want to reveal your text...
b.reveal(1000);

// And they're all chainable...
b.start()
    .set({ speed: 100 })
    .text(text => 'Hi dad!')
    .reveal(1000);

Options

You can set options on baffle during initialization or anytime afterward with baffle.set().

// During initialize
baffle('.baffle', {
    characters: '+#-•=~*',
    speed: 75
});

// Any time with set()
b.set({
    characters: '¯\_(ツ)_/¯',
    speed: 25
});

options.characters

The characters baffle uses to obfuscate your text. It can be a string or an array of characters.

Default: 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz~!@#$%^&*()-+=[]{}|;:,./<>?'

options.exclude

These are the characters that baffle ignores in your text when obfuscating it. You can pass in an array of characters.

Default: [' ']

options.speed

This is the frequency (in milliseconds) at which baffle updates your text when running.

Default: 50

Methods

An instance of baffle has six methods, all of which are chainable.

###baffle.once() Obfuscates each element once, using options.characters.

###baffle.start() Starts obfuscating your elements, updating every options.speed milliseconds.

###baffle.stop() Stops obfuscating your elements. This won't reveal your text. It will only stop updating it. To reveal it, use reveal().

###baffle.reveal([duration], [delay]) Reveals your text over duration milliseconds (default: 0), with the option to delay by delay milliseconds.

###baffle.set([options]) Updates instance options using the passed options object. You can set any number of keys, even while running.

###baffle.text(fn) Updates the text in each element of your instance using function fn, which receives the current text as it's only parameter. The value returned from fn will be used as the new text.