-
-
Notifications
You must be signed in to change notification settings - Fork 484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add assert/is-complex-string
#1417
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,115 @@ | ||||||
<!-- | ||||||
|
||||||
@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. | ||||||
|
||||||
--> | ||||||
|
||||||
# isComplexString | ||||||
|
||||||
> Tests whether input string is a complex number representation`. | ||||||
|
||||||
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||||||
|
||||||
<section class="intro"> | ||||||
|
||||||
</section> | ||||||
|
||||||
<!-- /.intro --> | ||||||
|
||||||
<!-- Package usage documentation. --> | ||||||
|
||||||
<section class="usage"> | ||||||
|
||||||
## Usage | ||||||
|
||||||
```js | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
var isComplexString = require( '@stdlib/assert/is-complex-string' ); | ||||||
``` | ||||||
|
||||||
#### isComplexString( str ) | ||||||
|
||||||
Tests whether input string is a complex number representation`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```js | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
var isComplexString = require( '@stdlib/assert/is-complex-string' ); | ||||||
|
||||||
var str = '5 + 3i'; | ||||||
|
||||||
var b = isComplexString( str ); | ||||||
// returns true | ||||||
``` | ||||||
|
||||||
</section> | ||||||
|
||||||
<!-- /.usage --> | ||||||
|
||||||
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||||||
|
||||||
<section class="notes"> | ||||||
|
||||||
</section> | ||||||
|
||||||
<!-- /.notes --> | ||||||
|
||||||
<!-- Package usage examples. --> | ||||||
|
||||||
<section class="examples"> | ||||||
|
||||||
## Examples | ||||||
|
||||||
<!-- eslint no-undef: "error" --> | ||||||
|
||||||
```js | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment |
||||||
var isComplexString = require( '@stdlib/assert/is-complex-string' ); | ||||||
|
||||||
var str; | ||||||
var b; | ||||||
|
||||||
b = isComplexString( '5 + 4i' ); | ||||||
// returns true | ||||||
|
||||||
b = isComplexString( 'Infinity + 2.34i' ); | ||||||
// returns true | ||||||
|
||||||
b = isComplexString( 'NaN + 4i' ); | ||||||
// returns true | ||||||
|
||||||
b = isComplexString( '45i55 + 5' ); | ||||||
// returns false | ||||||
|
||||||
b = isComplexString( '5 + 6 + 10e4i' ); | ||||||
// returns true | ||||||
|
||||||
b = isComplexString( {} ); | ||||||
// returns false | ||||||
``` | ||||||
|
||||||
</section> | ||||||
|
||||||
<!-- /.examples --> | ||||||
|
||||||
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||||||
|
||||||
<section class="references"> | ||||||
|
||||||
</section> | ||||||
|
||||||
<!-- /.references --> | ||||||
|
||||||
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||||||
|
||||||
<section class="related"> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are missing section |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* @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'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var isComplexString = require( '@stdlib/assert/is-complex-string/lib' ); | ||
var pkg = require( '@stdlib/assert/is-complex-string/package.json' ).name; | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var str; | ||
var v; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
str = '4 + 3i'; | ||
v = isComplexString( str ); | ||
if ( typeof v !== 'boolean' ) { | ||
v.fail( 'should return a boolean' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( typeof v !== 'boolean' ) { | ||
v.fail( 'should return a boolean' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,19 @@ | ||||||||
{{alias}}( str ) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
Tests whether input string is a complex number representation. | ||||||||
|
||||||||
Parameters | ||||||||
---------- | ||||||||
str: string | ||||||||
|
||||||||
Returns | ||||||||
------- | ||||||||
out: boolean | ||||||||
|
||||||||
Examples | ||||||||
-------- | ||||||||
> var str = '4 + 9i'; | ||||||||
> var b = {{alias}}( str ) | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add return type here |
||||||||
See Also | ||||||||
-------- | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||
/* | ||||||
* @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. | ||||||
*/ | ||||||
|
||||||
// TypeScript Version: 4.1 | ||||||
|
||||||
/** | ||||||
* Tests whether input string is a complex number representation. | ||||||
* | ||||||
* @param str | ||||||
* @returns boolean | ||||||
* | ||||||
* @example | ||||||
* var isComplexString = require( '@stdlib/assert/is-complex-string' ); | ||||||
* | ||||||
* var str = '4 + 6i'; | ||||||
* | ||||||
* var b = isComplexString( str ); | ||||||
* returns true | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
declare function isComplexString( str: string ): boolean; | ||||||
|
||||||
|
||||||
// EXPORTS // | ||||||
|
||||||
export = isComplexString; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* @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. | ||
*/ | ||
|
||
import isComplexString = require( './index' ); | ||
|
||
|
||
// TESTS // | ||
|
||
// The function returns a complex like object... | ||
{ | ||
const str = '54 + 3i'; | ||
isComplexString( str ); // $ExpectType boolean | ||
} | ||
|
||
// The compiler throws an error if the function is provided insufficient arguments... | ||
{ | ||
isComplexString(); // $ExpectError | ||
isComplexString( 'beep', 'boop' ); // $ExpectError | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. more tests can be added |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @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'; | ||
|
||
var isComplexString = require( './../lib' ); | ||
|
||
var str = '5 + 4i'; | ||
var b = isComplexString( str ); | ||
console.log( b ); | ||
// => true | ||
|
||
str = 'Infinity + 2.34i'; | ||
b = isComplexString( str ); | ||
console.log( b); | ||
// => true | ||
|
||
str = 'NaN + i4'; | ||
b = isComplexString( str ); | ||
console.log( b ); | ||
// => false | ||
|
||
str = '45i55 + 5'; | ||
b = isComplexString( str ); | ||
console.log( b ); | ||
// => false | ||
|
||
str = '5 + 6 + 10e4i'; | ||
b = isComplexString( str ); | ||
console.log( b ); | ||
// => true | ||
|
||
str = {}; | ||
b = isComplexString( str ); | ||
console.log( b ); | ||
// => false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @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'; | ||
|
||
/** | ||
* Test whether input string is a complex number representation. | ||
* | ||
* @module @stdlib/assert/is-complex-string | ||
* | ||
* @example | ||
* var isComplexString = require( '@stdlib/assert/is-complex-string' ); | ||
* | ||
* var str = '4 + 6i'; | ||
* | ||
* var isCmplx = isComplexString( str ); | ||
* // returns true | ||
*/ | ||
|
||
// MODULES // | ||
|
||
var main = require( './main.js' ); | ||
|
||
|
||
// EXPORTS // | ||
|
||
module.exports = main; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.