Introduction

Despite the fact that javascript is an excellent programming language, it sometimes suffers from a lack of functionalities. Unlike others programming language, it doesn’t have a native string replacer and that’s why I’ve written the @rimiti/stimmy (Github) package and this article.

 

Why @rimiti/stimmy?

Used in many production packages, it have been written to be safe and fully customizable.

Benefits:

  • Very light (8kb)
  • Can replace string variables from an object.
  • Can replace string variables from an array.
  • Pattern customizable.
  • Doesn’t have dependencies.
  • 100% of code coverage

 

How to use it?

Stimmy is CommonJS and ES6 compliant, in this case you can import or require it without .default. 

Like all NodeJS packages, you need to import it before using it.

After that, you just have to instantiate it:

Stimmy provides two ways for replacing your variables.

From an array:

From object:

 

Ok, but how to customize the replacement pattern?

In case you want to change the default pattern, you just have to pass it as parameter when you assign the replacer, example:

From an array:

From object:

 

If you want more examples or snippets, you can check the official repository.

 

Leave a comment