Skip to content

Commit d5aa641

Browse files
committed
es2015 setup
1 parent 838208e commit d5aa641

File tree

11 files changed

+77
-280
lines changed

11 files changed

+77
-280
lines changed

.babelrc

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2-
"presets": ["es2015", "es2016", "es2017"],
3-
"plugins": ["babel-plugin-add-module-exports"]
2+
"presets": ["env"],
3+
"plugins": [
4+
"add-module-exports",
5+
"transform-es2015-modules-umd"
6+
]
47
}

.eslintrc.json

+3-148
Original file line numberDiff line numberDiff line change
@@ -16,155 +16,10 @@
1616
"window": false
1717
},
1818
"parser": "babel-eslint",
19+
"extends": "airbnb-base",
1920
"rules": {
20-
"block-scoped-var": 2,
21-
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
22-
"camelcase": [2, { "properties": "always" }],
23-
"comma-dangle": [2, "never"],
24-
"comma-spacing": [2, { "before": false, "after": true }],
25-
"comma-style": [2, "last"],
26-
"complexity": 0,
27-
"consistent-return": 2,
28-
"consistent-this": 0,
29-
"curly": [2, "multi-line"],
30-
"default-case": 0,
31-
"dot-location": [2, "property"],
32-
"dot-notation": 0,
33-
"eol-last": 2,
34-
"eqeqeq": [2, "allow-null"],
35-
"func-names": 0,
36-
"func-style": 0,
37-
"generator-star-spacing": [2, "both"],
38-
"guard-for-in": 0,
39-
"handle-callback-err": [2, "^(err|error|anySpecificError)$" ],
40-
"indent": [2, 2, { "SwitchCase": 1 }],
41-
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
42-
"keyword-spacing": [2, {"before": true, "after": true}],
43-
"linebreak-style": 0,
44-
"max-depth": 0,
45-
"max-len": [2, 120, 4],
46-
"max-nested-callbacks": 0,
47-
"max-params": 0,
48-
"max-statements": 0,
49-
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
50-
"newline-after-var": [0, "always"],
51-
"new-parens": 2,
52-
"no-alert": 0,
53-
"no-array-constructor": 2,
54-
"no-bitwise": 0,
55-
"no-caller": 2,
56-
"no-catch-shadow": 0,
57-
"no-cond-assign": 2,
58-
"no-console": 0,
59-
"no-constant-condition": 0,
60-
"no-continue": 0,
61-
"no-control-regex": 2,
62-
"no-debugger": 2,
63-
"no-delete-var": 2,
64-
"no-div-regex": 0,
65-
"no-dupe-args": 2,
66-
"no-dupe-keys": 2,
67-
"no-duplicate-case": 2,
68-
"no-else-return": 2,
69-
"no-empty": 0,
70-
"no-empty-character-class": 2,
71-
"no-eq-null": 0,
72-
"no-eval": 2,
73-
"no-ex-assign": 2,
74-
"no-extend-native": 2,
75-
"no-extra-bind": 2,
76-
"no-extra-boolean-cast": 2,
77-
"no-extra-parens": 0,
78-
"no-extra-semi": 0,
79-
"no-extra-strict": 0,
80-
"no-fallthrough": 2,
81-
"no-floating-decimal": 2,
82-
"no-func-assign": 2,
83-
"no-implied-eval": 2,
84-
"no-inline-comments": 0,
85-
"no-inner-declarations": [2, "functions"],
86-
"no-invalid-regexp": 2,
87-
"no-irregular-whitespace": 2,
88-
"no-iterator": 2,
89-
"no-label-var": 2,
90-
"no-labels": 2,
91-
"no-lone-blocks": 0,
92-
"no-lonely-if": 0,
93-
"no-loop-func": 0,
94-
"no-mixed-requires": 0,
95-
"no-mixed-spaces-and-tabs": [2, false],
96-
"no-multi-spaces": 2,
97-
"no-multi-str": 2,
98-
"no-multiple-empty-lines": [2, { "max": 1 }],
99-
"no-native-reassign": 2,
100-
"no-negated-in-lhs": 2,
101-
"no-nested-ternary": 0,
102-
"no-new": 2,
103-
"no-new-func": 2,
104-
"no-new-object": 2,
105-
"no-new-require": 2,
106-
"no-new-wrappers": 2,
107-
"no-obj-calls": 2,
108-
"no-octal": 2,
109-
"no-octal-escape": 2,
110-
"no-path-concat": 0,
21+
"class-methods-use-this": 0,
11122
"no-plusplus": 0,
112-
"no-process-env": 0,
113-
"no-process-exit": 0,
114-
"no-proto": 2,
115-
"no-redeclare": 2,
116-
"no-regex-spaces": 2,
117-
"no-reserved-keys": 0,
118-
"no-restricted-modules": 0,
119-
"no-return-assign": 2,
120-
"no-script-url": 0,
121-
"no-self-compare": 2,
122-
"no-sequences": 2,
123-
"no-shadow": 0,
124-
"no-shadow-restricted-names": 2,
125-
"no-spaced-func": 2,
126-
"no-sparse-arrays": 2,
127-
"no-sync": 0,
128-
"no-ternary": 0,
129-
"no-throw-literal": 2,
130-
"no-trailing-spaces": 2,
131-
"no-undef": 2,
132-
"no-undef-init": 2,
133-
"no-undefined": 0,
134-
"no-underscore-dangle": 0,
135-
"no-unneeded-ternary": 2,
136-
"no-unreachable": 2,
137-
"no-unused-expressions": 0,
138-
"no-unused-vars": [2, { "vars": "all", "args": "none" }],
139-
"no-use-before-define": 2,
140-
"no-var": 0,
141-
"no-void": 0,
142-
"no-warning-comments": 0,
143-
"no-with": 2,
144-
"one-var": 0,
145-
"operator-assignment": 0,
146-
"operator-linebreak": [2, "after"],
147-
"padded-blocks": 0,
148-
"quote-props": 0,
149-
"quotes": [2, "single", "avoid-escape"],
150-
"radix": 2,
151-
"semi": [2, "always"],
152-
"semi-spacing": 0,
153-
"sort-vars": 0,
154-
"space-before-blocks": [2, "always"],
155-
"space-before-function-paren": [0, {"anonymous": "always", "named": "never"}],
156-
"space-in-brackets": 0,
157-
"space-in-parens": [2, "never"],
158-
"space-infix-ops": 2,
159-
"space-unary-ops": [2, { "words": true, "nonwords": false }],
160-
"spaced-comment": [2, "always"],
161-
"strict": 0,
162-
"use-isnan": 2,
163-
"valid-jsdoc": 0,
164-
"valid-typeof": 2,
165-
"vars-on-top": 0,
166-
"wrap-iife": [2, "any"],
167-
"wrap-regex": 0,
168-
"yoda": [2, "never"]
23+
"arrow-parens": 0
16924
}
17025
}

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ install:
66
script:
77
- npm run go
88
after_success:
9-
- npm run nyc-report
9+
- npm run coverage
1010
notifications:
1111
email:
1212
on_failure: change

