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
| { | |
| "countries": [{ | |
| "name": "India", | |
| "key": "https://gist.githubusercontent.com/ramsunvtech/694b7fd273ce50e7ba346f467a0b5261/raw/da763f3170e0e0f05e349c79a501e332b213006e/india.json" | |
| }] | |
| } |
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
| { | |
| "list": [{ | |
| "name": "Tamil Nadu", | |
| "key": "tamil-nadu", | |
| "active": true | |
| }, { | |
| "name": "Andhra Pradesh", | |
| "key": "andhra-pradesh", | |
| "active": false | |
| }, { |
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
| var async = require('async'); | |
| function firstCallback (customArg, callback) { | |
| callback(null, 'first: ' + customArg); | |
| } | |
| function secondCallback (customArg1, customArg2, customArg3, callback) { | |
| callback(null, 'second: ' + customArg1 + '-' + customArg2 + '-' + customArg3); | |
| } |
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
| /** | |
| * Return the Domain Name from the Url | |
| * @param {String} url Full HTTP Url. | |
| * @return {String} URl Domain Name. | |
| */ | |
| module.exports.getDomain = (url) => { | |
| if (!url) return ''; | |
| let hostName = ''; |
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 async = require('async'); | |
| const db = require('./db'); | |
| function myAsyncParallel(callback) { | |
| async.parallel({ | |
| first: db.userData.bind(null, 'first arg'), | |
| second: db.activityData.bind(null, 'second arg') | |
| }, callback); | |
| } | |
| module.exports = { | |
| myAsyncParallel, |
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
| (function simple() { | |
| let serviceResponse = new Promise((resolve, reject) => { | |
| setTimeout(() => resolve(‘Success’), 2000); | |
| }); | |
| serviceResponse.then((msg) => { | |
| console.log(`Hello Message is ${msg}`); | |
| }, () => { | |
| console.log(‘oops!its rejected’); | |
| }); | |
| }()); |
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
| function basic(result) { | |
| if (!result) { | |
| return Promise.reject('Failure'); | |
| } | |
| return new Promise((resolve, reject) => { | |
| // Assume that this below data is retrieved | |
| // from Database which takes 1.6 seconds. | |
| setTimeout(() => resolve(result), 1600); | |
| }); | |
| } |
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 mocha = require('mocha'); | |
| const expect = require('chai').expect; | |
| const basicFile = require('./basic'); | |
| describe('Basic Testing', () => { | |
| const noop = () => {}; | |
| describe('Basic', () => { | |
| it('should have method `basic`', () => { | |
| expect(basicFile).to.be.an('object'); | |
| expect(typeof basicFile.basic).to.equal('function'); | |
| }); |
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 db = require('./db'); | |
| function getResultData(name) { | |
| let payload; | |
| if (name) { | |
| payload = { | |
| prop1: `value1-${name}`, | |
| prop2: `value2-${name}`, | |
| }; | |
| } | |
| return new Promise((resolve, reject) => { |
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
| function getData(payload) { | |
| return new Promise((resolve, reject) => { | |
| if (!payload) { | |
| reject({ | |
| error: true, | |
| }); | |
| } | |
| setTimeout(() => { | |
| resolve({ | |
| name1: 'value1', |