This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
In this example I show how avoid to use assert in nodejs to validate if the parameter is defined. | |
*/ | |
//Star from here. | |
const assert = require('assert'); | |
//Using with assert | |
const sum3 = (a,b,c)=>{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getTimeZone = ()=>{ | |
let timezone_offset_min = new Date().getTimezoneOffset(), | |
offset_hrs = parseInt(Math.abs(timezone_offset_min/60)), | |
offset_min = Math.abs(timezone_offset_min%60), | |
timezone_standard; | |
if(offset_hrs < 10) | |
offset_hrs = '0' + offset_hrs; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Include joi module schema validator. | |
const Joi = require('joi'); | |
/* | |
Receive a js structure using joi values and return it as a joi object with keys. | |
Params: | |
schema : {strucutre} | |
Returns: | |
{Joi object} | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal{ | |
constructor(sound){ | |
this.sound = sound; | |
} | |
speak(text){ | |
//Split the input text by space. | |
let chunks = text.split(' '); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Parse and extract data from a string like: param1=111¶m2=222¶m3=333 | |
const parseQryStr = (url)=>{ | |
//Match xxx=yyy | |
const paramRegex = '[a-zA-Z0-9]=[a-zA-Z0-9]'; | |
//Split the params. | |
const params = url.split('&'); | |
//Extract the variables if match with the format. |
NewerOlder