nm-utils
nm-utils is a library of useful JavaScript functions. Currently, it includes 2 functions:
callFunction
- A safe way to call a function without the need to check that the callback parameter is indeed a function. This function takes care of calling the callback as well as passing any number of parameters you'd like. Additionally, it can also set the context of the callback.
parseBool
- parses string values as boolean. Especially useful parsing incoming parameters (e.g. url parameters which are sent as string).
Usage
Installing
npm install nm-utils
callFunction
example - without setting the context:
{ var utils = ; var { // do some asyn operations here... utils; }; ; };
callFunction
example - including setting the context:
{ var utils = ; { thisname = name; thisemail = email; this { return 'My name is: ' + thisname + ', my email is: ' + thisemail; }; } var { // assuming we got the name and email from an async operation var name = 'John Doe' email = 'john@doe.com' user = name email; utils; }; ; };
parseBool
example:
{ var utils = trueInput = 'true' falseInput = 'false' trueVal = utils falseVal = utils; console; };