Skip to content

Commit

Permalink
Merge pull request #108 from keithamus/build-improvements
Browse files Browse the repository at this point in the history
Build improvements
  • Loading branch information
vieiralucas authored Nov 3, 2017
2 parents e7aa747 + 834bf33 commit 49b7062
Show file tree
Hide file tree
Showing 16 changed files with 9,214 additions and 401 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ npm-debug.log
coverage/

type-detect.js
type-detect.test.js
.nyc_output
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://registry.npmjs.org/
81 changes: 59 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,72 @@
sudo: false

language: node_js
dist: trusty

addons:
sauce_connect: true
language: node_js

cache:
directories:
- node_modules
- ~/.npm

node_js:
- 4 # to be removed 2018-04-01
- 6 # to be removed 2019-04-01
- 7 # to be removed 2017-06-30
- lts/* # safety net; don't remove
- node # safety net; don't remove

before_install:
- npm i -g npm@latest

script:
- npm t
node_js: 8

after_success:
- 'travis-after-all && npm run semantic-release'
jobs:
include:
- stage: lint
script: npm run lint
- stage: test
addons:
chrome: stable
firefox: latest
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start
script: npm run test:browser
env:
- QUICKLY_TEST_BROWSERS_AVAILABLE_IN_CI=1 # kept here for easier reading of build log
- stage: test
addons:
sauce_connect: true
script:
- 'if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ -z "$SAUCE_USERNAME" ]; then echo "Cannot run tests without SAUCE_USERNAME"; exit 1; fi'
- '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'
- 'if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ -n "$SAUCE_USERNAME" ]; then npm run test:browser; fi'
env:
- TEST_BROWSERS_IN_SAUCELABS=1 # kept here for easier reading of build log
- secure: AgiUWRCNP2z0oHCjdm3lk4YawBOQz8Q4DOrzOR3tDt2fSWo2t40cynfGJlQwpFmTvec5G04lO9bEC9/yoW7xAS0ysu5p7utngXaKtKDoq3Zr0aYLLLsCv/0PAv1YstMyo/mRbRetxob76wUFcrbB3r5alIF5YW1JCmj/O9bvdUQ=
- secure: TepAZmznoPWUX12snu2eb7Sni+31tiOO6ZeU3wovrhCpGzykBNr6xAvUklr88L+uKtvfsTq8sipX0jtZvL7lcIEzujirTpjaj4QV5mUFiV2N40o+C3LdNmfmU9dhUcXRu9vMSs9uc7YfPers4We8X99UxTHxljK7VyJe39ULpRk=
- SAUCE_CONNECT_READY_FILE=/tmp/sauce-connect-ready
- stage: test
node_js: 8 # to be removed 2019-12-01
script: npm run test:node
- stage: test
node_js: 7 # to be removed 2017-06-30
before_install: npm i -g npm@5
script: npm run test:node
- stage: test
node_js: 6 # to be removed 2019-04-01
before_install: npm i -g npm@5
script: npm run test:node
- stage: test
node_js: 4 # to be removed 2018-04-01
before_install: npm i -g npm@5
script: npm run test:node
- stage: test
node_js: lts/* # safety net; don't remove
script: npm run test:node
- stage: test
node_js: node # safety net; don't remove
script: npm run test:node
- stage: semantic-release
script:
- 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
- if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then npm run semantic-release; fi
env:
- secure: fakflt6DaPW9NYFdUpTfQGoKFt5F1EZeSiGqWeTCZ3+VDiEC/d9rPf7JfHkDklpr4swEW7ovbfV4PHp+MeT+jje8eQAezbhdT8hAmChykeTKKfgvifMwQp6TD3DQVrf6cJqqZfkJkkzuYJjGivZ8FA4KXTglyBrjozM8KH675UU=
- secure: bE+qM+B4dA+oQSfHo4BM9NVU5LCdgkEmfThfmIp3kmX19RO/1R1dlu18M1rVyDUNaqFUwCsq/W/9a+Dv1r+7knmfmJoUKuXCcIjn6WBs4Pd2kPwjCjvQ+5RWTw67v44de78AFb3IH7dT2H+fhgeHrfaI3NIV27BlKx6OqTnqDRY=

env:
global:
- secure: AgiUWRCNP2z0oHCjdm3lk4YawBOQz8Q4DOrzOR3tDt2fSWo2t40cynfGJlQwpFmTvec5G04lO9bEC9/yoW7xAS0ysu5p7utngXaKtKDoq3Zr0aYLLLsCv/0PAv1YstMyo/mRbRetxob76wUFcrbB3r5alIF5YW1JCmj/O9bvdUQ=
- secure: TepAZmznoPWUX12snu2eb7Sni+31tiOO6ZeU3wovrhCpGzykBNr6xAvUklr88L+uKtvfsTq8sipX0jtZvL7lcIEzujirTpjaj4QV5mUFiV2N40o+C3LdNmfmU9dhUcXRu9vMSs9uc7YfPers4We8X99UxTHxljK7VyJe39ULpRk=
- SAUCE_CONNECT_READY_FILE=/tmp/sauce-connect-ready
- LOGS_DIR=/tmp/chai-build/logs
- secure: fakflt6DaPW9NYFdUpTfQGoKFt5F1EZeSiGqWeTCZ3+VDiEC/d9rPf7JfHkDklpr4swEW7ovbfV4PHp+MeT+jje8eQAezbhdT8hAmChykeTKKfgvifMwQp6TD3DQVrf6cJqqZfkJkkzuYJjGivZ8FA4KXTglyBrjozM8KH675UU=
- secure: bE+qM+B4dA+oQSfHo4BM9NVU5LCdgkEmfThfmIp3kmX19RO/1R1dlu18M1rVyDUNaqFUwCsq/W/9a+Dv1r+7knmfmJoUKuXCcIjn6WBs4Pd2kPwjCjvQ+5RWTw67v44de78AFb3IH7dT2H+fhgeHrfaI3NIV27BlKx6OqTnqDRY=
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img alt="ChaiJS" src="http://chaijs.com/img/chai-logo.png"/> type-detect
</a>
</h1>

<br>
<p align=center>
Improved typeof detection for <a href="http://nodejs.org">node</a> and the browser.
</p>
Expand Down Expand Up @@ -52,12 +52,21 @@
/>
</a>
<br/>
<a href="https://saucelabs.com/u/chaijs-type-detect">
<img
alt="Selenium Test Status"
src="https://saucelabs.com/browser-matrix/chaijs-type-detect.svg"
/>
</a>
<table>
<tr><th colspan=6>Supported Browsers</th></tr> <tr>
<th align=center><img src="https://camo.githubusercontent.com/ab586f11dfcb49bf5f2c2fa9adadc5e857de122a/687474703a2f2f73766773686172652e636f6d2f692f3278532e737667" alt=""> Chrome</th>
<th align=center><img src="https://camo.githubusercontent.com/98cca3108c18dcfaa62667b42046540c6822cdac/687474703a2f2f73766773686172652e636f6d2f692f3279352e737667" alt=""> Edge</th>
<th align=center><img src="https://camo.githubusercontent.com/acdcb09840a9e1442cbaf1b684f95ab3c3f41cf4/687474703a2f2f73766773686172652e636f6d2f692f3279462e737667" alt=""> Firefox</th>
<th align=center><img src="https://camo.githubusercontent.com/728f8cb0bee9ed58ab85e39266f1152c53e0dffd/687474703a2f2f73766773686172652e636f6d2f692f3278342e737667" alt=""> Safari</th>
<th align=center><img src="https://camo.githubusercontent.com/96a2317034dee0040d0a762e7a30c3c650c45aac/687474703a2f2f73766773686172652e636f6d2f692f3279532e737667" alt=""> IE</th>
</tr><tr>
<td align=center>✅</td>
<td align=center>✅</td>
<td align=center>✅</td>
<td align=center>✅</td>
<td align=center>9, 10, 11</td>
</tr>
</table>
<br>
<a href="https://chai-slack.herokuapp.com/">
<img
Expand Down
21 changes: 21 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '{build}'

skip_tags: true
skip_branch_with_pr: true
clone_depth: 1
deploy: off
build: off

install:
- ps: Install-Product node '8'
- npm i -g npm@5
- npm install

test_script:
- node --version
- npm --version
- npm test

cache:
- node_modules -> package-lock.json
- '%APPDATA%\npm-cache'
33 changes: 13 additions & 20 deletions bench/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';

var typeDetect = require('../');
var Benchmark = require('benchmark');
var benches = [];
var fixtures = {
import typeDetect from '../';
import Benchmark from 'benchmark';
const benches = [];
const fixtures = {
'string literal ': '',
'array literal ': [],
'boolean literal ': true,
Expand All @@ -14,9 +12,9 @@ var fixtures = {
'promise ': Promise.resolve(),
'null ': null,
'undefined ': undefined,
'function ': function () {},
'function '() {},

'buffer ': new Buffer(1),
'buffer ': Buffer.from(1),
'date ': new Date(),
'error ': new Error(),
'map ': new Map(),
Expand All @@ -39,12 +37,9 @@ try {
} catch (error) {
console.error('cannot benchmark generator functions');
}
[
'Float64Array', 'Float32Array',
'Uint32Array', 'Uint16Array', 'Uint8Array',
'Int32Array', 'Int16Array', 'Int8Array',
'Uint8ClampedArray',
].forEach(function (value) {
const arrayTypes = [ 'Float64', 'Float32', 'Uint32', 'Uint16', 'Uint8', 'Int32', 'Int16', 'Int8', 'Uint8Clamped' ];
arrayTypes.forEach((value) => {
value += 'Array';
if (typeof global[value] === 'function') {
fixtures[value + new Array(19 - value.length).join(' ')] = new (global[value])(1);
}
Expand All @@ -53,15 +48,13 @@ if (typeof DataView === 'function') {
fixtures['DataView '] = new DataView(new ArrayBuffer(1));
}

var filter = process.argv[2] || '';
Object.keys(fixtures).filter(function (key) {
return key.indexOf(filter) !== -1;
}).forEach(function (test) {
const filter = process.argv[2] || '';
Object.keys(fixtures).filter((key) => key.indexOf(filter) !== -1).forEach((test) => {
benches.push(new Benchmark(test, {
fn: function () {
fn() {
typeDetect(fixtures[test]);
},
onCycle: function (event) {
onCycle(event) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(event.target.toString());
Expand Down
56 changes: 26 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
'use strict';

/* !
* type-detect
* Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
* MIT Licensed
*/
var promiseExists = typeof Promise === 'function';
const promiseExists = typeof Promise === 'function';

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

