Skip to content

Commit 8ec2427

Browse files
committed
refactor: switch to es6 code standards
1 parent e7aa747 commit 8ec2427

File tree

9 files changed

+239
-258
lines changed

9 files changed

+239
-258
lines changed

bench/index.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
2-
3-
var typeDetect = require('../');
4-
var Benchmark = require('benchmark');
5-
var benches = [];
6-
var fixtures = {
1+
import typeDetect from '../';
2+
import Benchmark from 'benchmark';
3+
const benches = [];
4+
const fixtures = {
75
'string literal ': '',
86
'array literal ': [],
97
'boolean literal ': true,
@@ -14,7 +12,7 @@ var fixtures = {
1412
'promise ': Promise.resolve(),
1513
'null ': null,
1614
'undefined ': undefined,
17-
'function ': function () {},
15+
'function '() {},
1816

1917
'buffer ': new Buffer(1),
2018
'date ': new Date(),
@@ -44,7 +42,7 @@ try {
4442
'Uint32Array', 'Uint16Array', 'Uint8Array',
4543
'Int32Array', 'Int16Array', 'Int8Array',
4644
'Uint8ClampedArray',
47-
].forEach(function (value) {
45+
].forEach((value) => {
4846
if (typeof global[value] === 'function') {
4947
fixtures[value + new Array(19 - value.length).join(' ')] = new (global[value])(1);
5048
}
@@ -53,15 +51,13 @@ if (typeof DataView === 'function') {
5351
fixtures['DataView '] = new DataView(new ArrayBuffer(1));
5452
}
5553

56-
var filter = process.argv[2] || '';
57-
Object.keys(fixtures).filter(function (key) {
58-
return key.indexOf(filter) !== -1;
59-
}).forEach(function (test) {
54+
const filter = process.argv[2] || '';
55+
Object.keys(fixtures).filter((key) => key.indexOf(filter) !== -1).forEach((test) => {
6056
benches.push(new Benchmark(test, {
61-
fn: function () {
57+
fn() {
6258
typeDetect(fixtures[test]);
6359
},
64-
onCycle: function (event) {
60+
onCycle(event) {
6561
process.stdout.clearLine();
6662
process.stdout.cursorTo(0);
6763
process.stdout.write(event.target.toString());

index.js

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
1-
'use strict';
2-
31
/* !
42
* type-detect
53
* Copyright(c) 2013 jake luer <[email protected]>
64
* MIT Licensed
75
*/
8-
var promiseExists = typeof Promise === 'function';
6+
const promiseExists = typeof Promise === 'function';
97

108
/* eslint-disable no-undef */
11-
var globalObject = typeof self === 'object' ? self : global; // eslint-disable-line id-blacklist
9+
const globalObject = typeof self === 'object' ? self : global; // eslint-disable-line id-blacklist
1210

1311
/*
1412
* All of these attributes must be available on the global object for the current environment
1513
* to be considered a DOM environment (browser)
1614
*/
17-
var isDom = typeof window === 'object' &&
15+
const isDom = typeof window === 'object' &&
1816
'document' in window &&
1917
'navigator' in window &&
2018
'HTMLElement' in window;
2119
/* eslint-enable */
2220

23-
var symbolExists = typeof Symbol !== 'undefined';
24-
var mapExists = typeof Map !== 'undefined';
25-
var setExists = typeof Set !== 'undefined';
26-
var weakMapExists = typeof WeakMap !== 'undefined';
27-
var weakSetExists = typeof WeakSet !== 'undefined';
28-
var dataViewExists = typeof DataView !== 'undefined';
29-
var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
30-
var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
31-
var setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
32-
var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
33-
var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
34-
var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
35-
var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
36-
var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
37-
var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
38-
var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
39-
var toStringLeftSliceLength = 8;
40-
var toStringRightSliceLength = -1;
21+
const symbolExists = typeof Symbol !== 'undefined';
22+
const mapExists = typeof Map !== 'undefined';
23+
const setExists = typeof Set !== 'undefined';
24+
const weakMapExists = typeof WeakMap !== 'undefined';
25+
const weakSetExists = typeof WeakSet !== 'undefined';
26+
const dataViewExists = typeof DataView !== 'undefined';
27+
const symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
28+
const symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
29+
const setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
30+
const mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
31+
const setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
32+
const mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
33+
const arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
34+
const arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
35+
const stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
36+
const stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
37+
const toStringLeftSliceLength = 8;
38+
const toStringRightSliceLength = -1;
4139
/**
4240
* ### typeOf (obj)
4341
*
@@ -48,7 +46,7 @@ var toStringRightSliceLength = -1;
4846
* @return {String} object type
4947
* @api public
5048
*/
51-
module.exports = function typeDetect(obj) {
49+
export default function typeDetect(obj) {
5250
/* ! Speed optimisation
5351
* Pre:
5452
* string literal x 3,039,035 ops/sec ±1.62% (78 runs sampled)
@@ -63,7 +61,7 @@ module.exports = function typeDetect(obj) {
6361
* undefined x 32,363,368 ops/sec ±1.07% (82 runs sampled)
6462
* function x 31,296,870 ops/sec ±0.96% (83 runs sampled)
6563
*/
66-
var typeofObj = typeof obj;
64+
const typeofObj = typeof obj;
6765
if (typeofObj !== 'object') {
6866
return typeofObj;
6967
}
@@ -231,12 +229,12 @@ module.exports = function typeDetect(obj) {
231229
* Int8Array x 6,606,078 ops/sec ±1.74% (81 runs sampled)
232230
* Uint8ClampedArray x 6,602,224 ops/sec ±1.77% (83 runs sampled)
233231
*/
234-
var stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
232+
const stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
235233
if (typeof stringTag === 'string') {
236234
return stringTag;
237235
}
238236

239-
var objPrototype = Object.getPrototypeOf(obj);
237+
const objPrototype = Object.getPrototypeOf(obj);
240238
/* ! Speed optimisation
241239
* Pre:
242240
* regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
@@ -377,6 +375,4 @@ module.exports = function typeDetect(obj) {
377375
.toString
378376
.call(obj)
379377
.slice(toStringLeftSliceLength, toStringRightSliceLength);
380-
};
381-
382-
module.exports.typeDetect = module.exports;
378+
}

karma.conf.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
'use strict';
2-
31
/* eslint-disable no-process-env */
4-
var packageJson = require('./package.json');
5-
var defaultTimeout = 120000;
6-
var browserifyIstanbul = require('browserify-istanbul');
2+
const packageJson = require('./package.json');
3+
const defaultTimeout = 120000;
4+
const browserifyIstanbul = require('browserify-istanbul');
75
module.exports = function configureKarma(config) {
8-
var localBrowsers = [
6+
const localBrowsers = [
97
'PhantomJS',
108
];
11-
var sauceLabsBrowsers = {
9+
const sauceLabsBrowsers = {
1210
SauceChromeLatest: {
1311
base: 'SauceLabs',
1412
browserName: 'Chrome',
@@ -73,10 +71,10 @@ module.exports = function configureKarma(config) {
7371
});
7472

7573
if (process.env.SAUCE_ACCESS_KEY && process.env.SAUCE_USERNAME) {
76-
var branch = process.env.TRAVIS_BRANCH || 'local';
77-
var build = 'localbuild';
74+
const branch = process.env.TRAVIS_BRANCH || 'local';
75+
let build = 'localbuild';
7876
if (process.env.TRAVIS_JOB_NUMBER) {
79-
build = 'travis@' + process.env.TRAVIS_JOB_NUMBER;
77+
build = `travis@${ process.env.TRAVIS_JOB_NUMBER }`;
8078
}
8179
config.reporters.push('saucelabs');
8280
config.set({
@@ -88,8 +86,8 @@ module.exports = function configureKarma(config) {
8886
recordVideo: true,
8987
startConnect: ('TRAVIS' in process.env) === false,
9088
tags: [
91-
'typeDetect_' + packageJson.version,
92-
process.env.SAUCE_USERNAME + '@' + branch,
89+
`typeDetect_${ packageJson.version }`,
90+
`${ process.env.SAUCE_USERNAME }@${ branch }`,
9391
build,
9492
],
9593
},

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@
4040
"es6": true
4141
},
4242
"extends": [
43-
"strict/es5"
43+
"strict/es6"
4444
],
4545
"globals": {
4646
"HTMLElement": false
4747
},
4848
"rules": {
4949
"complexity": 0,
50-
"max-statements": 0
50+
"max-statements": 0,
51+
"prefer-rest-params": 0
5152
}
5253
},
5354
"dependencies": {},

0 commit comments

Comments
 (0)