This file contains 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
// Compose functions from right to left | |
const compose = (...fns) => x => fns.reduceRight((y, f) => f(y), x); | |
// Example | |
const lowercase = str => str.toLowerCase(); | |
const capitalize = str => `${str.charAt(0).toUpperCase()}${str.slice(1)}`; | |
const reverse = str => str.split('').reverse().join(''); | |
const fn = compose(reverse, capitalize, lowercase); |
This file contains 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 curry = (fn, ...args) => { | |
return fn.length <= args.length ? fn(...args) : curry.bind(null, fn, ...args); | |
} | |
// Example | |
const sum = (a, b, c) => a + b + c; | |
curry(sum)(3)(4)(5); // 12 | |
curry(sum)(3, 4, 5); // 12 |
This file contains 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 slugify = string => string.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]+/g, ''); | |
const kebabToCamel = str => str.replace(/-./g, m => m.toUpperCase()[1]); | |
const camelToKebab = str => str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase(); | |
const toPascalCase = str => (str.match(/[a-zA-Z0-9]+/g) || []) | |
.map(w => `${w.charAt(0).toUpperCase()}${w.slice(1)}`).join(''); | |
// Examples |
This file contains 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
// generate random string | |
const generateString = | |
(length, chars) => Array(length) | |
.fill('') | |
.map((v) => chars[Math.floor(Math.random() * chars.length)]) | |
.join(''); | |
// Example | |
generateString(10, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
This file contains 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
beforeEach(function() { | |
env = sinon.sandbox.create(); | |
//stub all requests to server | |
$ajax = env.stub($, 'ajax'); | |
}); | |
afterEach(function() { | |
env.restore(); | |
}); |
This file contains 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
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Mocha Tests</title> | |
<link rel="stylesheet" href="lib/mocha/mocha.css" /> | |
<script src="lib/coffee-script.js"></script> | |
</head> | |
<body> | |
<div id="mocha"></div> | |
<script src="lib/mocha/mocha.js"></script> |
This file contains 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
{ | |
"name": "coffee-examples", | |
"version": "0.0.1", | |
"scripts": { | |
"test": "./node_modules/.bin/mocha --compilers coffee:coffee-script" | |
}, | |
"dependencies": { | |
"coffee-script": "*", | |
"mocha": "*", | |
"chai": "*", |
This file contains 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> | |
<title>CoffeeScript Examples</title> | |
<script src="http://coffeescript.org/extras/coffee-script.js" type="text/javascript"></script> | |
<script type="text/coffeescript"> | |
class A | |
constructor: -> | |
alert "Hello CoffeeScript" | |
a = new A |
This file contains 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
{ | |
"name": "coffee-examples", | |
"version": "0.0.1", | |
"scripts": { | |
"test": "./node_modules/.bin/mocha --compilers coffee:coffee-script" | |
}, | |
"dependencies": { | |
"coffee-script": "*", | |
"mocha": "*", | |
"chai": "*" |