Giter Club home page Giter Club logo

support's Introduction

@kernel-js/support

Build Status Coverage Status

Util functions and classes

  • Expose some Lodash functions
  • Exports additional helpers

Inspirations

The main inspiration on my work is PHP Laravel Framework which I love because of its simplicity and beauty of code.

Why

First of all I created this to support development of Kernel Framework.
Just like the rest of the packages that make up the framework, I make the most of other existing libraries that are well tested on a day-to-day basis. The idea is not to reinvent the wheel, just join the ideas in a lightweight framework (the focus is on the client side), simple to use and make the code on the front more beautiful and organized.

Install

npm install @kernel-js/support

Helpers

Custom

Lodash

  • camelCase
  • capitalize
  • find
  • floor
  • get
  • has
  • hasIn
  • head
  • keysIn
  • last
  • set
  • snakeCase
  • startCase
  • map
  • mapValues
  • omitBy
  • unset

env

Gets the value of an environment variable.

env(key, [defaultValue])

Arguments

  • key - the path to the property you want. You can use dot notation on nested objects
  • defaultValue - the optional default value when the key was not found
// Examples
env('NODE_ENV');
env('app.name');
env('app.name', 'My Default App Name');

isArray

Return a boolean if the informed value is of Array type.

isArray(value)

Arguments

  • value - any value
// Example
isArray([]); // True
isArray({}); // False
isArray(''); // False

isObject

Return a boolean if the informed value is of Object type.

isObject(value)

Arguments

  • value - any value
// Example
isObject({}); // True
isObject([]); // False
isObject(''); // False

isEmpty

Check if the informed value is empty. This is a little different of lodash behaviour,
booleans are not considered empty and ' ' for example is considered empty.

isEmpty(value)

Arguments

  • value - any value
// Examples
isEmpty(true); // false
isEmpty(null); // true
isEmpty(undefined); // true
isEmpty(' '); // true
isEmpty({}); // true
isEmpty([]); // true

isNotEmpty

Just the oposite of isEmpty.

isNotEmpty(value)

Arguments

  • value - any value
// Examples
isNotEmpty(true); // true
isNotEmpty(null); // false
isNotEmpty(undefined); // false
isNotEmpty(' '); // false
isNotEmpty({}); // false
isNotEmpty([]); // false

toBoolean

Converts a give string or number into boolean or return null when cannot convert it.

toBoolean(value)

Arguments

  • value - any value
// Examples
toBoolean(1); // true
toBoolean('true'); // true
toBoolean('yes'); // true
toBoolean('on'); // true
toBoolean(0); // false
toBoolean('false'); // false
toBoolean('no'); // false
toBoolean('off'); // false
toBoolean('lorem ipsum'); // null

removeEmpty

Removes any empty property from object using isEmpty helper.

removeEmpty(value)

Arguments

  • value - any object
// Example
removeEmpty({"a": " ", "b": "b value", "c": null}); // {"b": "b value"}

mapEmptyToNull

Converts any empty property of object to null using isEmpty helper.

mapEmptyToNull(value)

Arguments

  • value - any object
// Example
mapEmptyToNull({"a": " ", "b": "b value", "c": null, "d": {}}); // {"a": null, "b": "b value", "c": null, "d": null}

Authors

This library was developed by Gustavo Siqueira, Bruno Santos e Carlos Escouto

Contribute

Please do! Check out our Contributing guidelines.

License

MIT © 2018-2018 Brid-IT

support's People

Contributors

brunovendedoor avatar carlosescouto avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.