Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Aug 24, 2021
1 parent dda5042 commit 794e56d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ jobs:
run: |
npm install || npm install || npm install
timeout-minutes: 15
- name: Build native add-on if `binding.gyp` exists
id: rebuild
run: |
if [ -f "binding.gyp" ]; then
npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild
fi
- name: Run tests
id: tests
run: |
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ jobs:
run: |
npm install || npm install || npm install
timeout-minutes: 15
- name: Build native add-on if `binding.gyp` exists
id: rebuild
run: |
if [ -f "binding.gyp" ]; then
npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild
fi
- name: Calculate test coverage
run: |
npm run test-cov || npm run test-cov || npm run test-cov
Expand Down
11 changes: 3 additions & 8 deletions is-node/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var getGlobal = require( '@stdlib/utils/global' );
var nativeClass = require( '@stdlib/utils/native-class' );
var isObject = require( './../../is-plain-object' );
var isString = require( './../../is-string' ).isPrimitive;
var toStr = require( './to_string.js' );
var globalScope = require( './global_scope.js' );


Expand Down Expand Up @@ -74,14 +75,8 @@ function isNode() {
// Check for a `process` global variable:
typeof proc === 'object' &&

// Check that the `process` global variable has the expected internal class:
(
// Node < v14.6.0
nativeClass( proc ) === '[object process]' ||

// Node >= v14.6.0
nativeClass( proc ) === '[object Object]'
) &&
// Check that the `process` global variable has the expected internal class (NOTE: we use `toStr`, rather than `nativecClass` to address changes introduced in Node >= v14.6.0; see https://github.com/stdlib-js/stdlib/issues/375):
toStr( proc ) === '[object process]' &&

// Check for a `versions` property:
isObject( proc.versions ) &&
Expand Down
42 changes: 42 additions & 0 deletions is-node/lib/to_string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2021 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// VARIABLES //

var toStr = Object.prototype.toString;


// MAIN //

/**
* Returns the internal class of a provided value.
*
* @private
* @param {*} value - input value
* @returns {string} internal class
*/
function toString( value ) { // eslint-disable-line stdlib/no-redeclare
return toStr.call( value );
}


// EXPORTS //

module.exports = toString;
5 changes: 4 additions & 1 deletion is-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
}
],
"main": "./lib",
"browser": "./lib/browser.js",
"browser": {
"./lib": "./lib/browser.js",
"process": "process/"
},
"directories": {
"doc": "./docs",
"example": "./examples",
Expand Down
18 changes: 10 additions & 8 deletions is-node/test/test.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ tape( 'the function returns `false` if runtime is not Node.js (`global` variable
tape( 'the function returns `false` if runtime is not Node.js (`global` variable has wrong class)', function test( t ) {
var isNode;

function nativeClass( val ) {
if ( val === proc ) {
return '[object process]';
}
function nativeClass() {
return '[object beeeeeeep]';
}

Expand Down Expand Up @@ -183,12 +180,16 @@ tape( 'the function returns `false` if runtime is not Node.js (`global` variable
tape( 'the function returns `false` if runtime is not Node.js (`process` variable has wrong class)', function test( t ) {
var isNode;

function nativeClass( val ) {
function nativeClass() {
// Node.js version <7 (https://github.com/nodejs/node/issues/9274):
return '[object global]';
}

function toStr( val ) {
if ( val === proc ) {
return '[object beeeeeeep]';
}
// Node.js version <7 (https://github.com/nodejs/node/issues/9274):
return '[object global]';
return Object.prototype.toString.call( val );
}

function isString() {}
Expand All @@ -202,7 +203,8 @@ tape( 'the function returns `false` if runtime is not Node.js (`process` variabl
'@stdlib/utils/native-class': nativeClass,
'./../../is-plain-object': alwaysTrue,
'./../../is-string': isString,
'./global_scope.js': true
'./global_scope.js': true,
'./to_string.js': toStr
});
t.equal( isNode(), false, 'returns false' );
t.end();
Expand Down

0 comments on commit 794e56d

Please sign in to comment.