examples/chapter03/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<title></title>
66
</head>
77
<body>
8-
<script src="index.js" type="module"></script>
8+
<script src="./../../dist/js/data-structures/Stack.js"></script>
9+
<script src="index.js"></script>
910
</body>
1011
</html>

examples/chapter03/index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import Stack from './../../src/js/data-structures/stack.js';
1+
// import Stack from './../../src/js/data-structures/stack.js'; // ES2015 modules
2+
// const Stack = require('../../dist/js/data-structures/Stack'); // node
3+
// none above for browser
24

3-
const stack = new Stack();
5+
// const s = new Stack();
6+
// s.push(1);
47

5-
console.log(stack);
8+
// console.log(s.isEmpty());

gulpfile.babel.js

-32
This file was deleted.

package.json

+16-21
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@
1414
},
1515
"homepage": "https://github.com/loiane/javascript-datastructures-algorithms",
1616
"scripts": {
17-
"gulp": "gulp",
18-
"clean": "rm -rf ./dist; mkdir ./dist rm; rm -rf ./coverage",
19-
"build:js": "babel src/js --presets babel-preset-es2015 --out-dir dist/js",
17+
"clean": "rm -rf ./dist ./coverage ./.nyc_output",
18+
"build:js": "babel src/js -d dist/js",
2019
"build:ts": "tsc",
2120
"build": "npm run build:js && npm run build:ts",
22-
"test:js": "mocha --compilers js:babel-core/register --colors --recursive ./test/js/**/*.spec.js",
23-
"test:ts": "mocha -r ts-node/register --colors --recursive ./test/ts/**/*.spec.ts",
21+
"lint:js": "eslint src/js && eslint test/js",
22+
"lint:ts": "tslint -c tslint.json 'src/ts/**/*.ts' && tslint -c tslint.json 'test/ts/**/*.ts'",
23+
"lint": "npm run lint:js && npm run lint:ts",
24+
"test:js": "mocha --compilers js:babel-core/register ./test/js/**/*.spec.js",
25+
"test:ts": "mocha -r ts-node/register ./test/ts/**/*.spec.ts",
2426
"test": "npm run test:js && npm run test:ts",
25-
"coverage:js": "./node_modules/.bin/istanbul cover --include-all-sources --root ./src/js ./node_modules/.bin/_mocha --recursive ./test/js/**/*.spec.js -- --compilers js:babel-core/register",
26-
"nyc-report": "npm run coverage && nyc report --reporter=text-lcov > coverage.lcov && codecov",
27-
"local": "npm run clean && npm run coverage && nyc report --reporter=text",
28-
"coverage": "NODE_ENV=test nyc --report-dir coverage npm run test",
29-
"go": "npm run clean && npm run build && npm run test"
27+
"test:dev": "npm run clean && npm run generate-report",
28+
"coverage": "npm run generate-report && nyc report --reporter=text-lcov > coverage.lcov && codecov",
29+
"generate-report": "nyc --report-dir coverage npm run test && nyc report --reporter=text",
30+
"go": "npm run clean && npm run lint && npm run build"
3031
},
3132
"nyc": {
3233
"include": [
@@ -55,24 +56,18 @@
5556
"babel-core": "^6.26.0",
5657
"babel-eslint": "^8.0.0",
5758
"babel-plugin-add-module-exports": "^0.2.1",
58-
"babel-preset-es2015": "^6.24.1",
59-
"babel-preset-es2016": "^6.24.1",
60-
"babel-preset-es2017": "^6.24.1",
61-
"babelify": "^7.3.0",
62-
"browserify": "^14.4.0",
59+
"babel-plugin-transform-es2015-modules-umd": "^6.24.1",
60+
"babel-preset-env": "^1.6.0",
6361
"chai": "^4.1.2",
6462
"codecov": "^2.3.0",
65-
"del": "^3.0.0",
6663
"eslint": "^4.6.1",
67-
"event-stream": "^3.3.4",
68-
"glob": "^7.1.2",
69-
"gulp": "^3.9.1",
64+
"eslint-config-airbnb-base": "^12.0.0",
65+
"eslint-plugin-import": "^2.7.0",
7066
"istanbul": "^v1.1.0-alpha.1",
7167
"mocha": "^3.5.0",
7268
"nyc": "^11.2.1",
7369
"ts-node": "^3.3.0",
7470
"tslint": "^5.7.0",
75-
"typescript": "^2.5.2",
76-
"vinyl-source-stream": "^1.1.0"
71+
"typescript": "^2.5.2"
7772
}
7873
}

