String and Array Helpers for JavaScript

News

December 2nd, 2019

grafite-string-helpers.png

Grafite Helpers is a collection of JavaScript string and array helpers for Laravel developers by Matt Lantz. These helpers are similar to the PHP helpers Laravel provides; however if you’re primarily a frontend developer, I still think you’ll appreciate them.

Here’s a few examples of the string helpers in action:

1"This is my name".explode()
2// ["This", "is", "my", "name"]
3
4"This is my name".after("This is")
5// ' my name'
6
7"This is my name".beforeLast("my name");
8// 'This is '
9
10"I love watching movies".slug();
11// "i-love-watching-movies"

And here’s a few array helper examples:

1["Nissan", "BMW", "Ferrari"].implode();
2// "Nissan BMW Ferrari"
3
4["Nissan", "BMW", "Ferrari"].first();
5// "Nissan"
6
7["Nissan", "BMW", "Ferrari"].last();
8// "Ferrari"
9
10["Nissan", "BMW", "Ferrari"].remove("BMW");
11// ["Nissan", "Ferrari"]

This package is available as @grafite/helpers in the NPM registry, and you can install it in your project with the following:

1npm install @grafite/helpers

You can then import it in your project:

1import '@grafite/helpers'

Check out the Helpers documentation for details of all the supported helpers. You can view the source code on GitHub at GrafiteInc/Helpers.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.