Skip to content

Commit 49b7062

Browse files
authored
Merge pull request #108 from keithamus/build-improvements
Build improvements
2 parents e7aa747 + 834bf33 commit 49b7062

16 files changed

+9214
-401
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ npm-debug.log
1919
coverage/
2020

2121
type-detect.js
22+
type-detect.test.js
23+
.nyc_output

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.npmjs.org/

.travis.yml

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,72 @@
11
sudo: false
22

3-
language: node_js
3+
dist: trusty
44

5-
addons:
6-
sauce_connect: true
5+
language: node_js
76

87
cache:
98
directories:
109
- node_modules
10+
- ~/.npm
1111

12-
node_js:
13-
- 4 # to be removed 2018-04-01
14-
- 6 # to be removed 2019-04-01
15-
- 7 # to be removed 2017-06-30
16-
- lts/* # safety net; don't remove
17-
- node # safety net; don't remove
18-
19-
before_install:
20-
- npm i -g npm@latest
21-
22-
script:
23-
- npm t
12+
node_js: 8
2413

25-
after_success:
26-
- 'travis-after-all && npm run semantic-release'
14+
jobs:
15+
include:
16+
- stage: lint
17+
script: npm run lint
18+
- stage: test
19+
addons:
20+
chrome: stable
21+
firefox: latest
22+
before_script:
23+
- "export DISPLAY=:99.0"
24+
- "sh -e /etc/init.d/xvfb start"
25+
- sleep 3 # give xvfb some time to start
26+
script: npm run test:browser
27+
env:
28+
- QUICKLY_TEST_BROWSERS_AVAILABLE_IN_CI=1 # kept here for easier reading of build log
29+
- stage: test
30+
addons:
31+
sauce_connect: true
32+
script:
33+
- 'if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ -z "$SAUCE_USERNAME" ]; then echo "Cannot run tests without SAUCE_USERNAME"; exit 1; fi'
34+
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then echo "SauceLabs tests do not run in builds of pull requests. This build will now exit"; exit 0; fi'
35+
- 'if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ -n "$SAUCE_USERNAME" ]; then npm run test:browser; fi'
36+
env:
37+
- TEST_BROWSERS_IN_SAUCELABS=1 # kept here for easier reading of build log
38+
- secure: AgiUWRCNP2z0oHCjdm3lk4YawBOQz8Q4DOrzOR3tDt2fSWo2t40cynfGJlQwpFmTvec5G04lO9bEC9/yoW7xAS0ysu5p7utngXaKtKDoq3Zr0aYLLLsCv/0PAv1YstMyo/mRbRetxob76wUFcrbB3r5alIF5YW1JCmj/O9bvdUQ=
39+
- secure: TepAZmznoPWUX12snu2eb7Sni+31tiOO6ZeU3wovrhCpGzykBNr6xAvUklr88L+uKtvfsTq8sipX0jtZvL7lcIEzujirTpjaj4QV5mUFiV2N40o+C3LdNmfmU9dhUcXRu9vMSs9uc7YfPers4We8X99UxTHxljK7VyJe39ULpRk=
40+
- SAUCE_CONNECT_READY_FILE=/tmp/sauce-connect-ready
41+
- stage: test
42+
node_js: 8 # to be removed 2019-12-01
43+
script: npm run test:node
44+
- stage: test
45+
node_js: 7 # to be removed 2017-06-30
46+
before_install: npm i -g npm@5
47+
script: npm run test:node
48+
- stage: test
49+
node_js: 6 # to be removed 2019-04-01
50+
before_install: npm i -g npm@5
51+
script: npm run test:node
52+
- stage: test
53+
node_js: 4 # to be removed 2018-04-01
54+
before_install: npm i -g npm@5
55+
script: npm run test:node
56+
- stage: test
57+
node_js: lts/* # safety net; don't remove
58+
script: npm run test:node
59+
- stage: test
60+
node_js: node # safety net; don't remove
61+
script: npm run test:node
62+
- stage: semantic-release
63+
script:
64+
- if [ "$TRAVIS_PULL_REQUEST" != "false" ] || [ "$TRAVIS_BRANCH" != "master" ]; then echo "the deploy job only runs for the master branch. This build will now exit"; exit 0; fi
65+
- if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then npm run semantic-release; fi
66+
env:
67+
- secure: fakflt6DaPW9NYFdUpTfQGoKFt5F1EZeSiGqWeTCZ3+VDiEC/d9rPf7JfHkDklpr4swEW7ovbfV4PHp+MeT+jje8eQAezbhdT8hAmChykeTKKfgvifMwQp6TD3DQVrf6cJqqZfkJkkzuYJjGivZ8FA4KXTglyBrjozM8KH675UU=
68+
- secure: bE+qM+B4dA+oQSfHo4BM9NVU5LCdgkEmfThfmIp3kmX19RO/1R1dlu18M1rVyDUNaqFUwCsq/W/9a+Dv1r+7knmfmJoUKuXCcIjn6WBs4Pd2kPwjCjvQ+5RWTw67v44de78AFb3IH7dT2H+fhgeHrfaI3NIV27BlKx6OqTnqDRY=
2769

2870
env:
2971
global:
30-
- secure: AgiUWRCNP2z0oHCjdm3lk4YawBOQz8Q4DOrzOR3tDt2fSWo2t40cynfGJlQwpFmTvec5G04lO9bEC9/yoW7xAS0ysu5p7utngXaKtKDoq3Zr0aYLLLsCv/0PAv1YstMyo/mRbRetxob76wUFcrbB3r5alIF5YW1JCmj/O9bvdUQ=
31-
- secure: TepAZmznoPWUX12snu2eb7Sni+31tiOO6ZeU3wovrhCpGzykBNr6xAvUklr88L+uKtvfsTq8sipX0jtZvL7lcIEzujirTpjaj4QV5mUFiV2N40o+C3LdNmfmU9dhUcXRu9vMSs9uc7YfPers4We8X99UxTHxljK7VyJe39ULpRk=
32-
- SAUCE_CONNECT_READY_FILE=/tmp/sauce-connect-ready
3372
- LOGS_DIR=/tmp/chai-build/logs
34-
- secure: fakflt6DaPW9NYFdUpTfQGoKFt5F1EZeSiGqWeTCZ3+VDiEC/d9rPf7JfHkDklpr4swEW7ovbfV4PHp+MeT+jje8eQAezbhdT8hAmChykeTKKfgvifMwQp6TD3DQVrf6cJqqZfkJkkzuYJjGivZ8FA4KXTglyBrjozM8KH675UU=
35-
- secure: bE+qM+B4dA+oQSfHo4BM9NVU5LCdgkEmfThfmIp3kmX19RO/1R1dlu18M1rVyDUNaqFUwCsq/W/9a+Dv1r+7knmfmJoUKuXCcIjn6WBs4Pd2kPwjCjvQ+5RWTw67v44de78AFb3IH7dT2H+fhgeHrfaI3NIV27BlKx6OqTnqDRY=

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<img alt="ChaiJS" src="http://chaijs.com/img/chai-logo.png"/> type-detect
44
</a>
55
</h1>
6-
6+
<br>
77
<p align=center>
88
Improved typeof detection for <a href="http://nodejs.org">node</a> and the browser.
99
</p>
@@ -52,12 +52,21 @@
5252
/>
5353
</a>
5454
<br/>
55-
<a href="https://saucelabs.com/u/chaijs-type-detect">
56-
<img
57-
alt="Selenium Test Status"
58-
src="https://saucelabs.com/browser-matrix/chaijs-type-detect.svg"
59-
/>
60-
</a>
55+
<table>
56+
<tr><th colspan=6>Supported Browsers</th></tr> <tr>
57+
<th align=center><img src="https://camo.githubusercontent.com/ab586f11dfcb49bf5f2c2fa9adadc5e857de122a/687474703a2f2f73766773686172652e636f6d2f692f3278532e737667" alt=""> Chrome</th>
58+
<th align=center><img src="https://camo.githubusercontent.com/98cca3108c18dcfaa62667b42046540c6822cdac/687474703a2f2f73766773686172652e636f6d2f692f3279352e737667" alt=""> Edge</th>
59+
<th align=center><img src="https://camo.githubusercontent.com/acdcb09840a9e1442cbaf1b684f95ab3c3f41cf4/687474703a2f2f73766773686172652e636f6d2f692f3279462e737667" alt=""> Firefox</th>
60+
<th align=center><img src="https://camo.githubusercontent.com/728f8cb0bee9ed58ab85e39266f1152c53e0dffd/687474703a2f2f73766773686172652e636f6d2f692f3278342e737667" alt=""> Safari</th>
61+
<th align=center><img src="https://camo.githubusercontent.com/96a2317034dee0040d0a762e7a30c3c650c45aac/687474703a2f2f73766773686172652e636f6d2f692f3279532e737667" alt=""> IE</th>
62+
</tr><tr>
63+
<td align=center>✅</td>
64+
<td align=center>✅</td>
65+
<td align=center>✅</td>
66+
<td align=center>✅</td>
67+
<td align=center>9, 10, 11</td>
68+
</tr>
69+
</table>
6170
<br>
6271
<a href="https://chai-slack.herokuapp.com/">
6372
<img

appveyor.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: '{build}'
2+
3+
skip_tags: true
4+
skip_branch_with_pr: true
5+
clone_depth: 1
6+
deploy: off
7+
build: off
8+
9+
install:
10+
- ps: Install-Product node '8'
11+
- npm i -g npm@5
12+
- npm install
13+
14+
test_script:
15+
- node --version
16+
- npm --version
17+
- npm test
18+
19+
cache:
20+
- node_modules -> package-lock.json
21+
- '%APPDATA%\npm-cache'

bench/index.js

Lines changed: 13 additions & 20 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,9 +12,9 @@ var fixtures = {
1412
'promise ': Promise.resolve(),
1513
'null ': null,
1614
'undefined ': undefined,
17-
'function ': function () {},
15+
'function '() {},
1816

19-
'buffer ': new Buffer(1),
17+
'buffer ': Buffer.from(1),
2018
'date ': new Date(),
2119
'error ': new Error(),
2220
'map ': new Map(),
@@ -39,12 +37,9 @@ try {
3937
} catch (error) {
4038
console.error('cannot benchmark generator functions');
4139
}
42-
[
43-
'Float64Array', 'Float32Array',
44-
'Uint32Array', 'Uint16Array', 'Uint8Array',
45-
'Int32Array', 'Int16Array', 'Int8Array',
46-
'Uint8ClampedArray',
47-
].forEach(function (value) {
40+
const arrayTypes = [ 'Float64', 'Float32', 'Uint32', 'Uint16', 'Uint8', 'Int32', 'Int16', 'Int8', 'Uint8Clamped' ];
41+
arrayTypes.forEach((value) => {
42+
value += 'Array';
4843
if (typeof global[value] === 'function') {
4944
fixtures[value + new Array(19 - value.length).join(' ')] = new (global[value])(1);
5045
}
@@ -53,15 +48,13 @@ if (typeof DataView === 'function') {
5348
fixtures['DataView '] = new DataView(new ArrayBuffer(1));
5449
}
5550

56-
var filter = process.argv[2] || '';
57-
Object.keys(fixtures).filter(function (key) {
58-
return key.indexOf(filter) !== -1;
59-
}).forEach(function (test) {
51+
const filter = process.argv[2] || '';
52+
Object.keys(fixtures).filter((key) => key.indexOf(filter) !== -1).forEach((test) => {
6053
benches.push(new Benchmark(test, {
61-
fn: function () {
54+
fn() {
6255
typeDetect(fixtures[test]);
6356
},
64-
onCycle: function (event) {
57+
onCycle(event) {
6558
process.stdout.clearLine();
6659
process.stdout.cursorTo(0);
6760
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+
}

0 commit comments

Comments
 (0)