src/js/data-structures/stack.js

+39-42
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,39 @@
1-
const Stack = (() => {
2-
let items;
3-
class DS {
4-
constructor() {
5-
items = [];
6-
}
7-
push(element) {
8-
items.push(element);
9-
}
10-
11-
pop() {
12-
return items.pop();
13-
}
14-
15-
peek() {
16-
return items[items.length - 1];
17-
}
18-
19-
isEmpty() {
20-
return items.length === 0;
21-
}
22-
23-
size() {
24-
return items.length;
25-
}
26-
27-
clear() {
28-
items = [];
29-
}
30-
31-
toArray() {
32-
return items;
33-
}
34-
35-
toString() {
36-
return items.toString();
37-
}
38-
}
39-
return DS;
40-
})();
41-
42-
export default Stack;
1+
let items;
2+
export default class Stack {
3+
constructor() {
4+
items = [];
5+
}
6+
push(element) {
7+
items.push(element);
8+
}
9+
10+
pop() {
11+
return items.pop();
12+
}
13+
14+
peek() {
15+
return items[items.length - 1];
16+
}
17+
18+
isEmpty() {
19+
return items.length === 0;
20+
}
21+
22+
size() {
23+
return items.length;
24+
}
25+
26+
clear() {
27+
items = [];
28+
}
29+
30+
toArray() {
31+
return items;
32+
}
33+
34+
toString() {
35+
return items.toString();
36+
}
37+
}
38+
39+
// export default Stack;

test/js/data-structures/stack.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Stack from '../../../src/js/data-structures/stack';
55
describe('Stack', () => {
66
let stack;
77

8-
beforeEach(function() {
8+
beforeEach(() => {
99
stack = new Stack();
1010
});
1111

0 commit comments

Comments
 (0)