├── .gitignore ├── .snyk ├── .travis.yml ├── README.md ├── gulpfile.js ├── images └── es6-lab.gif ├── js └── es6.js ├── package.json └── spec └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | -------------------------------------------------------------------------------- /.snyk: -------------------------------------------------------------------------------- 1 | version: v1.5.0 2 | ignore: {} 3 | patch: 4 | 'npm:minimatch:20160620': 5 | - gulp > vinyl-fs > glob-stream > glob > minimatch: 6 | patched: '2016-12-02T03:57:00.427Z' 7 | - gulp > vinyl-fs > glob-stream > minimatch: 8 | patched: '2016-12-02T03:57:00.427Z' 9 | - gulp > vinyl-fs > glob-watcher > gaze > globule > minimatch: 10 | patched: '2016-12-02T03:57:00.427Z' 11 | - gulp > vinyl-fs > glob-watcher > gaze > globule > glob > minimatch: 12 | patched: '2016-12-02T03:57:00.427Z' 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.11" 4 | - "0.10" 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://travis-ci.org/hemanth/es6-lab-setup.svg?branch=master) 2 | 3 | > What the hell is this? 4 | 5 | Simply put it's a place where you code in ES6 which gets converted to ES5 on the fly along with jasmine test. 6 | 7 | ES6 => ECMAScript6 8 | 9 | > How to setup your ES6 LAB? 10 | 11 | * git clone https://github.com/hemanth/es6-lab-setup.git 12 | 13 | * cd es6-lab-setup 14 | 15 | * npm install 16 | 17 | * gulp 18 | 19 | That would watch for any changes in `js` and `spec` dir and fire a `babel` or `traceur` and `jasmine` task. 20 | 21 | P.S: You may use `gulp babel` or `gulp traceur` as per your need, defaults to `babel`. 22 | __Sample usage:__ 23 | 24 | ![](/images/es6-lab.gif) 25 | 26 | 27 | More ES6 recpies at [paws-on-es6](https://github.com/hemanth/paws-on-es6) 28 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'), 2 | watch = require('gulp-watch'), 3 | jasmine = require('gulp-jasmine'), 4 | sourcemaps = require('gulp-sourcemaps'), 5 | traceur = require('gulp-traceur'), 6 | to5 = require('gulp-babel'); 7 | 8 | gulp.task('babel', function () { 9 | return gulp.src('js/**/*.js') 10 | .pipe(sourcemaps.init()) 11 | .pipe(to5({ 12 | stage: 0, 13 | loose: 'all' 14 | })) 15 | .pipe(sourcemaps.write()) 16 | .pipe(gulp.dest('dist')); 17 | }); 18 | 19 | gulp.task('traceur', function() { 20 | return gulp.src('js/**/*.js') 21 | .pipe(sourcemaps.init()) 22 | .pipe(traceur({ 23 | blockBinding: true, 24 | experimental: true, 25 | arrayComprehension: true, 26 | types: true 27 | })) 28 | .pipe(sourcemaps.write()) 29 | .pipe(gulp.dest('dist')); 30 | }); 31 | 32 | gulp.task('jasmine', function() { 33 | return gulp.src('spec/test.js') 34 | .pipe(jasmine()); 35 | }); 36 | 37 | gulp.task('default', ['babel','jasmine'], function() { 38 | gulp.watch('js/**/*.js', ['babel']); 39 | gulp.watch('js/**/*.js', ['jasmine']); 40 | gulp.watch('spec/*.js', ['jasmine']); 41 | }); 42 | -------------------------------------------------------------------------------- /images/es6-lab.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemanth/es6-lab-setup/b2c599e0b1062e1d085f1af0f94ba951657e84a4/images/es6-lab.gif -------------------------------------------------------------------------------- /js/es6.js: -------------------------------------------------------------------------------- 1 | require("babel/polyfill"); 2 | require('traceur/bin/traceur-runtime'); 3 | 4 | var es6 = {}; 5 | 6 | // Arrow function. 7 | es6.arrow = (x) => x * x; 8 | 9 | // Array Comprehension. 10 | es6.ArrayComprehension = function (){ 11 | // BTW it was Charles Darwin's tortoise. 12 | return [ for (value of ["Harriet", "178"]) value ] 13 | .join(" was "); 14 | } 15 | 16 | // Block scope 17 | es6.blockBinding = function (){ 18 | { 19 | var wife = 1; 20 | let gfs = 10; 21 | }; 22 | return typeof gfs; 23 | } 24 | 25 | // Default params. 26 | es6.defaultParmas = function(msg="Hello ",name="World!"){ 27 | return msg+name; 28 | } 29 | 30 | // Destructuring. 31 | es6.destructuring = function (){ 32 | var {foo, bar} = {foo: "lorem", bar: "ipsum"}; 33 | return foo+bar; 34 | } 35 | 36 | // for of 37 | es6.forOf = function(nums) { 38 | let sum = 0; 39 | for (let element of nums) { 40 | sum = sum + element; 41 | } 42 | return sum; 43 | } 44 | 45 | // Generator function. 46 | es6.gen = function(){ 47 | var counterFn = function *Counter(){ 48 | var n = 0; 49 | while(1<2) { 50 | yield n; 51 | ++n; 52 | } 53 | }; 54 | return (new counterFn()); 55 | }; 56 | 57 | es6.objectObserve = function(obj, changeFn) { 58 | // Gone to ES7 59 | // Object.observe(obj, changeFn); 60 | } 61 | 62 | es6.sortRestArgs = function (...theArgs){ 63 | return theArgs.sort(); 64 | } 65 | 66 | es6.spreadData = function (n) { 67 | var spreadedArray = [1,...n,5]; 68 | return spreadedArray; 69 | } 70 | 71 | es6.symbols = function(value){ 72 | var s = Symbol("catname"); 73 | var object = {}; 74 | object[s] = value; 75 | return object[s]; 76 | }; 77 | 78 | es6.map = function(answer, unset=true){ 79 | let m = new Map(); 80 | m.set('answer', answer); 81 | if(unset) { 82 | m.delete('answer'); 83 | } 84 | return m.has('answer'); 85 | }; 86 | 87 | es6.objLiteral = function () { 88 | var x = -10; 89 | var y = 10; 90 | 91 | return {x, y}; 92 | }; 93 | 94 | es6.tmplLiteral = function(name="hemanth"){ 95 | return `hello ${name}`; 96 | }; 97 | 98 | module.exports = es6; 99 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "babel": "^6.0.0", 4 | "gulp": "^3.8.11", 5 | "gulp-babel": "^6.0.0", 6 | "gulp-jasmine": "^2.0.1", 7 | "gulp-sourcemaps": "~1.5.1", 8 | "gulp-traceur": "^0.17.0", 9 | "gulp-watch": "^4.2.3", 10 | "traceur": "0.0.103", 11 | "snyk": "^1.21.2" 12 | }, 13 | "scripts": { 14 | "test": "gulp babel && gulp jasmine", 15 | "test2": "gulp traceur && gulp jasmine", 16 | "snyk-protect": "snyk protect", 17 | "prepublish": "npm run snyk-protect" 18 | }, 19 | "snyk": true 20 | } 21 | -------------------------------------------------------------------------------- /spec/test.js: -------------------------------------------------------------------------------- 1 | var es6 = require("../dist/es6.js"); 2 | 3 | describe("ES6 suite", function() { 4 | 5 | it("should sq the number", function() { 6 | expect(es6.arrow(2)).toBe(4); 7 | }); 8 | 9 | it("should give a count value", function() { 10 | var countr = new es6.gen(); 11 | expect(countr.next().value).toBe(0); 12 | expect(countr.next().value).toBe(1); 13 | expect(countr.next().value).toBe(2); 14 | expect(countr.next().value).toBe(3); 15 | }); 16 | 17 | it("should give a string", function() { 18 | expect(es6.ArrayComprehension()).toMatch('was'); 19 | }); 20 | 21 | it("should be undefined", function() { 22 | expect(es6.blockBinding()).toBe('undefined'); 23 | }); 24 | 25 | it("should return Hello World!", function() { 26 | expect(es6.defaultParmas()).toBe('Hello World!'); 27 | }); 28 | 29 | it("should return loremipsum", function() { 30 | expect(es6.destructuring()).toBe('loremipsum'); 31 | }); 32 | 33 | it("should return the sum of the arrays", function() { 34 | expect(es6.forOf([1,2,3])).toBe(6); 35 | }); 36 | 37 | xit("should return the changed value", function() { 38 | var obj = {}; 39 | var changeFn = function(changes){ 40 | console.log(changes); 41 | return changes; 42 | }; 43 | es6.objectObserve(obj, changeFn); 44 | 45 | obj.name = "test"; 46 | }); 47 | 48 | it("should sort the passed list", function() { 49 | expect(es6.sortRestArgs(6,1,7,3,8).join(",")).toBe("1,3,6,7,8"); 50 | }); 51 | 52 | it("should give expanded array", function(){ 53 | expect(es6.spreadData([2,3,4]).join(",")).toBe("1,2,3,4,5"); 54 | }); 55 | 56 | it("should give the name of cat", function(){ 57 | expect(es6.symbols("milly")).toBe("milly"); 58 | }); 59 | 60 | it("to test presence of answer", function(){ 61 | expect(es6.map(42)).toBe(false); 62 | expect(es6.map(42, false)).toBe(true); 63 | }); 64 | 65 | it("should return an object", function() { 66 | expect(es6.objLiteral()).toEqual({ x : -10, y : 10 }); 67 | }); 68 | 69 | it("should do some template manipulation", function() { 70 | expect(es6.tmplLiteral('world')).toEqual('hello world'); 71 | }); 72 | 73 | }); --------------------------------------------------------------------------------