@noeldemartin/utils v0.7.1
JavaScript Utilities 
These are some JavaScript utilities I use in different projects. If you want to use them as well, you're most welcome. You can install the package with:
npm install @noeldemartin/utilsHelpers
There is a bunch of helpers I've been reusing across projects, and I wanted to get them in one place to abide by the DRY principle (Don't Repeat Yourself). They consist of simple operations such as converting a string to camelCase, checking if an element exists within an array, etc.
The best way to check these out is by looking at the test files within the src/helpers/ folder.
Fluent API
I strive to make readable code, and I wasn't happy with combining my own helpers with built-in methods. There is nothing in the fluent API that's not implemented in some helper, this is all about readability.
For example, this is the kind of code I'd write often:
const items = ['my', 'array', 'of', 'items'];
return arrayContains(items.filter(item => item.startsWith('a')), 'array');Where arrayContains is a custom helper (which you can find in this package), and Array.filter is a native method. My only option was to combine method chaining with nesting function calls. And the end result wasn't too readable.
Now, with the fluent API I created in this package, I can write it like this:
return fluent(['my', 'array', 'of', 'items']) // or, to be explicit, arr([...])
.filter(item => item.startsWith('a'))
.contains('array'); // returns trueLike this, I'm able to combine native methods with custom helpers using method chaining.
And that's not only with arrays, for example with strings I can do:
return fluent('foo-bar') // or, to be explicit, str('...')
.replace('foo', 'hello')
.replace('bar', 'world')
.toStudlyCase()
.toString(); // returns "HelloWorld"I also included my own port of Laravel's tap helper. This allows me to rewrite this kind of code:
const foo = new Foo();
foo.bar = 'bar';
return foo;Like this:
return tap(new Foo(), foo => {
foo.bar = 'bar';
});And all of this works properly with TypeScript! So when I create a variable with fluent('foo'), I get auto-completion for both my custom helpers and native methods - along the complete method chain!
11 months ago
10 months ago
10 months ago
10 months ago
11 months ago
10 months ago
11 months ago
8 months ago
10 months ago
12 months ago
10 months ago
10 months ago
10 months ago
11 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
11 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
1 year ago
2 years ago
2 years ago
3 years ago
3 years ago
4 years ago
4 years ago
5 years ago