ext install prettier-vscode
ext install prettier-standard-vscode
ext install vscode-standardjs
{
| handler: (request, h) => { | |
| const captcha = svgCaptcha.create({ | |
| size: 5 | |
| }) | |
| return h.response(captcha.data).header('Content-Type', 'image/svg+xml') | |
| } |
| // handy function to strip the plusing part of a email address with + | |
| const stripPlusing = em => em.replace(/\+[^@]+/, '') | |
| console.log(stripPlusing('[email protected]')) | |
| console.log(stripPlusing('[email protected]')) | |
| console.log(stripPlusing('[email protected]')) | |
| /* | |
| [email protected] | |
| [email protected] |
| const register = async server => { | |
| server.route([ | |
| { | |
| path: '/moduleA/info', | |
| method: 'GET', | |
| handler: request => { | |
| return 'this is from moduleA/info' | |
| } | |
| } | |
| ]) |
| const fetch = require('node-fetch') | |
| const delay = (ms) => { | |
| return new Promise(resolve => { | |
| setTimeout(() => { | |
| resolve() | |
| }, ms) | |
| }) | |
| } | |
| const retryFetch = (url, fetchOptions={}, retries=3, retryDelay=1000) => { |
| const Hapi = require('hapi') | |
| const double = (input) => { | |
| return new Promise(resolve => { | |
| setTimeout(() => { | |
| return resolve(input+input) | |
| }, 500) | |
| }) | |
| } |
| // using array | |
| const bluebird = require('bluebird') | |
| const things = [{a: 1}, {b: 2}, {c: 3}] | |
| function doit(doc) { | |
| return bluebird.delay(1000).then(() => {return doc}) | |
| } | |
| async function main() { |
| async function main() { | |
| const Hapi = require('./lib'); | |
| const server = Hapi.server({ port: 80 }); | |
| server.event('test'); | |
| server.events.once('test', (update) => console.log(update)); | |
| await server.emit('test', 'hello'); | |
| await server.emit('test', 'hello'); // Ignored | |
| } |
| const mongoose = require('mongoose') | |
| mongoose.Promise = require('bluebird') // optional, use this to get rid of | |
| // the mpromise DeprecationWarning | |
| const conn = mongoose.createConnection('mongodb://localhost/testDB') | |
| const Schema = mongoose.Schema | |
| const UserSchema = new Schema({ | |
| username: String, | |
| email: String | |
| }) |
| const fetch = require('node-fetch') | |
| const Promise = require('bluebird') | |
| const headers = { | |
| 'User-Agent': 'YOUR-GITHUB-USERNAME' | |
| } | |
| const repos = [ | |
| 'scottwrobinson/camo', | |
| 'facebook/react', |