Easy String Manipulation with Voca JS

So far in my experience using Javascript, I’ve encountered a lot of situations where I needed to manipulate strings. Whether that be inserting new words, creating a slug for URL, or stripping HTML tags, it’s almost always harder than it seems like it should be.

I wanted to find an easier way to solve some of these problems which led me to find Voca JS, a javascript library made specifically for string manipulation. The documentation for Voca can be found here. For my blog this week, I wanted to walk through some of the methods that I found useful.

You can install the Voca library in your local modules directory using npm by running “npm install voca” and then require it in your file by setting it equal to a variable like this.

Once the package is installed, you have access to a bunch of helpful methods. Here are 3 methods that I noticed while looking through the documentation that seem useful.


Normally if we were to change a string in javascript to be used as a URL slug, we would have to write a function to remove special characters and replace spaces with ‘ — ‘ which might look something like this.

However with Voca all we need to do is this:


Another useful method in the Voca library lets you count the number of times a substring appears in a string object. So if we take a look at this quote from Deion Sanders, we can see how many times he said the word ‘good’


When I was looking around the internet for different ways to strip HTML tags from a string using javascript, I found a variety of different methods but some were very tedious and none were as easy as the Voca method stripTags.

The method also gives you the option to remove all of the tags, or only strip certain tags and keep others.

These are just a few of the methods provided by Voca JS, but I encourage you to go and check out the documentation to see some of the other easy string manipulation methods that it provides!

Download Chrome Extension or visit https://moon.ly