- break
- catch
- delete
- else
- for
- function
- if
- return
- throw
- try
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
module.exports = function HTTPSRedirect(req, res, next) { | |
var env = process && process.env && process.env.NODE_ENV | |
if (env !== 'production' || req.headers['x-forwarded-proto'] === 'https' || req.url === '/health') { | |
next() | |
} | |
else { | |
res.redirect('https://' + req.hostname + req.url); | |
} | |
} |
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 add(a, b) { | |
if (!a) throw ReferenceError('a is undefined') | |
if (typeof a != 'number') throw TypeError('a not a number') | |
if (!b) throw ReferenceError('b is undefined') | |
if (typeof b != 'number') throw TypeError('b not a number') | |
return a + b | |
} | |
add(1, 2) |
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 assert = require('@smallwins/validate/assert') | |
function add(params) { | |
assert(params, { | |
'a': Number, | |
'b': Number, | |
}) | |
return params.a + params.b | |
} |
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 assert = require('assert') | |
function add(a, b) { | |
assert(typeof a === 'number', 'a is not a number got ' + typeof a) | |
assert(typeof b === 'number', 'b is not a number got ' + typeof b) | |
return a + b | |
} | |
add(1, 2) |
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
sns.publish({ | |
TargetArn: device.arn, | |
MessageStructure: 'json', | |
Message: JSON.stringify({ | |
default: 'you will never see this muah!', | |
APNS_SANDBOX: JSON.stringify({ | |
aps: { | |
'alert': '', | |
'content-available': 1 | |
}, |
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 test = require('tape') | |
var thingo = null | |
var mock = null | |
test('setup', t=> { | |
t.plan(1) | |
thingo.init() | |
t.ok(true, 'things are setup') | |
}) |
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
// Node style module writ in ES6 syntax: | |
exports default foo = () => console.log(‘hi’) | |
// Unfortunately “literally” transpiles to this: | |
exports.default = function foo() { | |
return console.log(‘hi’) | |
} | |
// Which means this will fail: | |
var foo = require(‘./foo’) |
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
// this is an AMD module | |
define(function () { | |
return something | |
}) | |
// and this is CommonJS | |
module.exports = something |
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset=utf-8> | |
<title>tests</title> | |
</head> | |
<body> | |
<div id=out></div> | |
<script src=test-echo-browser.js> | |
</script> |