Introducing Replacer.js

Reading time ~2 minutes

For those of you who don’t know me: I’m a huge Shakespeare geek. I love performing, reading, and teaching Shakespeare. I especially love his First Folio, the earliest surviving publications of his work. The problem? Weird typography. At the time it wasn’t unusual to switch v’s and u’s and i’s and j’s around willy nilly, because letters were expensive, and those basically loow the same, right? So already goofy 16th century spellings gets get goofier with words like “vnto”, “ioyner”, and “beleeue.” In the past I’ve spent hours with a cobbled together workflow using spellchecks and find/replacers to try and fix the problem.

But now I know how to code.

So say hello to Replacer.js. Replacer is a Node.js command line tool designed to execute persistent find/replace commands narrowed by misspellings. In other words, it looks for mispelled words with certain characters, prompts you for a replacement, and remembers that replacement for next time. It allows me to do hours worth of First Folio processing in minutes, and is (almost) modular enough that you can easily customize it for similar projects of your own.

Currently just a 0.1 release, expect a few more updates from me in the near future to flesh out some features before I leave it for others to play with if they so desire. Complete instructions are in the github readme, but here are the highlights:

Installing

First thing to do is to install Node.js and npm. If you don’t know how to do that, you’ll find great instructions here. You’ll also want to go to Replacer.js’s github page and download a zip of the files. Afterwards, open up your command line, navigate over to Replacer’s directory and type:

npm install

Npm will automatically install Replacer.js’s dependencies (readline-sync and spellchecker, if your curious), and you are ready to run it.

Usage

By default Replacer.js will read and change text from the target.txt file provided, and save changed and ignored words to the cipher.json and ignore.json files in the words/ directory. To run replacer with these defaults, simply type into your command line:

node replacer

You can also specify other text files, as many as you like, by typing their relative paths as arguments in the command line, like this:

node replacer macbeth.txt midsummer/act1.txt

In future versions you will also be able to specify different JSON files.

Shortcuts

When running, Replacer will prompt you with any misspelled word containing a ‘u’, ‘v’, ‘j’, or ‘i’ that it hasn’t seen before. That character list is currently hard-coded in, but will soon be easily customizable through another JSON file. When prompted, you can simply ignore the word by pressing enter, type in a new spelling, or use shortcuts to make quick switches. For example, consider the following possible prompts and user responses:

thinke? 

ioyes? j

reuiu'd? v

successiue? successive

vnproued? *

In the preceding example ‘thinke’ will be unchanged, ‘ioyes’ will become ‘joyes’, ‘reuiu’d’ will become ‘reviv’d’, ‘successiue’ will become ‘successive’, and ‘vnproued’ will become ‘unproved’. And Replacer.js will remember the change, never asking about the same word twice.

That’s it!

I had a lot of fun building this tool, and I look forward to using it fthe next time I teach a class on the bard. I’m not sure anyone else will find it useful, but hopefully it’s modular enough thatnsomeone out there can put it to a new purpose. In the meantime, lookout for a new blogpost from me detailing the process of building your own Node.js tool.

Scraping the Web for Fun and Profit

So you and your team have been talking about your new social web app. Development has been going well, and someone had the bright idea: "...… Continue reading

The How's Why's and WTF's of Mongoose Hooks

Published on January 30, 2016