/*
* All of these attributes must be available on the global object for the current environment
* to be considered a DOM environment (browser)
*/
var isDom = typeof window === 'object' &&
const isDom = typeof window === 'object' &&
'document' in window &&
'navigator' in window &&
'HTMLElement' in window;
/* eslint-enable */

var symbolExists = typeof Symbol !== 'undefined';
var mapExists = typeof Map !== 'undefined';
var setExists = typeof Set !== 'undefined';
var weakMapExists = typeof WeakMap !== 'undefined';
var weakSetExists = typeof WeakSet !== 'undefined';
var dataViewExists = typeof DataView !== 'undefined';
var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
var setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
var toStringLeftSliceLength = 8;
var toStringRightSliceLength = -1;
const symbolExists = typeof Symbol !== 'undefined';
const mapExists = typeof Map !== 'undefined';
const setExists = typeof Set !== 'undefined';
const weakMapExists = typeof WeakMap !== 'undefined';
const weakSetExists = typeof WeakSet !== 'undefined';
const dataViewExists = typeof DataView !== 'undefined';
const symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
const symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
const setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
const mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
const setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
const mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
const arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
const arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
const stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
const stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
const toStringLeftSliceLength = 8;
const toStringRightSliceLength = -1;
/**
* ### typeOf (obj)
*
Expand All @@ -48,7 +46,7 @@ var toStringRightSliceLength = -1;
* @return {String} object type
* @api public
*/
module.exports = function typeDetect(obj) {
export default function typeDetect(obj) {
/* ! Speed optimisation
* Pre:
* string literal x 3,039,035 ops/sec ±1.62% (78 runs sampled)
Expand All @@ -63,7 +61,7 @@ module.exports = function typeDetect(obj) {
* undefined x 32,363,368 ops/sec ±1.07% (82 runs sampled)
* function x 31,296,870 ops/sec ±0.96% (83 runs sampled)
*/
var typeofObj = typeof obj;
const typeofObj = typeof obj;
if (typeofObj !== 'object') {
return typeofObj;
}
Expand Down Expand Up @@ -231,12 +229,12 @@ module.exports = function typeDetect(obj) {
* Int8Array x 6,606,078 ops/sec ±1.74% (81 runs sampled)
* Uint8ClampedArray x 6,602,224 ops/sec ±1.77% (83 runs sampled)
*/
var stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
const stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
if (typeof stringTag === 'string') {
return stringTag;
}

var objPrototype = Object.getPrototypeOf(obj);
const objPrototype = Object.getPrototypeOf(obj);
/* ! Speed optimisation
* Pre:
* regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
Expand Down Expand Up @@ -377,6 +375,4 @@ module.exports = function typeDetect(obj) {
.toString
.call(obj)
.slice(toStringLeftSliceLength, toStringRightSliceLength);
};

module.exports.typeDetect = module.exports;
}
Loading

0 comments on commit 49b7062

Please sign in to comment.