Skip to content

Commit 0d2b813

Browse files
committed
Refactor to avoid circular dependencies
1 parent fa7d6ba commit 0d2b813

File tree

7 files changed

+108
-26
lines changed

7 files changed

+108
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MAIN //
22+
23+
/**
24+
* Tests if a finite double-precision floating-point number is an integer.
25+
*
26+
* @param {number} x - value to test
27+
* @returns {boolean} boolean indicating whether the value is an integer
28+
*
29+
* @example
30+
* var bool = isInteger( 1.0 );
31+
* // returns true
32+
*
33+
* @example
34+
* var bool = isInteger( 3.14 );
35+
* // returns false
36+
*/
37+
function isInteger( x ) {
38+
return ( Math.floor( x ) === x ); // eslint-disable-line stdlib/no-builtin-math
39+
}
40+
41+
42+
// EXPORTS //
43+
44+
module.exports = isInteger;

lib/node_modules/@stdlib/cli/lib/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
var parseArgs = require( 'minimist' ); // TODO: replace with stdlib equivalent
2626
var notifier = require( 'update-notifier' ); // TODO: replace with stdlib equivalent
27-
var isInteger = require( '@stdlib/math/base/assert/is-integer' );
2827
var defaults = require( './defaults.json' );
28+
var isInteger = require( './is_integer.js' );
2929
var validate = require( './validate.js' );
3030
var proc = require( './process.js' );
3131
var log = require( './console.js' );

lib/node_modules/@stdlib/utils/library-manifest/bin/cli

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// MODULES //
2424

2525
var resolve = require( 'path' ).resolve;
26-
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
26+
var readFileSync = require( 'fs' ).readFileSync; // eslint-disable-line no-sync
2727
var CLI = require( '@stdlib/cli' );
2828
var manifest = require( './../lib' );
2929

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MAIN //
22+
23+
/**
24+
* Tests if a value is an object; e.g., `{}`.
25+
*
26+
* @param {*} value - value to test
27+
* @returns {boolean} boolean indicating whether value is an object
28+
*
29+
* @example
30+
* var bool = isObject( {} );
31+
* // returns true
32+
*
33+
* @example
34+
* var bool = isObject( null );
35+
* // returns false
36+
*/
37+
function isObject( value ) {
38+
return (
39+
typeof value === 'object' &&
40+
value !== null &&
41+
!Array.isArray( value )
42+
);
43+
}
44+
45+
46+
// EXPORTS //
47+
48+
module.exports = isObject;

lib/node_modules/@stdlib/utils/library-manifest/lib/manifest.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@
2121
// MODULES //
2222

