From f446620fbaecdf00aa8af4c93cf6e79b4e8b3e38 Mon Sep 17 00:00:00 2001 From: Abdul Kaium Date: Tue, 23 Jun 2026 01:52:35 +0600 Subject: [PATCH 01/14] fix: fix `complex/base/parse` for correct parsing behavior --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/complex/base/parse/lib/main.js | 129 ++++++++++-------- .../@stdlib/complex/base/parse/test/test.js | 51 ++++++- 2 files changed, 123 insertions(+), 57 deletions(-) diff --git a/lib/node_modules/@stdlib/complex/base/parse/lib/main.js b/lib/node_modules/@stdlib/complex/base/parse/lib/main.js index 4cfa330cbc21..785f9d4cc6b2 100644 --- a/lib/node_modules/@stdlib/complex/base/parse/lib/main.js +++ b/lib/node_modules/@stdlib/complex/base/parse/lib/main.js @@ -20,10 +20,59 @@ // MODULES // -var replace = require( '@stdlib/string/replace' ); var Number = require( '@stdlib/number/ctor' ); +// FUNCTIONS // + +/** +* Return a regular expression that matches and captures a complex number, supporting standard notation, scientific notation, Infinity, and NaN (e.g., "3+4i", "-1.5e10", "NaN-i"). +* +* Regular expression: `/^(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)\s*(?=$|[+-]))?(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?\s*(i)\s*)?$/` +* +* - `^` +* - start of input +* +* - `(?:\s*([+-]?)\s*` +* - open an optional non-capturing group for the real part and capture an optional `+` or `-` literal for its sign, ignoring surrounding whitespace +* +* - `((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)` +* - capture the real magnitude, matching standard decimals, scientific notation, `Infinity`, or `NaN` +* +* - `\s*(?=$|[+-]))?` +* - match optional trailing whitespace, assert via positive lookahead that the real part is followed by either the end of input or the sign for the imaginary part, and close the real part group +* +* - `(?:\s*([+-]?)\s*` +* - open an optional non-capturing group for the imaginary part and capture an optional `+` or `-` literal for its sign, ignoring surrounding whitespace +* +* - `((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?` +* - capture the optional imaginary magnitude, matching standard decimals, scientific notation, `Infinity`, or `NaN` +* +* - `\s*(i)\s*)?` +* - capture the literal character `i` for the imaginary unit, ignoring surrounding whitespace, and close the imaginary part group +* +* - `$` +* - end of input +* +* ## Notes +* +* - The regular expression has the following capture groups +* 1. Sign of real part +* 2. Value of real part +* 3. Sign of imaginary part +* 4. Value of imaginary part +* 5. Imaginary suffix 'i' +* +* @private +* @constant +* @returns {RegExp} regular expression +* @default /^(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)\s*(?=$|[+-]))?(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?\s*(i)\s*)?$/ +*/ +function regexp() { + return /^(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)\s*(?=$|[+-]))?(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?\s*(i)\s*)?$/; +} + + // MAIN // /** @@ -46,70 +95,38 @@ var Number = require( '@stdlib/number/ctor' ); * // returns { 're': 4, 'im': 6 } */ function parse( str ) { - var imaginaryParts = []; - var currentToken = ''; - var isImaginary; - var realParts = []; - var parts = []; - var valid = true; - var value; - var part; - var re = 0; - var im = 0; - - var i; - if ( typeof str !== 'string' ) { - return null; - } + var match; + var re; + var im; - str = replace( str, ' ', '' ); - for ( i = 0; i < str.length; i++ ) { - if ( (str[i] === '+' || str[i] === '-') && i !== 0 && str[i - 1] !== 'e' ) { - parts.push( currentToken ); - currentToken = ''; - } else if ( i === str.length - 1 ) { - currentToken += str[ i ]; - parts.push( currentToken ); - } - currentToken += str[ i ]; + if ( typeof str !== 'string' || str === '' ) { + return null; } - for ( i = 0; i < parts.length; i++ ) { // Check for invalid parts... - part = parts[ i ]; - isImaginary = false; - - // Check for Iota on either sides: - if ( part[0] === 'i' ) { - part = part.slice( 1 ); - isImaginary = true; - } else if ( part[part.length - 1] === 'i' ) { - part = part.slice( 0, part.length - 1 ); - isImaginary = true; - } - - value = Number( part ); - if ( isNaN( value ) && part !== 'NaN' && part !== '+NaN' && part !== '-NaN' ) { - valid = false; - break; - } + match = str.match( regexp() ); // [ full_match, real_sign, real_value, imag_sign, imag_value, imag_suffix ] - if ( isImaginary ) { - imaginaryParts.push( value ); - } - else { - realParts.push( value ); - } + if ( match === null ) { + return null; } - if ( !valid ) { - return null; + // Real component: + if ( match[ 2 ] ) { + re = ( match[ 1 ] === '-' ) ? -1 : 1; + re *= Number.parseFloat( match[ 2 ] ); + } + else { + re = 0; } - for ( i = 0; i < realParts.length; i++ ) { - re += realParts[i]; + // Imaginary component: + if ( match[ 5 ] ) { + im = ( match[ 3 ] === '-' ) ? -1 : 1; + if ( match[ 4 ] ) { + im *= Number.parseFloat( match[ 4 ] ); + } } - for ( i = 0; i < imaginaryParts.length; i++ ) { - im += imaginaryParts[i]; + else { + im = 0; } return { diff --git a/lib/node_modules/@stdlib/complex/base/parse/test/test.js b/lib/node_modules/@stdlib/complex/base/parse/test/test.js index 7dcee4c10063..20881b8cb08e 100644 --- a/lib/node_modules/@stdlib/complex/base/parse/test/test.js +++ b/lib/node_modules/@stdlib/complex/base/parse/test/test.js @@ -141,6 +141,41 @@ tape( 'the function returns complex like object if provided valid complex string 're': Infinity, 'im': -Infinity } + }, + { + 'value': 'i', + 'expected': { + 're': 0, + 'im': 1 + } + }, + { + 'value': '1+i', + 'expected': { + 're': 1, + 'im': 1 + } + }, + { + 'value': '1-i', + 'expected': { + 're': 1, + 'im': -1 + } + }, + { + 'value': '.5 + 2.i', + 'expected': { + 're': 0.5, + 'im': 2 + } + }, + { + 'value': ' + 12.34e-5 - 54.32e1 i ', + 'expected': { + 're': 12.34e-5, + 'im': -54.32e1 + } } ]; @@ -161,7 +196,21 @@ tape( 'the function returns null if provided input is not a complex number strin Infinity, '55555555555555boop5', {}, - NaN + NaN, + '', + ' ', + ' ', + '+', + '-', + '2i + 1', + '12 3', + '.', + '1..2', + '1. 2', + '1.2e', + 'e5', + '1.2e3.5', + '1++2i' ]; for ( i = 0; i < values.length; i++ ) { From 7931870b207d08b0d9251ff10367cd1f679c6a65 Mon Sep 17 00:00:00 2001 From: Abdul Kaium Date: Tue, 23 Jun 2026 02:10:47 +0600 Subject: [PATCH 02/14] fix: update `complex/float64/parse` to use `complex/base/parse` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/complex/float32/parse/lib/main.js | 38 +++--------------- .../@stdlib/complex/float64/parse/lib/main.js | 40 +++---------------- 2 files changed, 11 insertions(+), 67 deletions(-) diff --git a/lib/node_modules/@stdlib/complex/float32/parse/lib/main.js b/lib/node_modules/@stdlib/complex/float32/parse/lib/main.js index 86d48d8e6e69..bfab5138f85f 100644 --- a/lib/node_modules/@stdlib/complex/float32/parse/lib/main.js +++ b/lib/node_modules/@stdlib/complex/float32/parse/lib/main.js @@ -21,28 +21,11 @@ // MODULES // var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var parse = require( '@stdlib/complex/base/parse' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var replace = require( '@stdlib/string/base/replace' ); var format = require( '@stdlib/string/format' ); -// FUNCTIONS // - -/** -* Matches a complex number string. -* -* @private -* @returns {RegExp} regular expression -* -* @example -* var re = regexp(); -* // returns /^([-+]?(\d*\.?\d*(?:[eE][-+]?\d+)?|Infinity|NaN)i?)?([-+])?((\d*\.?\d*(?:[eE][-+]?\d+)?|Infinity|NaN)i)?$/ -*/ -function regexp() { - return /^([-+]?(\d*\.?\d*(?:[eE][-+]?\d+)?|Infinity|NaN)i?)?([-+])?((\d*\.?\d*(?:[eE][-+]?\d+)?|Infinity|NaN)i)?$/; -} - - // MAIN // /** @@ -59,29 +42,18 @@ function regexp() { * // returns */ function parseComplex64( str ) { - var match; - var re; - var im = 0; + var v; if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } - match = replace( str, /\s/g, '' ).match( regexp() ); - if ( !match ) { + v = parse( str ); + if ( v === null ) { throw new Error( format( 'invalid argument. Unable to parse input string as a complex number. Value: `%s`.', str ) ); } - // Real part: - re = ( match[1] && !match[1].endsWith( 'i' ) ) ? parseFloat( match[1] ) : 0; - - // Imaginary part: - if ( match[4] ) { - im = ( ( match[3] === '-' ) ? -1 : 1 ) * parseFloat( replace( match[4], /i$/, '' ) ); - } else if ( match[1] && match[1].endsWith( 'i' ) ) { - im = parseFloat( replace( match[1], /i$/, '' ) ); - } - return new Complex64( re, im ); + return new Complex64( v.re, v.im ); } diff --git a/lib/node_modules/@stdlib/complex/float64/parse/lib/main.js b/lib/node_modules/@stdlib/complex/float64/parse/lib/main.js index 3bceef653762..8464471231ac 100644 --- a/lib/node_modules/@stdlib/complex/float64/parse/lib/main.js +++ b/lib/node_modules/@stdlib/complex/float64/parse/lib/main.js @@ -20,29 +20,12 @@ // MODULES // -var Complex128 = require( '@stdlib/complex/float64/ctor' ); var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var replace = require( '@stdlib/string/base/replace' ); +var parse = require( '@stdlib/complex/base/parse' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); var format = require( '@stdlib/string/format' ); -// FUNCTIONS // - -/** -* Matches a complex number string. -* -* @private -* @returns {RegExp} regular expression -* -* @example -* var re = regexp(); -* // returns /^([-+]?(\d*\.?\d*(?:[eE][-+]?\d+)?|Infinity|NaN)i?)?([-+])?((\d*\.?\d*(?:[eE][-+]?\d+)?|Infinity|NaN)i)?$/ -*/ -function regexp() { - return /^([-+]?(\d*\.?\d*(?:[eE][-+]?\d+)?|Infinity|NaN)i?)?([-+])?((\d*\.?\d*(?:[eE][-+]?\d+)?|Infinity|NaN)i)?$/; -} - - // MAIN // /** @@ -59,29 +42,18 @@ function regexp() { * // returns */ function parseComplex128( str ) { - var match; - var re; - var im = 0; + var v; if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } - match = replace( str, /\s/g, '' ).match( regexp() ); - if ( !match ) { + v = parse( str ); + if ( v === null ) { throw new Error( format( 'invalid argument. Unable to parse input string as a complex number. Value: `%s`.', str ) ); } - // Real part: - re = ( match[1] && !match[1].endsWith( 'i' ) ) ? parseFloat( match[1] ) : 0; - - // Imaginary part: - if ( match[4] ) { - im = ( ( match[3] === '-' ) ? -1 : 1 ) * parseFloat( replace( match[4], /i$/, '' ) ); - } else if ( match[1] && match[1].endsWith( 'i' ) ) { - im = parseFloat( replace( match[1], /i$/, '' ) ); - } - return new Complex128( re, im ); + return new Complex128( v.re, v.im ); } From dc2c10a107a1eae4dfdd8ffa3061a0c53763e6a0 Mon Sep 17 00:00:00 2001 From: Abdul Kaium Date: Tue, 23 Jun 2026 02:39:14 +0600 Subject: [PATCH 03/14] refactor: extract regexp out into separate file --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/complex/base/parse/lib/main.js | 52 +------------ .../@stdlib/complex/base/parse/lib/regexp.js | 73 +++++++++++++++++++ 2 files changed, 75 insertions(+), 50 deletions(-) create mode 100644 lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js diff --git a/lib/node_modules/@stdlib/complex/base/parse/lib/main.js b/lib/node_modules/@stdlib/complex/base/parse/lib/main.js index 785f9d4cc6b2..285e3cde53e9 100644 --- a/lib/node_modules/@stdlib/complex/base/parse/lib/main.js +++ b/lib/node_modules/@stdlib/complex/base/parse/lib/main.js @@ -21,56 +21,7 @@ // MODULES // var Number = require( '@stdlib/number/ctor' ); - - -// FUNCTIONS // - -/** -* Return a regular expression that matches and captures a complex number, supporting standard notation, scientific notation, Infinity, and NaN (e.g., "3+4i", "-1.5e10", "NaN-i"). -* -* Regular expression: `/^(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)\s*(?=$|[+-]))?(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?\s*(i)\s*)?$/` -* -* - `^` -* - start of input -* -* - `(?:\s*([+-]?)\s*` -* - open an optional non-capturing group for the real part and capture an optional `+` or `-` literal for its sign, ignoring surrounding whitespace -* -* - `((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)` -* - capture the real magnitude, matching standard decimals, scientific notation, `Infinity`, or `NaN` -* -* - `\s*(?=$|[+-]))?` -* - match optional trailing whitespace, assert via positive lookahead that the real part is followed by either the end of input or the sign for the imaginary part, and close the real part group -* -* - `(?:\s*([+-]?)\s*` -* - open an optional non-capturing group for the imaginary part and capture an optional `+` or `-` literal for its sign, ignoring surrounding whitespace -* -* - `((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?` -* - capture the optional imaginary magnitude, matching standard decimals, scientific notation, `Infinity`, or `NaN` -* -* - `\s*(i)\s*)?` -* - capture the literal character `i` for the imaginary unit, ignoring surrounding whitespace, and close the imaginary part group -* -* - `$` -* - end of input -* -* ## Notes -* -* - The regular expression has the following capture groups -* 1. Sign of real part -* 2. Value of real part -* 3. Sign of imaginary part -* 4. Value of imaginary part -* 5. Imaginary suffix 'i' -* -* @private -* @constant -* @returns {RegExp} regular expression -* @default /^(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)\s*(?=$|[+-]))?(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?\s*(i)\s*)?$/ -*/ -function regexp() { - return /^(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)\s*(?=$|[+-]))?(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?\s*(i)\s*)?$/; -} +var regexp = require( './regexp.js' ); // MAIN // @@ -103,6 +54,7 @@ function parse( str ) { return null; } + // OPTIMIZE: Consider implementing an alternative parser to improve performance over regular expression match = str.match( regexp() ); // [ full_match, real_sign, real_value, imag_sign, imag_value, imag_suffix ] if ( match === null ) { diff --git a/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js b/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js new file mode 100644 index 000000000000..d848c47e1acb --- /dev/null +++ b/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js @@ -0,0 +1,73 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +// MAIN // + +/** +* Return a regular expression that matches and captures a complex number, supporting standard notation, scientific notation, Infinity, and NaN (e.g., "3+4i", "-1.5e10", "NaN-i"). +* +* Regular expression: `/^(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)\s*(?=$|[+-]))?(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?\s*(i)\s*)?$/` +* +* - `^` +* - start of input +* +* - `(?:\s*([+-]?)\s*` +* - open an optional non-capturing group for the real part and capture an optional `+` or `-` literal for its sign, ignoring surrounding whitespace +* +* - `((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)` +* - capture the real magnitude, matching standard decimals, scientific notation, `Infinity`, or `NaN` +* +* - `\s*(?=$|[+-]))?` +* - match optional trailing whitespace, assert via positive lookahead that the real part is followed by either the end of input or the sign for the imaginary part, and close the real part group +* +* - `(?:\s*([+-]?)\s*` +* - open an optional non-capturing group for the imaginary part and capture an optional `+` or `-` literal for its sign, ignoring surrounding whitespace +* +* - `((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?` +* - capture the optional imaginary magnitude, matching standard decimals, scientific notation, `Infinity`, or `NaN` +* +* - `\s*(i)\s*)?` +* - capture the literal character `i` for the imaginary unit, ignoring surrounding whitespace, and close the imaginary part group +* +* - `$` +* - end of input +* +* ## Notes +* +* - The regular expression has the following capture groups +* 1. Sign of real part +* 2. Value of real part +* 3. Sign of imaginary part +* 4. Value of imaginary part +* 5. Imaginary suffix 'i' +* +* @private +* @constant +* @returns {RegExp} regular expression +* @default /^(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)\s*(?=$|[+-]))?(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?\s*(i)\s*)?$/ +*/ +function regexp() { + return /^(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)\s*(?=$|[+-]))?(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?\s*(i)\s*)?$/; +} + + +// EXPORTS // + +module.exports = regexp; From c6c5bc6c68b3a05b7788b040d93ac46b969c67d2 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Mon, 22 Jun 2026 20:43:00 +0000 Subject: [PATCH 04/14] chore: update copyright years --- lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js b/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js index d848c47e1acb..85f8cac7b868 100644 --- a/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js +++ b/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2026 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. From 61880e597c949677e63131986835dd0889e7c055 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 22 Jun 2026 22:42:14 -0700 Subject: [PATCH 05/14] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/complex/base/parse/lib/main.js | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/complex/base/parse/lib/main.js b/lib/node_modules/@stdlib/complex/base/parse/lib/main.js index 285e3cde53e9..e5186c712e70 100644 --- a/lib/node_modules/@stdlib/complex/base/parse/lib/main.js +++ b/lib/node_modules/@stdlib/complex/base/parse/lib/main.js @@ -37,7 +37,7 @@ var regexp = require( './regexp.js' ); * - **im**: imaginary component * * @param {string} str - input string -* @returns {ComplexLike} an object containing real and imaginary parts +* @returns {(ComplexLike|null)} an object containing real and imaginary parts * * @example * var str = '4 + 6i'; @@ -63,22 +63,20 @@ function parse( str ) { // Real component: if ( match[ 2 ] ) { - re = ( match[ 1 ] === '-' ) ? -1 : 1; - re *= Number.parseFloat( match[ 2 ] ); - } - else { - re = 0; + re = ( match[ 1 ] === '-' ) ? -1.0 : 1.0; + re *= parseFloat( match[ 2 ] ); + } else { + re = 0.0; } // Imaginary component: if ( match[ 5 ] ) { - im = ( match[ 3 ] === '-' ) ? -1 : 1; + im = ( match[ 3 ] === '-' ) ? -1.0 : 1.0; if ( match[ 4 ] ) { - im *= Number.parseFloat( match[ 4 ] ); + im *= parseFloat( match[ 4 ] ); } - } - else { - im = 0; + } else { + im = 0.0; } return { From e230063b28b9510b2a737feda44810c75341b43b Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 22 Jun 2026 22:42:45 -0700 Subject: [PATCH 06/14] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/complex/base/parse/lib/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/complex/base/parse/lib/main.js b/lib/node_modules/@stdlib/complex/base/parse/lib/main.js index e5186c712e70..273688973a3b 100644 --- a/lib/node_modules/@stdlib/complex/base/parse/lib/main.js +++ b/lib/node_modules/@stdlib/complex/base/parse/lib/main.js @@ -20,7 +20,6 @@ // MODULES // -var Number = require( '@stdlib/number/ctor' ); var regexp = require( './regexp.js' ); From 6f7e443e10b3a9919f1551b8ac0fd46136292d3b Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 22 Jun 2026 22:43:59 -0700 Subject: [PATCH 07/14] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/complex/base/parse/lib/main.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/node_modules/@stdlib/complex/base/parse/lib/main.js b/lib/node_modules/@stdlib/complex/base/parse/lib/main.js index 273688973a3b..5d7f21859a40 100644 --- a/lib/node_modules/@stdlib/complex/base/parse/lib/main.js +++ b/lib/node_modules/@stdlib/complex/base/parse/lib/main.js @@ -52,14 +52,11 @@ function parse( str ) { if ( typeof str !== 'string' || str === '' ) { return null; } - // OPTIMIZE: Consider implementing an alternative parser to improve performance over regular expression match = str.match( regexp() ); // [ full_match, real_sign, real_value, imag_sign, imag_value, imag_suffix ] - if ( match === null ) { return null; } - // Real component: if ( match[ 2 ] ) { re = ( match[ 1 ] === '-' ) ? -1.0 : 1.0; @@ -67,7 +64,6 @@ function parse( str ) { } else { re = 0.0; } - // Imaginary component: if ( match[ 5 ] ) { im = ( match[ 3 ] === '-' ) ? -1.0 : 1.0; From 84afd681b990ac5fa75ca5b3234453ebf902c11a Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 22 Jun 2026 22:45:38 -0700 Subject: [PATCH 08/14] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/complex/base/parse/lib/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/complex/base/parse/lib/main.js b/lib/node_modules/@stdlib/complex/base/parse/lib/main.js index 5d7f21859a40..f0ae5792d9a9 100644 --- a/lib/node_modules/@stdlib/complex/base/parse/lib/main.js +++ b/lib/node_modules/@stdlib/complex/base/parse/lib/main.js @@ -73,7 +73,6 @@ function parse( str ) { } else { im = 0.0; } - return { 're': re, 'im': im From a7d8dd1387437679ef2eccad57f428ce38e9159b Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 22 Jun 2026 22:48:29 -0700 Subject: [PATCH 09/14] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js b/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js index 85f8cac7b868..9c2e3efb9bf4 100644 --- a/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js +++ b/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js @@ -52,6 +52,7 @@ * ## Notes * * - The regular expression has the following capture groups +* * 1. Sign of real part * 2. Value of real part * 3. Sign of imaginary part From 91b108c41c08160a1c326056bacae9fda7997e33 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 22 Jun 2026 22:48:47 -0700 Subject: [PATCH 10/14] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js b/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js index 9c2e3efb9bf4..b9ca9c4d0781 100644 --- a/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js +++ b/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js @@ -51,7 +51,7 @@ * * ## Notes * -* - The regular expression has the following capture groups +* - The regular expression has the following capture groups: * * 1. Sign of real part * 2. Value of real part From 9410e4bb69c49b2a0e2c3aca6d2795887e72ed77 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 22 Jun 2026 22:49:59 -0700 Subject: [PATCH 11/14] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js b/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js index b9ca9c4d0781..2b208dca69b5 100644 --- a/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js +++ b/lib/node_modules/@stdlib/complex/base/parse/lib/regexp.js @@ -21,7 +21,7 @@ // MAIN // /** -* Return a regular expression that matches and captures a complex number, supporting standard notation, scientific notation, Infinity, and NaN (e.g., "3+4i", "-1.5e10", "NaN-i"). +* Returns a regular expression that matches and captures a complex number, supporting standard notation, scientific notation, Infinity, and NaN (e.g., "3+4i", "-1.5e10", "NaN-i"). * * Regular expression: `/^(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)\s*(?=$|[+-]))?(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?\s*(i)\s*)?$/` * @@ -60,9 +60,7 @@ * 5. Imaginary suffix 'i' * * @private -* @constant * @returns {RegExp} regular expression -* @default /^(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)\s*(?=$|[+-]))?(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?\s*(i)\s*)?$/ */ function regexp() { return /^(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)\s*(?=$|[+-]))?(?:\s*([+-]?)\s*((?:(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)|Infinity|NaN)?\s*(i)\s*)?$/; From f2c988c74043dae8bd2fbb9560c08ad588da4285 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 22 Jun 2026 22:52:20 -0700 Subject: [PATCH 12/14] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/complex/base/parse/lib/main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/complex/base/parse/lib/main.js b/lib/node_modules/@stdlib/complex/base/parse/lib/main.js index f0ae5792d9a9..34f06123591e 100644 --- a/lib/node_modules/@stdlib/complex/base/parse/lib/main.js +++ b/lib/node_modules/@stdlib/complex/base/parse/lib/main.js @@ -20,6 +20,7 @@ // MODULES // +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var regexp = require( './regexp.js' ); @@ -49,7 +50,7 @@ function parse( str ) { var re; var im; - if ( typeof str !== 'string' || str === '' ) { + if ( !isString( str ) || str === '' ) { return null; } // OPTIMIZE: Consider implementing an alternative parser to improve performance over regular expression From badc7ec1171fc8c9e3187baa9a5f7501e43011df Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 22 Jun 2026 22:53:25 -0700 Subject: [PATCH 13/14] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/complex/float32/parse/lib/main.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/complex/float32/parse/lib/main.js b/lib/node_modules/@stdlib/complex/float32/parse/lib/main.js index bfab5138f85f..95b3139baad5 100644 --- a/lib/node_modules/@stdlib/complex/float32/parse/lib/main.js +++ b/lib/node_modules/@stdlib/complex/float32/parse/lib/main.js @@ -47,12 +47,10 @@ function parseComplex64( str ) { if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } - v = parse( str ); if ( v === null ) { throw new Error( format( 'invalid argument. Unable to parse input string as a complex number. Value: `%s`.', str ) ); } - return new Complex64( v.re, v.im ); } From 63bfad29b7bd405ae08564f2bb7401c54aec6a4c Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 22 Jun 2026 22:54:03 -0700 Subject: [PATCH 14/14] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/complex/float64/parse/lib/main.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/complex/float64/parse/lib/main.js b/lib/node_modules/@stdlib/complex/float64/parse/lib/main.js index 8464471231ac..41ed063a63bc 100644 --- a/lib/node_modules/@stdlib/complex/float64/parse/lib/main.js +++ b/lib/node_modules/@stdlib/complex/float64/parse/lib/main.js @@ -47,12 +47,10 @@ function parseComplex128( str ) { if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } - v = parse( str ); if ( v === null ) { throw new Error( format( 'invalid argument. Unable to parse input string as a complex number. Value: `%s`.', str ) ); } - return new Complex128( v.re, v.im ); }