Skip to content

Commit ba7f4e5

Browse files
committed
Inline functions in order to not depend on other pkgs
1 parent 28f541d commit ba7f4e5

5 files changed

Lines changed: 96 additions & 10 deletions

File tree

lib/node_modules/@stdlib/string/format/lib/format_double.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
// MODULES //
2222

23-
var isUppercase = require( '@stdlib/assert/is-uppercase' );
24-
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
23+
var isNumber = require( './is_number.js' );
2524

2625
// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.
2726
var abs = Math.abs; // eslint-disable-line stdlib/no-builtin-math
@@ -55,7 +54,7 @@ function formatDouble( token ) {
5554
var digits;
5655
var out;
5756
var f = parseFloat( token.arg );
58-
if ( !isFinite( f ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` to avoid circular dependencies.
57+
if ( !isFinite( f ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.
5958
if ( !isNumber( token.arg ) ) {
6059
throw new Error( 'invalid floating-point number. Value: ' + out );
6160
}
@@ -100,7 +99,7 @@ function formatDouble( token ) {
10099
if ( f >= 0 && token.sign ) {
101100
out = token.sign + out;
102101
}
103-
out = ( isUppercase( token.specifier ) ) ?
102+
out = ( token.specifier === uppercase.call( token.specifier ) ) ?
104103
uppercase.call( out ) :
105104
lowercase.call( out );
106105
return out;

lib/node_modules/@stdlib/string/format/lib/format_integer.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
// MODULES //
2222

23-
var isUppercase = require( '@stdlib/assert/is-uppercase' );
24-
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
23+
var isNumber = require( './is_number.js' );
2524
var zeroPad = require( './zero_pad.js' );
2625

2726
// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.
@@ -68,7 +67,7 @@ function formatInteger( token ) {
6867
}
6968
out = token.arg;
7069
i = parseInt( out, 10 );
71-
if ( !isFinite( i ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` to avoid circular dependencies.
70+
if ( !isFinite( i ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.
7271
if ( !isNumber( out ) ) {
7372
throw new Error( 'invalid integer. Value: ' + out );
7473
}
@@ -98,7 +97,7 @@ function formatInteger( token ) {
9897
if ( token.alternate ) {
9998
out = '0x' + out;
10099
}
101-
out = ( isUppercase( token.specifier ) ) ?
100+
out = ( token.specifier === uppercase.call( token.specifier ) ) ?
102101
uppercase.call( out ) :
103102
lowercase.call( out );
104103
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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+
/**
22+
* Tests if a value is a number primitive.
23+
*
24+
* @param {*} value - value to test
25+
* @returns {boolean} boolean indicating if a value is a number primitive
26+
*
27+
* @example
28+
* var bool = isNumber( 3.14 );
29+
* // returns true
30+
*
31+
* @example
32+
* var bool = isNumber( NaN );
33+
* // returns true
34+
*
35+
* @example
36+
* var bool = isNumber( new Number( 3.14 ) );
37+
* // returns false
38+
*/
39+
function isNumber( value ) {
40+
return ( typeof value === 'number' ); // NOTE: we inline the `isNumber.isPrimitive` function from `@stdlib/assert/is-number` in order to avoid circular dependencies.
41+
}
42+
43+
44+
// EXPORTS //
45+
46+
module.exports = isNumber;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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+
/**
22+
* Tests if a value is a string primitive.
23+
*
24+
* @param {*} value - value to test
25+
* @returns {boolean} boolean indicating if a value is a string primitive
26+
*
27+
* @example
28+
* var bool = isString( 'beep' );
29+
* // returns true
30+
*
31+
* @example
32+
* var bool = isString( new String( 'beep' ) );
33+
* // returns false
34+
*/
35+
function isString( value ) {
36+
return ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.
37+
}
38+
39+
40+
// EXPORTS //
41+
42+
module.exports = isString;

lib/node_modules/@stdlib/string/format/lib/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
// MODULES //
2222

23-
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2423
var formatInteger = require( './format_integer.js' );
2524
var formatDouble = require( './format_double.js' );
2625
var tokenize = require( './tokenize.js' );
2726
var spacePad = require( './space_pad.js' );
2827
var zeroPad = require( './zero_pad.js' );
28+
var isString = require( './is_string.js' );
2929

3030

3131
// VARIABLES //
@@ -94,7 +94,7 @@ function format( str ) {
9494
token.padZeros = false;
9595
break;
9696
case '0':
97-
token.padZeros = !flags.includes( '-' ); // NOTE: We use built-in `Array.prototype.includes` here instead of `@stdlib/assert/contains` to avoid circular dependencies.
97+
token.padZeros = !flags.includes( '-' ); // NOTE: We use built-in `Array.prototype.includes` here instead of `@stdlib/assert/contains` in order to avoid circular dependencies.
9898
break;
9999
case '#':
100100
token.alternate = true;

0 commit comments

Comments
 (0)