2323
var path = require( 'path' );
24+
var cwd = require( 'process' ).cwd;
2425
var logger = require( 'debug' );
2526
var resolve = require( 'resolve' ).sync;
26-
var objectKeys = require( '@stdlib/utils/keys' );
27-
var cwd = require( '@stdlib/process/cwd' );
28-
var copy = require( '@stdlib/utils/copy' );
29-
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
30-
var isObject = require( '@stdlib/assert/is-plain-object' );
3127
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
3228
var parentPath = require( '@stdlib/fs/resolve-parent-path' ).sync;
33-
var dirname = require( '@stdlib/utils/dirname' );
3429
var convertPath = require( '@stdlib/utils/convert-path' );
30+
var isObject = require( './is_object.js' );
3531
var unique = require( './unique.js' );
3632
var validate = require( './validate.js' );
3733
var DEFAULTS = require( './defaults.json' );
@@ -79,10 +75,10 @@ function manifest( fpath, conditions, options ) {
7975
var j;
8076
var k;
8177

82-
if ( !isString( fpath ) ) {
78+
if ( typeof fpath !== 'string' ) {
8379
throw new TypeError( 'invalid argument. First argument must be a string. Value: `'+fpath+'`.' );
8480
}
85-
opts = copy( DEFAULTS );
81+
opts = JSON.parse( JSON.stringify( DEFAULTS ) );
8682
if ( arguments.length > 2 ) {
8783
err = validate( opts, options );
8884
if ( err ) {
@@ -95,11 +91,11 @@ function manifest( fpath, conditions, options ) {
9591
debug( 'Options: %s', JSON.stringify( opts ) );
9692

9793
fpath = path.resolve( opts.basedir, fpath );
98-
dir = dirname( fpath );
94+
dir = path.dirname( fpath );
9995
debug( 'Manifest file path: %s', fpath );
10096

10197
conf = require( fpath ); // eslint-disable-line stdlib/no-dynamic-require
102-
conf = copy( conf );
98+
conf = JSON.parse( JSON.stringify( conf ) );
10399
debug( 'Manifest: %s', JSON.stringify( conf ) );
104100

105101
// TODO: validate a loaded manifest (conf) according to a JSON schema
@@ -109,7 +105,7 @@ function manifest( fpath, conditions, options ) {
109105
throw new TypeError( 'invalid argument. Second argument must be an object. Value: `' + conditions + '`.' );
110106
}
111107
debug( 'Provided conditions: %s', JSON.stringify( conditions ) );
112-
coptnames = objectKeys( conf.options );
108+
coptnames = Object.keys( conf.options );
113109
for ( i = 0; i < coptnames.length; i++ ) {
114110
key = coptnames[ i ];
115111
if ( hasOwnProp( conditions, key ) ) {
@@ -135,7 +131,7 @@ function manifest( fpath, conditions, options ) {
135131
}
136132
// If we exhausted all the options, then we found a match...
137133
if ( j === coptnames.length ) {
138-
obj = copy( o );
134+
obj = JSON.parse( JSON.stringify( o ) );
139135
debug( 'Matching configuration: %s', JSON.stringify( obj ) );
140136
break;
141137
}
@@ -172,9 +168,9 @@ function manifest( fpath, conditions, options ) {
172168

173169
// Resolve a dependency's path by finding the dependency's `package.json`:
174170
mpath = parentPath( 'package.json', {
175-
'dir': dirname( mpath )
171+
'dir': path.dirname( mpath )
176172
});
177-
mpath = dirname( mpath );
173+
mpath = path.dirname( mpath );
178174
debug( 'Dependency path: %s', mpath );
179175

180176
// Load the dependency configuration (recursive):

lib/node_modules/@stdlib/utils/library-manifest/lib/unique.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818

1919
'use strict';
2020

21-
// MODULES //
22-
23-
var objectKeys = require( '@stdlib/utils/keys' );
24-
25-
2621
// MAIN //
2722

2823
/**
@@ -39,7 +34,7 @@ function unique( arr ) {
3934
for ( i = 0; i < arr.length; i++ ) {
4035
obj[ arr[i] ] = true;
4136
}
42-
return objectKeys( obj );
37+
return Object.keys( obj );
4338
}
4439

4540

lib/node_modules/@stdlib/utils/library-manifest/lib/validate.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020

2121
// MODULES //
2222

23-
var isObject = require( '@stdlib/assert/is-plain-object' );
2423
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
25-
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
24+
var isObject = require( './is_object.js' );
2625

2726

2827
// MAIN //
@@ -54,13 +53,13 @@ function validate( opts, options ) {
5453
}
5554
if ( hasOwnProp( options, 'basedir' ) ) {
5655
opts.basedir = options.basedir;
57-
if ( !isString( opts.basedir ) ) {
56+
if ( typeof opts.basedir !== 'string' ) {
5857
return new TypeError( 'invalid option. `basedir` option must be a primitive string. Option: `' + opts.basedir + '`.' );
5958
}
6059
}
6160
if ( hasOwnProp( options, 'paths' ) ) {
6261
opts.paths = options.paths;
63-
if ( !isString( opts.paths ) ) {
62+
if ( typeof opts.paths !== 'string' ) {
6463
return new TypeError( 'invalid option. `paths` option must be a primitive string. Option: `' + opts.paths + '`.' );
6564
}
6665
}

0 commit comments

Comments
 (0)