Some JS syntax-sugar for heavily used expressions

Usage no npm install needed!

<script type="module">
  import jsCandy from 'https://cdn.skypack.dev/js-candy';



Some JS syntax-sugar for heavily used expressions


The method checks if the variable has a value, essentialy for you to don't use them without it on critical parts, make a cleaner and readable code or/and don't pass a null parameter were it simply doesn't need to be.


Shortcut for:

    variable ? variable : null


Here's the gold. The method checks if each one of the values exists and returns to you an object with only the values that exists


    var objectThatIWant = exists(receivedObject);

Also, it makes simpler to use the {...object} ES syntax without having to worry about "falsey" values.

PS: Boolean 'false' values are kept, as they are, in the object (As they are intended to be there).


Capitalize the first letter of the string.

The allFirsts parameter

Use the allFirsts parameter if you want to capitalize all the letters after a blank space.


    capitalFirst("my string", true); //My String
    capitalFirst("my other string", false); //My other string
    capitalFirst("another string"); //Another string

Importing to your code

    // require module:
    var capitalFirst = require("js-candy/capital-first");
    var exists = require("js-candy/if-exists");
    // or with ES6 import
    import capitalFirst from 'js-candy/capital-first';
    import exists from 'js-candy/if-exists';